1

Attempting to Get List Items from SharePoint using PowerShell.

I used the example from here Windows PowerShell Blog, modified it to use with my site. Now I get the following error:

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

Script I am using:

# 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'            
        }            
}

Anyone tried this before? How can I resolve this issue?

Ganesh Sanap
  • 1,386
  • 1
  • 8
  • 18
SuperSooty
  • 81
  • 4
  • 9
  • Catch your exception and see what additional details it give. Inside your catch {} add [System.Exception], and then echo it out with ($_.Exception).Message – Austin T French Mar 29 '13 at 01:20
  • The exception being thrown is that shown above ... Exception calling "GetListItems" with "7" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown." – SuperSooty Apr 02 '13 at 08:04

3 Answers3

3

Here's the solution worked for me..

Add "?WSDL" to the end of $uri string

$uri = "http://SITE/sites/DefaultCollection/Engineering/Subsite%20(UK)/_vti_bin/lists.asmx?WSDL"

According to this link:To return a service description of a Web service that was created by using ASP.NET, append "?WSDL" to the URL of the Web service (for example, http://www.ss64.com/MyWebService.asmx?WSDL)

Qianhong
  • 31
  • 2
0

The line it is throwing the error at is:

$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")

That line is not caught, but here is a similar issue throwing the same error. If you want to try and get a better exception, wrap the line in another try catch:

try{
$list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")
}
catch{
[System.Exception]
write-host ($_.Exception).Message
}
Community
  • 1
  • 1
Austin T French
  • 5,022
  • 1
  • 22
  • 40
-1

Please make sure to add "?WSDL" to your URI which is why the code breaks. Pretends like it doesn't know the definition of the function (atleast I guess)...

Like the one below. I was surprised to see this made my code work. Weird..

$uri = "http://<>/sites/DefaultCollection/Engineering/Subsite%20(UK)/_vti_bin/lists.asmx?WSDL"