How Do I Make A Conditional Export-CSV?


i have following code below, , here i'm wanting accomplish.  want script check sharepoint library in question, , if there no items in library, not run rest of script , not export anything.  if there items in sharepoint list, continue running script , export csv file rest of script outlines.  idea how go accomplishing this?  i'll admit, i'm new @ powershell scripting, learning quick.  appreciated!

$spweb = get-spweb "https://mysite"  $splist = $spweb.lists["nll_pli"]  $exportlist = @()  $splist.items | foreach {   $obj = new-object psobject -property @{    ####"csv column name" - "sharepoint list column"    "loan number" = $_["loan number"]    "gl number" = $_["gl number"]    "amount" = $_["amount"]    "post date" = get-date ($_["post date"]) -uformat "%m/%d/%y"    "description" = $_["description"]    "voucher number" = $_["voucher number"]    "lx code" = $_["lx code"]   }   $exportlist += $obj    }  $now=get-date  $yr=$now.year.tostring()  $mo=$now.month.tostring()  $dy=$now.day.tostring()  $hr=$now.hour.tostring()  $mi=$now.minute.tostring()  $sc=$now.second.tostring()  $ms=$now.millisecond.tostring()  $filepath = 'c:\output\'  $csv = '.csv'  $filenamestring=$filepath+$yr+$mo+$dy+$hr+$mi+$sc+$csv  if ($mo.length -lt 2) {  $mo="0"+$mo} #pad single digit month leading 0  if ($dy.length -lt 2) {  $dy="0"+$dy} #pad single digit day leading 0  if ($hr.length -lt 2) {  $hr="0"+$hr} #pad single digit hour leading 0  if ($mi.length -lt 2) {  $mi="0"+$mi} #pad single digit minute leading 0  if ($sc.length -lt 2) {  $sc="0"+$sc} #pad single digit second leading 0  $exportlist | select "loan number", "gl number", "amount", "post date", "description", "voucher number", "lx code" | export-csv -path $filenamestring -notype  (gc $filenamestring) -replace('"','') | out-file $filenamestring -force  $spweb.dispose()

try enclosing of statements "$now=get-date" end following if-block

    if ( $exportlist.length -ne 0 ) {
        [your statements go here]
    }


al dunbar



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...