我正在努力解决查询 Sharepoint 的脚本。
此脚本应该查询 SharePoint 列表,然后生成输出,然后修补服务器。这是我遇到困难的部分。
当我运行它时,我收到此错误:
使用“7”个参数调用“GetListItems”时发生异常:“引发了类型为‘Microsoft.SharePoint.So apServer.SoapServerException’的异常。”在 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 }
}
答案1
我在处理包含空格的列表名称时遇到了无数问题。
[string] $ListName = 'Automated Patching' )
克隆列表并首先检查一下。我已经在这个问题上浪费了足够多的时间,所以我总是先尝试一下。如果是这样的话,您可以找出他们用于空格的邪恶嵌套引号,或者使用无空格名称重新实现。(您可以更改名称的显示以包含空格,而无需更改创建列表时使用的基本名称……它仍然会让老板觉得好看。;-)
更新据我所知,您可以先尝试 URL 引用'Automated%20Patching'
,这通常就足够了。