3

I am trying to get the contents of a Sharepoint 2007 list using Powershell. I'm able to connect to the web service but receive an exception whenever I try to call the GetListItems method.

# Create credential object
$username = "domain\user"
$password = cat C:\users\user\dashboard\securestring.txt | convertto-securestring
$credential = new-object -typename System.Management.Automation.PSCredential -argumentlist $username, $password

# Connect to web service
$uri = "https://sharepoint.com/teams/SysAdmin/_vti_bin/lists.asmx"
$service = New-WebServiceProxy -uri $uri –Credential $credential
$listname = 'Services'

$service.GetListItems($listname, $null, $null, $null, $null, $null, $null)

Exception calling "GetListItems" with "7" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerExcept ion' was thrown." At C:\Users\user\Dashboard\sharepoint.ps1:15 char:22 + $service.GetListItems <<<< ($listname, "", $query, $viewFields, "", $queryOptions, "") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException**

1

I was able to figure this one out. I had to connect to the parent Sharepoint site when creating the service object. Then I specified the subsite web services address prior to calling GetListItems.

# Connect to web service
$uri = "https://sharepoint.com/_vti_bin/lists.asmx"
$service = New-WebServiceProxy -uri $uri –Credential $credential

# Set service url to subsite
$service.url = "https://sharepoint.com/teams/SysAdmin/_vti_bin/lists.asmx"

# Pull contents of list
$listname = 'Services'
$list = $service.GetListItems($listname, $null, $null, $null, $null, $null, $null)
0

You can also avoid this by just putting ?WSDL on the end of the subset service URL and not change the url of the WebServiceProxy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.