为PS Script指定视图以获取Sharepoint企业列表数据



我正在尝试创建一个PowerShell脚本,以便从我们的企业Sharepoint站点中提取报表文件的一组数据。使用getlistitems,我可以从我们的列表中提取一大块所需的数据,但它似乎只是从每个列表的默认视图中返回项目。我想将其设置为从"所有项目"视图中提取,但很难获得。请参阅下面的代码。

$serverurl = "https:linkhiddenforprivacy/_vti_bin/Lists.asmx"
$xml = New-WebServiceProxy -Uri $serverurl -UseDefaultCredential
$dslist = $xml.GetListCollection()
$overalllist = $dslist.ChildNodes
foreach($listitem in $overalllist) {
try {
$xmlDoc = new-object System.Xml.XmlDocument
$query = $xmlDoc.CreateElement("Query")
$viewFields = $xmlDoc.CreateElement("ViewFields")
$queryOptions = $xmlDoc.CreateElement("QueryOptions")
$queryOptions.InnerXml = "<ViewAttributes Scope='RecursiveAll' IncludeMandatoryColumns='FALSE' />"
$rowLimit = "10000"
$view = $overalllist.views["All Items"]
$listitems = $xml.getlistitems($listitem.id, $view ,$null, $null, $rowLimit, $queryOptions, $null).data.row 
foreach($child in $listitems) {
if($child.ows_DocIcon -eq "rdl"){
$vs = $xml.GetVersionCollection($listitem.ID, $child.ows_ID, "_UIVersionString")
$childlib = $child.ows_FileRef
$childname = $child.ows_LinkFileName 
[string]$childowner = $child.ows_ReportOwner
$childcategory = $child.ows_ReportCategory
$childdescription = $child.ows_ReportDescription
$childstatus = $child.ows_ReportStatus
[PSCustomObject]@{
'Doctype' = $child.ows_DocIcon
'Library' = $childlib.substring($childlib.indexof('#') + 1, $childlib.lastindexof('/') - $childlib.indexof('#') - 1)
'Report' = $childname
'Owner' = $childOwner.Substring($childowner.indexof('#') + 1, $childowner.Length - $childowner.IndexOf('#') - 1)
'Category' = $childCategory
'Description' = $childDescription
'Status' = $childStatus
'Version' = $vs.Version[0]._UIVersionString
'Childlib' = $childlib
} | Export-Csv output.csv -Append -NoTypeInformation
}

我已经尝试了一些变体,但没有取得任何成功。我是Powershell的新手,如果有任何帮助,我们将不胜感激。

在PowerShell中使用CSOM,可以轻松地基于视图获取项目。

示例脚本:

Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.dll"  
Add-Type -Path "C:Program FilesCommon Filesmicrosoft sharedWeb Server Extensions15ISAPIMicrosoft.SharePoint.Client.Runtime.dll"  
$siteURL = "http://sp:12001"   
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteURL)  
try{  
$lists = $ctx.web.Lists  
$list = $lists.GetByTitle("MyList")  
$view = $list.Views.GetByTitle("All Items")
$ctx.load($view)        
$ctx.executeQuery()
$query=New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml = $view.ViewQuery;
$listItems = $list.GetItems($query)  
$ctx.load($listItems)        
$ctx.executeQuery()  
foreach($listItem in $listItems)  
{  
Write-Host "ID - " $listItem["ID"] "Title - " $listItem["Title"]  
}  
}  
catch{  
write-host "$($_.Exception.Message)" -foregroundcolor red  
}

从2013年至2016年获取CSOM SDK或在线

如果你尝试在SharePoint中使用PowerShell搜索CSOM,你可能会得到很多演示。

最新更新