Extrahieren Sie mithilfe von Powershell Daten aus der SharePoint-Dokumentbibliothek in CSV

517
murali kuruva

Ich versuche, Daten aus der SharePoint-Dokumentbibliothek mithilfe von Powershell in eine CSV-Datei zu extrahieren. Ich bekomme Daten korrekt in der CSv-Datei. Eine Spalte, z. B. "Description", enthält jedoch mehr Textdaten. Wenn das Skript ausgeführt wird, kommen die Daten in eine andere Zeile (sie kommen nicht in einer Zeile). Als Referenz hatte unten ein Skript und meine Out-Datei geschrieben.

Powershell-Skript

$web = get-spweb "Site Url" $caseLib = $web.lists | where {$_.title -eq "Document Library"} $query=new-object Microsoft.SharePoint.SPQuery $query.ViewFields = "" $query.RowLimit=500000  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"] $str = ""  if('$Description' -ne $null) { $str = $caseLibItems[$x]["LinkFilename"].ToString() + '}' + $Description } else { $str = $caseLibItems[$x]["LinkFilename"].ToString()  }  Write-Output $str | Out-File "Path" import-csv Data.csv -delimiter "}" -Header "Number", "Description" | export-csv -NoTypeInformation -Path "C:\csvfile1.csv" }  } while ($query.ListItemCollectionPosition -ne $null)  Write-Host "Exiting" 

Ausgabedatei als Referenz

Name Description ABCD-123 This file imported data of system. XYZA-231 Data migrated to next session file need to upload on another server. System update required. CDFC-231 New file need to create on system XYZA-984 system creating problem. Source code error. update new file HGFC-453 Maintenance updated file. 

Ausgabe möchte ich wie folgt

Name Description ABCD-123 This file imported data of system. XYZA-231 Data migrated to next session.file need to upload on another server. System update required. CDFC-231 New file need to create on system XYZA-984 system creating problem. Source code error. update new file. HGFC-453 Maintenance updated file. 

Ich hoffe, ihr versteht meine Anforderung. Ich möchte, dass Beschreibungsspaltendaten mich nur in einer Zeile benötigen.

0

1 Antwort auf die Frage

1
murali kuruva

Ersetzen Sie Zeilenumbrüche durch Leerzeichen, bevor Sie $ Description verwenden.

$web = get-spweb $siteUrl $caseLib = $web.lists | where {$_.title -eq $listTitle} $query=new-object Microsoft.SharePoint.SPQuery  $query.ViewFields = "<FieldRef Name='LinkFilename'/><FieldRef Name='DocumentSetDescription'/>" $query.RowLimit=500000  Write-Output "Header}Description" | Out-File "temp.csv"   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"] $str = "" if('$Description' -ne $null) { ### Insert the line below to remove line breaks ############### $Description = $Description -replace "`n"," " -replace "`r"," " ############################################################### $str = $caseLibItems[$x]["LinkFilename"].ToString() + '}' + $Description } else { $str = $caseLibItems[$x]["LinkFilename"].ToString() } Write-Output $str | Out-File -Append "temp.csv"  } } while ($query.ListItemCollectionPosition -ne $null)  import-csv temp.csv -delimiter "}" | export-csv -NoTypeInformation -Path "result.csv"  Write-Host "Exiting" 

Antwort geteilt von Piero.