Manipulating SharePoint Lists with PowerShell

Manipulating SharePoint Lists with PowerShell

Manipulating SharePoint Lists with PowerShell

Manipulating SharePoint Lists with PowerShell – PowerShell Gives us an easy way to manipulate SharePoint data using New-WebServiceProxy cmdlet, without using Microsoft.SharePoint.dll which is not easily accesible, also Microsoft SharePoint dll file has some dependencies which might cause it not to run even if you are able to get hold of it from some one.Using New-WebServiceProxy cmdlet is an interesting way of getting access to SharePoint site and manipulate its lists

If i navigate to the uri which gives a list fo services available to us we can see the following entries

https://space.com/sites/dn/_vti_bin/lists.asmx

Manipulating SharePoint Lists with PowerShell

Now let me show you some examples which i was able to achieve using GetListItems service to

  • Get All Items from SharePoint List
  • Update List Items in SharePoint List
  • Add New Items to SharePoint List
  • Delete Items from SharePoint List
Get All Items from SharePoint List : –

 

<#######################################################################################################################>

Update List Items in SharePoint List : –

Lets assume  that we need to to modify the ClusterName field value from “mhv1” to “mhv2”.

 

Here’s the output which i got when i ran for my list


 

# Next Create an xmldocument object and construct a batch element and its attributes.

 

Now if i again run a query against the list i do see the clustername value was updated to “mhv2”


 

ows_HostName : N01

ows_ClusterName : MHV2

ows_HostGroup  Clusters
ows_OperatngSystem : Microsoft Windows Server 2008 R2 Datacenter , Service Pack 1
ows_TotalMemory : 62.7500000000000
ows_Site : ADows__ModerationStatus : 0
ows__Level : 1
ows_Title : N01
ows_ID : 16683
ows_owshiddenversion : 1
ows_UniqueId : 16683;#{D7E3FA26-63A1-4C86-A1B5-35A515DE0EB8}
ows_FSObjType: 16683;#0
ows_Created: 2012-08-08 14:06:16
ows_FileRef: 16683;#sites/dn/Lists/VM Host Inventory/16683_.000

ows_MetaInfo: 16683;#

<#######################################################################################################################>

Add New Items to SharePoint List : –

Let me add a new item to the list with the below properties. To Add a new list item to a SharePoint list, we just need to modify the xml content and update Cmd=’New’


 

Delete Items from SharePoint List : –

Now let me show an example to delete a list item from SharePoint list, we just need to modify the xml content and update Cmd=’Delete’

Here im deleting the row which has an ID of 16683 which we previously modified.


I hope you learned something good from this post “Manipulating SharePoint Lists with PowerShell” 🙂 Thanks!

Please follow and like us:

Share this post

2 thoughts on “Manipulating SharePoint Lists with PowerShell

Post Comment