locked
Retrieving SP list data with Powershell RRS feed

  • Question

  • As part of a project, I need to connect to a Sharepoint 2010 list and pull data from it using Powershell.

    I understand that what I want is probably a SOAP web service connection, but I can't find any sample code(and barely even evidence that it's possible) for using a connection of that type with Sharepoint+powershell.

     

    All I require is a list of every single "Title" from the list.  I do not have access to run scripts on the server itself.

     

    Can anyone point me in the right direction?  I have a solid understanding of the Powershell, CAML, and XML required for the task, I'm just having trouble putting this all together.

    If there's a smarter/smoother way than SOAP, I'm open to any advice.

    Thanks in advance!
    Monday, October 17, 2011 6:56 PM

Answers

  • This site is producing results- but what comes back is a table and not XML.  Still, exceedingly helpful!

     

    http://blogs.msdn.com/b/powershell/archive/2010/06/24/using-new-webserviceproxy-to-get-modify-and-add-items-to-a-list-in-sharepoint-2007.aspx


    # The uri refers to the path of the service description, e.g. the .asmx page            
    $uri = "https://site/siteurl/_vti_bin/lists.asmx?WSDL"          
                
    # Create the service            
    $service = New-WebServiceProxy -Uri $uri  -Namespace SpWs  -UseDefaultCredential            
                
    # The name of the list             
    $listName = "MyList"             
                
    # 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='Full Name'")             
    $rowLimit = "50"            
                
    $list = $null             
    $service = $null              
                
    try{            
        $service = New-WebServiceProxy -Uri $uri  -Namespace SpWs  -UseDefaultCredential              
    }            
    catch{             
        Write-Error $_ -ErrorAction:'SilentlyContinue'             
    }
    #Now, we use the service object to retrieve the list.
    
    if($service -ne $null){            
        try{                    
            $list = $service.GetListItems($listName, "", $query, $viewFields, $rowLimit, $queryOptions, "")             
        }            
        catch{             
            Write-Error $_ -ErrorAction:'SilentlyContinue'            
    	
    	}            
    }



    • Edited by FranktheFink Monday, October 17, 2011 11:17 PM
    • Proposed as answer by Shimin Huang Wednesday, October 19, 2011 2:01 AM
    • Marked as answer by Shimin Huang Friday, October 28, 2011 3:34 AM
    Monday, October 17, 2011 10:52 PM

All replies