извлекать данные из библиотеки документов SharePoint в CSV с помощью powershell

360
murali kuruva

Я пытаюсь извлечь данные из библиотеки документов SharePoint в файл CSV с помощью powershell. Я получаю данные правильно на файл CSv. Но один столбец, то есть «Описание», содержит больше текстовых данных. Так что при запуске сценария данные поступают в другие строки (а не в одну строку). Для справки написал сценарий ниже, а мой файл ниже.

Скрипт Powershell

$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" 

Выходной файл для справки

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. 

Вывод я хочу как ниже

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. 

Надеюсь, вы, ребята, понимаете мое требование. Я хочу, чтобы данные столбца описания были нужны мне только в одной строке.

0

1 ответ на вопрос

1
murali kuruva

Замените разрывы строк пробелами перед использованием $ Description.

$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" 

Ответ поделился Пьеро.