获取网络

获取网络

我想每天导出我的 SharePoint 文档库数据,并且 csv 文件需要按照命名约定保存为 Dataname_yyyyMMdd。根据我的以下脚本,需要将 SharePoint 库中的数据导出到一个 CSV 文件中,文件名为 Data_yyyyMMdd。然后,需要从 Data_yyyyMMdd 导入数据,并将“header”添加到文件,然后导出到新的最终输出 CSV 文件中,文件名为“DataName_yyyyMMdd”。

运行脚本时,我仅获得一个文件,即 Data_yyyyMMdd。文件中的数据未导入到最终的 csv 文件中,并且未生成最终的输出文件 DataName_yyyyMMdd。如果脚本中存在错误,请纠正我。请与我分享正确的脚本。

Powershell 脚本

$web = get-spweb $siteUrl $caseLib = $web.lists | 其中 {$_.title -eq $listTitle} $query=new-object Microsoft.SharePoint.SPQuery $query.ViewFields = "" $query.RowLimit=5000

$ListName1 = "数据" $ExportFolder1 = “C:\Users\” $ExportName1 = Get-Date -f “yyyyMMdd” $ExportPath1 = $ExportFolder1 + $ListName1 + $ExportName1 + “.csv” $ListName = "数据名称_" $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() }

写入输出 $str | 输出文件 $ExportPath1 -Append
}

当 ($query.ListItemCollectionPosition -ne $null)

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

写主机“退出”

答案1

将 SharePoint 列表数据导出到 CSV

添加 PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

获取网络

$web = Get-SPWeb -identity “站点名称”

获取目标列表

$list = $web.Lists["月度计划日志"]

保存结果的数组 - PSObjects

$ListItemCollection = @()

#获取状态为“进行中”的所有列表项 $list.Items | Where-Object { $["状态"] -eq "进行中"} | foreach { $ExportItem = New-Object PSObject $ExportItem | Add-Member -MemberType NoteProperty -name "标题" -value $["标题"] $ExportItem | 添加成员 -成员类型 NoteProperty -名称 "部门" -值 $["部门"] $ExportItem | Add-Member -MemberType NoteProperty -name "状态" -value $["状态"] $ExportItem | Add-Member -MemberType NoteProperty -name "优先级" -value $_["优先级"]

#将具有属性的对象添加到数组 $ListItemCollection += $ExportItem } #将结果数组导出到 CSV 文件 $ListItemCollection | Export-CSV "c:\List.txt" -NoTypeInformation

处置 web 对象

$web.Dispose()

所有字段使用 PowerShell 导出

变量

$SiteUrl="站点" $OutPutFile = "位置"

获取网站和用户信息列表

$web = Get-SPWeb $SiteUrl $UserInfoList = $Web.SiteUserInfoList Write-host “找到的项目总数:”$UserInfoList.Itemcount

保存结果的数组 - PSObjects

$ListItemCollection = @()

#获取状态为“进行中”的所有列表项 $UserInfoList.Items | foreach { write-host "处理项目 ID:"$_["ID"]

$ExportItem = New-Object PSObject #获取每个字段 foreach($Field in $.Fields) { $ExportItem | 添加成员-成员类型 NoteProperty -名称 $Field.InternalName -值 $[$Field.InternalName]
} #将具有属性的对象添加到数组 $ListItemCollection += $ExportItem

}

将结果数组导出到 CSV 文件

$ListItemCollection | Export-CSV $OutPutFile -NoTypeInformation Write-host "用户信息列表已导出至站点 $($SiteURL) 的 $($OutputFile)"

$web.Dispose()

相关内容