Get-SharePointList

Osin has a great set of posts about working with Sharepoint with PowerShell. The key to all of it is his wonderful Get-WebService function that allows you to easily connect to any web service you like. I actually took his script and added it as a function to my profile.

Along with updating a list, I found myself needing to pull data from a list as well. Osin had 3/4’s of the CRUD (Create,Read,Update,Delete) operations, but I really needed the Read operation. WIth the work that he had done, it was extremely easily to figure out what I needed to do.

Once you have the webservice object, you simply need to call the GetListItems as shown in the example below. In this case, the lists variable is the webservice object.

   1: $lists = get-webservice -url $listurl
   2: $lists.Credentials = [System.Net.CredentialCache]::DefaultCredentials
   3: $lists.url = $listurl
   4: $result = $lists.GetListItems($listname,$null, $null, $null, $null, $null, $null)

You will notice that GetListItems takes a bunch of arguments. In this basic example, I am simply passing in the name of the list. In the next couple of posts I will talk about what some of the other parameters can do for us and a bit of an intro into the world of CAML or Collaborative Application Markup Language.

Comments are closed