How to use different credentials to access SharePoint 2010 web services in powershell

Steps Involved:

  1. Open SharePoint 2010 Management Shell by going to Start | All Programs | SharePoint | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell (Run as Administrator).
  2. Run the following script.

Powershell Script:

 

## How to use different credentials to access web services in powershell
$listName="List"
## Get-Credential cmdlet is used to get a credential object based on a user name and password.
$credential=Get-Credential
## Web Service Reference - http://Site/_vti_bin/Lists.asmx
$uri="http://serverName:10736/sites/ECT/_vti_bin/Lists.asmx?wsdl"
$listWebServiceReference = New-WebServiceProxy -Uri $uri -Credential $credential
[
System.Xml.XmlNode]$node=$listWebServiceReference.GetList($listName)
write-host -ForegroundColor Green "List Title: " $node.Title



Once you run the script, a pop up will be opened where you could provide the credentials to access the web service.


Untitled.jpg