i am trying export library data into CSV file. i had used string functionality on my script to get content. my script was working fine but i am getting output in single string (or) one column. My script and out as below.
Script
$web = get-spweb "SiteURL"
$caseLib = $web.lists | where {$_.title -eq "Library"}
$query = new-object Microsoft.SharePoint.SPQuery
$query.ViewFields = "<FieldRef Name='LinkFilename'/><FieldRef Name='DocumentSetDescription'/><FieldRef Name='Party_x0020_Lookup'/><FieldRef Name='State_x0020_code'/><FieldRef Name='Case_x0020_Manager'/>"
$query.RowLimit=50000
do
{
$caseLibItems=$caseLib.GetItems($query)
$query.ListItemCollectionPosition=$caseLibItems.ListItemCollectionPosition
$listItemsTotal = $caseLibItems.Count
$x = 0
for($x=0;$x -lt $listItemsTotal; $x++)
{
$Description = $caseLibItems[$x]["DocumentSetDescription"]
$CaseManager = $caseLibItems[$x]["Case_x0020_Manager"]
$str = ""
if('$Description; $CaseManager' -ne $null)
{
$str = $caseLibItems[$x]["LinkFilename"].ToString()
+ $Description
+ $caseLibItems[$x]["Party_x0020_Lookup"].ToString()
+ $caseLibItems[$x]["State_x0020_code"].ToString()
+ $CaseManager
}
else
{
$str = $caseLibItems[$x]["LinkFilename"].ToString()
}
Write-Output $str | Out-File "C:\test.csv" -Append
}
} while ($query.ListItemCollectionPosition -ne $null)
Write-Host "Exiting"
Output file in CSV
XXXXX-2-AB-123,file was uploaded,country1,12345,[email protected]
XXXXX-3-CB-124,data received,country2,12365,[email protected]
XXXXX-8-AC-246,file mismatch uploaded,country1,12345,[email protected]
I want to add headers on CSV and i want output file data below format on CSV file (Means, name content should come in one column, Description data should come in another column,Party lockup another column etc ).. How to split string in array. If anyone had idea please share with updated powershell script
Name Description Party Lookup State code Case Manager
XXXXX-2-AB-123 file was uploaded country1 12345
[email protected]XXXXX-3-CB-124 data received country2 1236 [email protected]
XXXXX-8-AC-246 file mismatch uploaded country1 12345 [email protected]