每天提取SharePoint数据

时间:2018-10-03 09:46:00

标签: arrays string powershell sharepoint export

我想每天导出我的SharePoint文档库数据,并且csv文件需要作为命名约定另存为Dataname_yyyyMMdd。按照我下面的脚本,它需要将数据从共享点库导出到一个CSV文件中,名称为Data_yyyyMMdd。然后,它需要从Data_yyyyMMdd导入数据,并在文件中添加“标头”,然后以名称“ DataName_yyyyMMdd”的形式导出到新的最终输出CSV。

在运行脚本时,我只得到一个文件Data_yyyyMMdd。来自文件的数据未导入到最终的csv文件,并且未生成最终的输出文件DataName_yyyyMMdd。如果在脚本中做错了,请纠正我。请分享正确的脚本。

Powershell脚本

$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=5000

do

$ListName1 = "Data"
$ExportFolder1 = “C:\Users\”
$ExportName1 = Get-Date -f “yyyyMMdd”
$ExportPath1 = $ExportFolder1 + $ListName1 + $ExportName1 + “.csv”
$ListName = "Dataname_"
$ExportFolder = “C:\Users\csv\”
$ExportName = Get-Date -f “yyyyMMdd”
$ExportPath = $ExportFolder + $ListName + $ExportName + “.csv”
{
$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 $ExportPath1 -Append  
}

} while ($query.ListItemCollectionPosition -ne $null)

Import-csv $ExportPath1 -delimiter "}" -Header "Number", "Description"  | export-csv $ExportPath -NoTypeInformation  

Write-Host "Exiting"

0 个答案:

没有答案