In this article you will see how to get all the items from a particular list
using SharePoint 2010 web service in PowerShell.
List Items
I have a list named "List" which contains the following items

In this you will see how to get all the items from the list "List" using
SharePoint 2010 web service in PowerShell.
Steps Involved
- Open SharePoint 2010 Management Shell by going to Start | All Programs | SharePoint | Microsoft SharePoint 2010 Products | SharePoint 2010 Management Shell (Run as Administrator).
- Run the following script.
PowerShell Script
##==============================================================================
## Automation : Get all the list items for a particular list using SharePoint
2010 Web Service in PowerShell
## Note : Need to modify the input parameters
## Author : Vijai Anand.R
## Date : 05-January-2012
##================================================================================
#------------- Input Parameters --------------
## Specify the site URL from where you need to get all the list items
$webURL="http://serverName:46563/sites/MMS"
## Specify the list name from where you need to get the list items
[string]$listName
=
"List"
## Specify the location where the output xml file GetListItems.xml file has to
be generated
$outputXmlFilePath="D:\VijaiPOC\GetListItems.xml"
## $viewName is a string that contains the GUID of the view. If you give empty
value it will take the values from default view
[string]$viewName
=
""
## $rowLimit is a string that contains number of items to be retreived from the
list
[string]$rowLimit
=
"50"
[String]$viewFieldsValue="<FieldRef
Name='Title' />"
[String]$queryValue="<Where><Gt><FieldRef
Name='ID'/><Value Type='Number'>3</Value></Gt></Where>"
[String]$queryOptionsValue=""
#--------- Get List Items Function ----------
Function
GetListItems()
{
Write-Host
-ForegroundColor
Green
"Please pass the credentials that have access to the site: "$webURL
$credential=Get-Credential
$uri=$webURL+"/_vti_bin/Lists.asmx?wsdl"
$listsWebServiceReference
=
New-WebServiceProxy
-Uri
$uri
-Credential
$credential
[System.Xml.XmlDocument]$xmlDoc=New-Object
-TypeName
System.Xml.XmlDocument
[System.Xml.XmlElement]$query
=
$xmlDoc.CreateElement("Query")
[System.Xml.XmlElement]$viewFields
=$xmlDoc.CreateElement("ViewFields")
[System.Xml.XmlElement]$queryOptions
=$xmlDoc.CreateElement("QueryOptions")
$viewFields.InnerXml
=
$viewFieldsValue
$query.InnerXml
=
$queryValue
$queryOptions.InnerXml
=
$queryOptionsValue
[System.Xml.XmlNode]$nodeListItems
=$listsWebServiceReference.GetListItems($listName,
$viewName,
$query,
$viewFields,
$rowLimit,
$queryOptions,
$null)
$output
=
New-Object
-TypeName
System.IO.StreamWriter
-ArgumentList
$outputXmlFilePath,
$false
$output.WriteLine($nodeListItems.Outerxml)
$output.WriteLine()
$output.Dispose()
Write-Host
-ForegroundColor
Green
"Output file is generated in the path: "$outputXmlFilePath
}
#--------- Calling the Function -----------
GetListItems
Output
Output file is generated in the path specified in the $outputXmlFilePath.
Note: You will get only two items because in the query I have given a
condition ID>3.

Summary
Thus in this article you have seen how to get all the items from a particular
list using SharePoint 2010 web service.

Amar SPosted Sep 16, 2016, 5:23 AM
Also, since this script uses web service, it can be run from any client machine also.
Amar SPosted Sep 16, 2016, 5:22 AM
Thanks man. Appreciate that you have posted this solution here. Helped me a lot.
ShirleyPosted Feb 15, 2012, 4:57 PM
If I leave the $viewName empty, the default view is not used. In fact, if I put in the guid, I don't get the expected columns. Any suggestions?
Brenda HartsonPosted Jan 27, 2012, 7:30 PM
PS C:\exports> c:\exports\exporttestbh.ps1 Please pass the credentials that have access to the site: https://lbrmain.lbrealty.com/intranet cmdlet Get-Credential at command pipeline position 1 Supply values for the following parameters: Credential Exception calling "GetListItems" with "7" argument(s): "Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerExcepti on' was thrown." At C:\exports\exporttestbh.ps1:41 char:82 + [System.Xml.XmlNode]$nodeListItems =$listsWebServiceReference.GetListItems <<<< ($listName, $viewName, $query, $vie wFields, $rowLimit, $queryOptions, $null) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException New-Object : Exception calling ".ctor" with "2" argument(s): "Access to the path 'c:\exports\ArmedForcesMembers.xml' is deni ed." At C:\exports\exporttestbh.ps1:42 char:28 + $output = New-Object <<<< -TypeName System.IO.StreamWriter -ArgumentList $outputXmlFilePath, $false + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationException + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.Commands.NewObjectCommand You cannot call a method on a null-valued expression. At C:\exports\exporttestbh.ps1:43 char:25 + $output.WriteLine <<<< ($nodeListItems.Outerxml) + CategoryInfo : InvalidOperation: (WriteLine:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At C:\exports\exporttestbh.ps1:44 char:25 + $output.WriteLine <<<< () + CategoryInfo : InvalidOperation: (WriteLine:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull You cannot call a method on a null-valued expression. At C:\exports\exporttestbh.ps1:45 char:23 + $output.Dispose <<<< () + CategoryInfo : InvalidOperation: (Dispose:String) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Output file is generated in the path: c:\exports\ArmedForcesMembers.xml PS C:\exports>
Arjun PanwarPosted Jan 7, 2012, 3:38 AM
Thanks
Akash AhlawatPosted Jan 6, 2012, 11:08 PM
As a big sharepoint fan i really like this article and appreciate your efforts
Vijai Anand RamalingamPosted Jan 6, 2012, 3:57 AM
Thank You:-)
Rajesh KumarPosted Jan 6, 2012, 3:53 AM
Good Work........
Maria JohnsonPosted Jan 6, 2012, 3:50 AM
Hi Vijai. Very nicely presented article. Everything clearly understood.