Techsavy
asked on
Powershell help
Hi, am running following powershell script, and I ran into an error.
Add-PSSnapin Microsoft.Sharepoint.Power Shell
$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"]).su bstring(($ _["Classif ications"] ).IndexOf( "#")+1)
"Classifications ID" = ($_["Classifications"]).sp lit(";")[0 ]
}
$exportList += $obj
$exportlist | Export-Csv -Path "\\MyServer\MyLocation\MyE xport.csv"
}
Error: Export-CSV : Cannot bind argument to parameter ‘InputObject’ because it is null.
Add-PSSnapin Microsoft.Sharepoint.Power
$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"]).su
"Classifications ID" = ($_["Classifications"]).sp
}
$exportList += $obj
$exportlist | Export-Csv -Path "\\MyServer\MyLocation\MyE
}
Error: Export-CSV : Cannot bind argument to parameter ‘InputObject’ because it is null.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The error is that $exportlist | Export-Csv -Path "\\MyServer\MyLocation\MyE xport.csv" needs to be outside of the foreach. But the code Subsun showned is better, not using any intermediate variables.
http://en.community.dell.com/techcenter/powergui/f/4834/t/19571829.aspx