Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

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.
0
Techsavy
Asked:
Techsavy
1 Solution
 
Jamie McAllister MVPArchitectCommented:
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
0
 
SubsunCommented:
Slightly modified/cleaned version.. Check this and let me know if you find any error..
Add-PSSnapin Microsoft.Sharepoint.PowerShell
$MyWeb = Get-SPWeb "http://MySite"
$MyList = $MyWeb.Lists["MyList"]
$MyList.Items | foreach{
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]    
	}
} | Export-Csv -Path "\\MyServer\MyLocation\MyExport.csv"

Open in new window

0
 
QlemoC++ DeveloperCommented:
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.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now