Powershell查询Sharepoint列表

我正在苦苦寻找SharePoint的脚本。

这个脚本应该查询一个共享点列表,然后生成一个输出,然后修补服务器。 这是我正在努力的部分..
当我运行它我得到这个错误:

调用具有“7”参数的“GetListItems”的exception:“types'Microsoft.SharePoint.So apServer.SoapServerException'的exception被抛出。 在C:\ Scripts \ AUpdate \ iPatch2.ps1:472 char:33 + $ list = $ SiteWS.GetListItems <<<<($ ListName,$ ViewGuid,$ query,$ null,$ null,$ queryOptions,$ nul l )+ CategoryInfo:NotSpecified:(:) [],MethodInvocationException + FullyQualifiedErrorId:DotNetMethodException

任何人都可以帮忙吗?

# Gather a list of servers to be patched from a Sharepoint list function Get-PatchList { param ( [string] $Uri = 'http://site/_vti_bin/lists.asmx?wsdl', [string] $Day = $(throw "The Day parameter is required"), [string] $Time = $(throw "The Time parameter is required"), [System.Management.Automation.PSCredential] $Credential, [string] $ViewGuid = '{1DD35D95-E1CB-4DFA-8EFD-63C9342C524A}', [string] $ListName = 'Automated Patching' ) # initialise return object $out = @() # connect to web service $SiteWS = New-WebServiceProxy -Uri $Uri -Credential $Credential Write-Verbose "Connecting to web service at $Uri" Write-Verbose " Connecting using $($Credential.username)" Write-Verbose " Filtering hosts managed by $thisHost" # Get the list [System.Xml.XmlNode] $queryOptions [System.Xml.XmlNode] $viewFields #[System.Xml.XmlNode] $query = [xml]"<Query><Where><And><And><Eq><FieldRef Name='TOD'/><Value Type='Text'>$Time</Value></Eq><Eq><FieldRef Name='Day'/><Value Type='Text'>$Day</Value></Eq></And><Or><Eq><FieldRef Name='Status'/><Value Type='Text'>ON</Value></Eq><Eq><FieldRef Name='Status'/><Value Type='Text'>ON In Production</Value></Eq></Or></And></Where></Query>" [System.Xml.XmlNode] $query = [xml]"<Query><Where><And><And><And><Eq><FieldRef Name='TOD'/><Value Type='Text'>$Time</Value></Eq><Eq><FieldRef Name='Day'/><Value Type='Text'>$Day</Value></Eq></And><Or><Eq><FieldRef Name='Status'/><Value Type='Text'>ON</Value></Eq><Eq><FieldRef Name='Status'/><Value Type='Text'>ON In Production</Value></Eq></Or></And><Eq><FieldRef Name='Server'/><Value Type='Text'>$thisServer</Value></Eq></And></Where></Query>" $list = $SiteWS.GetListItems($ListName,$ViewGuid,$query,$null,$null,$queryOptions,$null) #Write-Verbose "Retrieving data with filter " $query #Parse through the list foreach ($row in $list.data.row) { $myhost = New-Object PatchableServer $myhost.Host = $row.ows_Title $myhost.Domain = $row.ows_Domain $myhost.Services = $row.ows_TS $myhost.Impact = $row.ows_Impact $out = $out + $myhost } return $out } # Reformat the list of services from the MOSS format to human-readable function Parse-Services { param ( [string] $Services ) [string] $out = "" if ($Services) { $split = $Services.Split('#') $len = $split.Length if ($len -lt 2) {return $null} else { for ($i=1; $i -le $len; $i+=2) {$out += $split[$i]} return $out } } else { return $null } } function Resolve-FQDN { param ([string] $Identifier) $myhost = [System.Net.Dns]::GetHostEntry($Identifier) return $myhost.HostName } function Get-HostDomain { param([string] $Hostname) $fqdn = Resolve-FQDN -Identifier $Hostname return $fqdn.TrimStart($Hostname).TrimStart('.') } function Get-Ping { param ([string] $Hostname) $myhost = gwmi Win32_PingStatus -Filter "Address='$Hostname'" if ($myhost) { return $myhost.ResponseTime } else { return $null } } 

列表名称中有空格的问题已经没有结束了。

[string] $ListName = 'Automated Patching' )

克隆列表并首先检查出来。 我浪费了足够的时间来处理这个问题,我总是先试一试。 如果是这样的话,你可以找出它们用于空格的恶意嵌套引用,或者用无空格的名字重新实现。 (你可以改变名字的DISPLAY来创build一个空格而不用改变你创build列表时使用的基本名字……它对老板来说仍然很好看; 😉

更新 IIRC你可以尝试url引用第一个'Automated%20Patching' ,这往往是足够的。