I you follow this blog, you might have read that I have been working ‘intensively’ on Sharepoint. I actually didn’t know Sharepoint before starting the two simultaneous Sharepoint projects begin of this year. But I know PowerShell, and I can say one thing for sure: Sharepoint has  A LOT of automation to offer.

While I have been asked to automate more and more stuff, I noticed that we could find a big range of examples spread all over the internet. No matter what you try to automate, you can get examples (more commonly CSharp examples actually) on the internet.

  • How to create SharePoint list with powershell?
  • How To create a list Item using PowerShell?
  • How to create Sharepoint Web part with Powershell?

A lot of theses examples can be found on the internet. What I noticed while finding the different examples (when there were PowerShell examples), is that most of them were not written as ‘Advanced functions’, and sometimes, not as functions as all.

Quite often I could actually not find any example on some particular tasks I was searching to automate, so a reverse engineering process started, and had to write the function from scratch. I had so much fun in writing these cmdlets that I actually decided to create my own Sharepoint 2013 farm in my lab (If you are curious how I did, check my post here –> How I created my Sharepoint Farm lab using AutoSpInstaller). I have written quite a few cmdlets that I actually did not needed in any of my projects, but each time I saw how I could automate it, I just did it 🙂

You simply want to download the module. Get it here –> You simply want to download the module? No worries! get it here –> Download on Technet

Why a Sharepoint powershell module?

Isn’t there already built-in SharePoint powershell cmdlets?

Absolutely! But I like to simply things to a maximum, and love to have a easy to use and end user friendly way of using automation (the end user’s here would be ITPros, Devops Engineers, and System admins) . This makes things really easier I think.

The end result is a Sharepoint PowerShell module composed of 35 SharePoint powershell cmdlets that I have named “Sharepoint-Community” module.

I have written part of it yes, but I got also bits of it from several different sources on the internet. (If you are the author of any of these functions, and want me mention you in this article, please drop me a line and I will be glad to do so! :)).

See at the bottom of this post to get a full list of the available cmdlets.

I also recently discovered the power of REST + PowerShell. I have working on automating things in my lab and I am pretty close to release a similar type of module, but this time 100% on Powershell + REST, so stay tuned!

How does this Sharepoint community powershell module works?

Well, there is nothing really complex about it. I tried to respect a certain logic in the way the connection would be done. In (almost) all the cmdlets, you can find two parameters:

  • -Url
  • -Web

Parameter -Url

Basically, if you need to get the list items from a specefic list, I would recommend you use this (the -url) parameter.  In the background, the cmdlet will do a Get-SpWeb, of the specefied url. A typical example would be something as follow:

This would return all the list items that are present in the list “Server Inventory” hosted on the “Config” site.

Parameter -Web

This would be the recommend approach. Use Get-SpWeb to first put in memory the site where you want to do the automation on, and then, use each cmdlet using the -Web Parameter and passing the $web parameter. This would be a typical example:

It is important to release the memory by using the $web.dispose() at the end of your script.

PowerShell SharePoint community cmdlets:

Here is the list of all the available cmdlets in powershell Sharepoint Community Cmdlets:

Add-LinkToQuickLinks
Add-SpContentTypeToLibrary
Add-SpFieldToContentType
Add-SpItemToPromotedLinkList
Add-SpUSerToSpGroup
Add-SpWebPart
Get-SharepointVersion
Get-SpContentType
Get-SpField
Get-SpGroup
Get-SpGroupMembers
Get-SpItemFieldValue
Get-SPLibraryFile
Get-SPList
Get-SpListItem
Get-SpListTemplate
Get-SPPropertyBagValue
Get-SpSiteGroup
Get-SpWebPart
New-SharePointLibrary
New-SpcontentType
New-SpDefaultSiteGroups
New-SpField
New-SPList
New-SpListWebPart
New-SPPropertyBagValue
New-SpSiteGroup
Remove-SpContentType
Remove-SpField
Remove-SpList
Remove-SpListItem
Remove-SpLisTtemplate
Remove-SpWebPart
Set-SpItemFieldValue
Set-SpPropertyBagValue

A few examples of what can be achieved using the PowerShell Sharepoint Community module:

How to work with SharePoint list Items using powershell:

How To get a SharePoint list item with PowerShell?

How to get a sharepoint field value using powershell?

How to Set a sharepoint item field value using powershell?

How to delete a Sharepoint list item using PowerShell?

How to create a sharepoint Contenttype using powershell?

How to list all sharepoint contentTypes using powershell?

 

One notice, you need to load the powershell sharepoint snapin before calling any of the commands above (simply add the following line at the top your Sharepoint powershell scripts)

Sources:

Do you want to join the fun, and participate in the writings of this module? Easy, the project is available right here –>  https://github.com/Stephanevg/PowerShell-Sharepoint-Community

You simply want to download the module? No worries! get it here –> Download on Technet

By | 2016-10-19T21:00:13+00:00 July 20th, 2015|PowerShell, sharepoint|1 Comment

About the Author:

Stéphane is a dynamic and passionate Cloud and datacenter Microsoft MVP since. He is the founder of the Basel PowerShell user Group (BPUG), the co-founder of the French Speaking PowerShell UserGroup (FRPSUG), author, blogger, and received the community award "PowerShell Hero" from PowerShell.org. Stéphane has implemented microsoft infrastructure solutions in various countries of Europe and is currently working in Basel / Switzerland. Stéphane help his clients to reduce their global infrastructure costs by implementing Microsft infrastructure solutions by combining great products such as System Center, Windows Server, with heavy automation using Windows PowerShell. Stéphane loves languages, Belgium beer, French cheese and French Wine. If any of these topics are of your interest, don't hesitate to come and say hi.

One Comment

  1. Wahid Saleemi (@wahidsaleemi) July 20, 2015 at 11:29 pm - Reply

    Very nice! To get even more commandlets, you can also load https://sharepointpowershell.codeplex.com/. (uses CSOM) and these http://www.thelapointes.com/blog/Lapointe.SharePointOnline.PowerShell.msi. I think most of the CSOM ones will work for on-premises too.

Leave a Reply

%d bloggers like this: