Get SharePoint list items using Get-WebService

This is an example of how to get SharePoint list items using Get-WebService. This does not require any SharePoint modules or special dlls to be loaded. This particular example shows how to get back a particular set of items. You pass in a Query Column and Query Value and a CAML query is created. i.e. QueryColumn = Title and QueryValue = Item1. All matching items are returned. This is a simple example, you can get way more precise if needed.


    Get a sharepoint list object
    Using the name of of a field in a list and a value for that field, this will return all items that match the critiria.  \
    This returned object is XML
    SharePoint is case sensitive!
    Column names returned in the output are ows_[name], but when you pass them in they are just [name]
    The URL to the Sharepoint WSDL
.PARAMETER SharePointListName
    This name of the SharePoint list you are querying
.PARAMTER ColumnNames
    The array should contains the name of columns you want returned in your dataset from the SharePoint list.  
.PARAMETER QueryColumn
    This is column of the list you are querying with
    This is the value of the column you querying with 
    Get-SPList -URI "http://sharepointsite/sitename/_vti_bin/Lists.asmx?wsdl -SharePointListName "MySharePointList" -ColumnName "ID","Title","Vendor" -QueryColumn "Color" -QueryValue "Red"
function Get-SPList
        [string] $URI = "http://sharepointsite/sitename/_vti_bin/Lists.asmx?wsdl",
        [string] $SharePointListName = "List Name",
        [string[]] $ColumnNames = [string[]]("ID","Title","Vendor"),  #examples
        [string] $QueryColumn = "FieldName",
        [string] $QueryValue = "FieldValue"

        #Maybe put some logging in here
        #Prepare the ViewFieldsXML
        $ColumnNames | ForEach-Object {
            $ViewFieldsXML = $ViewFieldsXML + ""
        #get sharepoint web service connection
        $service = New-WebServiceProxy -Uri $URI  -Namespace SpWs -UseDefaultCredential
        #the status field is ows_Demand_x0020_Status
        #This sets up the XML to use the webservice.
        $xmlDoc = new-object System.Xml.XmlDocument            
        $query = $xmlDoc.CreateElement("Query")            
        $viewFields = $xmlDoc.CreateElement("ViewFields") 

        #define your view fields with the name of SharePoint columns.  
        $queryOptions = $xmlDoc.CreateElement("QueryOptions")            
        $rowLimit = "100"
        $ListItems = $service.GetListItems($SharePointListName, "", $query, $viewfields, $rowLimit, $queryOptions, "") 
        Write-Output $ListItems.Data.Row
        #some logging here