尝试使用 PowerShell 从 SharePoint 获取列表项。
我使用了此处Windows PowerShell Blog中的示例,并对其进行了修改以与我的站点一起使用。现在我收到以下错误:
Exception calling "GetListItems" with "7" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown."
At line:30 char:1
+ $list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $qu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : SoapException
我正在使用的脚本:
# The uri refers to the path of the service description, e.g. the .asmx page
$uri = "http://SITE/sites/DefaultCollection/Engineering/Subsite%20(UK)/_vti_bin/lists.asmx"
# Create the service
$service = New-WebServiceProxy -Uri $uri -Namespace SpWs -UseDefaultCredential
# The name of the list
$listName = "Test1"
# Create xml query to retrieve list.
$xmlDoc = new-object System.Xml.XmlDocument
$query = $xmlDoc.CreateElement("Query")
$viewFields = $xmlDoc.CreateElement("ViewFields")
$queryOptions = $xmlDoc.CreateElement("QueryOptions")
$query.set_InnerXml("FieldRef Name='Text1'")
$rowLimit = "10"
$list = $null
$service = $null
try
{
$service = New-WebServiceProxy -Uri $uri -Namespace SpWs -UseDefaultCredential
}
catch
{
Write-Error $_ -ErrorAction:'SilentlyContinue'
}
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
if($service -ne $null)
{
try
{
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
}
catch
{
Write-Error $_ -ErrorAction:'SilentlyContinue'
}
}
以前有人试过吗?我该如何解决这个问题?