I want to export data from document library column into csv file using PowerShell.
In document library i had column name "Post Code" under column i had different post codes as "XXXXX-12-AD-2345, XXXXX-24-AD-2134, XXXXX-12-CD-1111, AAAAA-34-CR-1232, CCCCC-90-CX-11222, etc". I want data of "Post code" column and "post code" starting with XXXXX- only with all columns.
Means output like be in CSV file as below
Output on csv file as below
Post Code Name Contact Name Phone number
XXXXX-02-AD-1234 Jhonson [email protected] 12345678
XXXXX-24-AD-2134 Mike [email protected] 34534564
XXXXX-12-CD-1111 Peter [email protected] 11222233
I tried "Where-OPostcoder getting data of "Post code" column, but it generating empty file. Is there other condition (or) other powershell script using Loop condtion etc. Please share script. Thank you so much in Advance.
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Get the Web
$web = Get-SPWeb -identity "site url"
#Get the Target List
$list = $web.Lists["Document Library"]
#Array to Hold Result - PSObjects
$ListItemCollection = @()
#Get All List items
$list.Items | Where-Object {$_.'Post code' -like '*XXXXX-*'} | foreach {
$ExportItem = New-Object PSObject
$ExportItem | Add-Member -MemberType NoteProperty -name "Post code" -value $_["Post code"]
$ExportItem | Add-Member -MemberType NoteProperty -name "Name" -value $_["Name"]
$ExportItem | Add-Member -MemberType NoteProperty -name "Contact name" -value $_["Contact Name"]
$ExportItem | Add-Member -MemberType NoteProperty -name "Phone number" -value $_["Phone number"]
#Add the object with property to an Array
$ListItemCollection += $ExportItem
}
#Export the result Array to CSV file
$ListItemCollection | Export-CSV "Path location" -NoTypeInformation
#Dispose the web Object
$web.Dispose()
write-Host "Exiting"