Jesper M. Christensen

SharePoint and Security

Sharepointing with Windows Powershell


Recently I needed a specific function for my Sharepoint lists: Updating multiple items in a list. I thought of workflows instantly and found many good articles and blogs on how to manipulate the items but not quite changing searched items with data from another list. Then I fell over the Windows Powershell for Sharepoint on Karine Bosch blog – and Windows Powershell really has all the tools you need!

  • Create sites and mundane configurations easily
  • Batch import, export and manipulate Sharepoint items
  • Run jobs at a specific time with Windows scheduler (workflows are action-based)

As other blogs mention there isn’t much information and examples online, but browsing around the Internet can give you the information you need to build your scripts the way you want it. Some articles also import the Visual Studio 8 tools, but I just needed the script to work on my Sharepoint servers locally with installing Visual Studio.

Start with Sharepoint Powershell for beginners and Sharepoint Powershell for beginners – continued by Karine which will guide you through the basics. She also has an excellent post about Update a Sharepoint list with Powershell.

If you do not want to use CAML queries (an excellent CAML builder exist at U2U Community tools) you can query the lists and filter through Powershell even though the performance isn’t the best if you have many items in the list. I have included an example below with comments for you. Change the first lines to match your environment and run the commands on one of your Sharepoint servers.

#Define various data
$siteUrl = "http://intranet.domain.local"
$webName = "/"
$ContactslistName = "Contacts"

#Set up connection to the Sharepoint site
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$spSite = new-object Microsoft.SharePoint.SPSite($siteurl)
$spWeb = $spSite.OpenWeb($webName)

#Set up the list connection
$spListContacts = $spWeb.Lists[$ContactslistName]
$spListContactsCol = $spListContacts.items

#Get and show the list of contacts working in Dallas
$spListContactsCol.GetDataTable() | where-object{$_.WorkCity -like "Dallas"} | ft FullName, WorkAddress, WorkZip, WorkCity

Using the Windows Powershell gives you endless possibilities without programming and compiling in Visual Studio. Explore the shell and what it can do for your solutions.

Links to more information about Powershell and Sharepoint

Great info by Karine Bosch: http://www.u2u.info/Blogs/karine
Adventures in SPWonderland: http://blogs.flexnetconsult.co.uk/colinbyrne/CategoryView,category,PowerShell.aspx
Dataset/datatable output: http://mow001.blogspot.com/2006/05/powershell-out-datagrid-update-and.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: