Link to home
Start Free TrialLog in
Avatar of Techsavy
Techsavy

asked on

Powershell help

Hi, am running following powershell script, and I ran into an error.

Add-PSSnapin Microsoft.Sharepoint.PowerShell


$MyWeb = Get-SPWeb "http://MySite"
$MyList = $MyWeb.Lists["MyList"]
$exportList = @()
$MyList.Items | foreach{
$obj = New-Object PSObject -Property @{
    "ID" = $_["ID"]
     "Content Type" = $_["P. Type"]
     "Program Name" = $_["Program Name"]
     "Classifications" = ($_["Classifications"]).substring(($_["Classifications"]).IndexOf("#")+1)
     "Classifications ID" = ($_["Classifications"]).split(";")[0]
     
       
}

 
  $exportList += $obj
  $exportlist | Export-Csv -Path "\\MyServer\MyLocation\MyExport.csv"

}

Error: Export-CSV : Cannot bind argument to parameter ‘InputObject’ because it is null.
Avatar of Jamie McAllister
Jamie McAllister
Flag of Switzerland image

Filter null values out of the feed sent to Export-CSV with a Where-Object {$_}

http://en.community.dell.com/techcenter/powergui/f/4834/t/19571829.aspx
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The error is that    $exportlist | Export-Csv -Path "\\MyServer\MyLocation\MyExport.csv" needs to be outside of the foreach. But the code Subsun showned is better, not using any intermediate variables.