![](/img/trans.png)
[英]Powershell - Exporting data from powershell into a csv file using custom objects
[英]extract data from SharePoint document library to CSV using powershell
我正在嘗試使用 powershell 將 SharePoint 文檔庫的數據提取到 CSV 文件。 我在 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.
希望大家能理解我的要求。 我希望僅在一行中需要我的描述列數據。
任何人都可以在這個腳本上幫助我或糾正我。
在使用$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)
{
$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"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.