为PS脚本指定视图以提取Sharepoint Enterprise列表数据

问题描述 投票:0回答:1

我正在尝试创建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 sharepoint view listitem
1个回答
1
投票

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

示例脚本:

Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"  
Add-Type -Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.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 2016online获取CSOM SDK

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

© www.soinside.com 2019 - 2024. All rights reserved.