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:
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:
Get-SpListItem -Url http://sp.district.local:3000/sites/Config -ListName "Server Inventory"
This would return all the list items that are present in the list “Server Inventory” hosted on the “Config” site.
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:
$Web= Get-SpWeb -Identity "http://sp.district.local:3000/sites/Config"
#Do automation on sites
$items = Get-SpListItem -web $web -ListName "Server Inventory" -ItemName "Server01"
Remove-SpListItem -Web $Web -ListName "Server Inventory" -ItemName "Server10"
#End of automation operations
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:
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?
Get-SpListItem -Url http://sp.district.local:3000/sites/Config -ListName "Server Inventory" -ItemName "Server01"
How to get a sharepoint field value using powershell?
Get-SpItemFieldValue -Url http://sp.district.local:3000/sites/Config -ListName "Server Inventory" -ItemName "Server01" -FieldName "Description"
How to Set a sharepoint item field value using powershell?
Set-SpItemFieldValue -Url http://sp.district.local:3000/sites/Config -ListName "Server Inventory" -ItemName "Server01" -FieldName "Description" -FieldValue "NewDescription"
How to delete a Sharepoint list item using PowerShell?
Remove-SpListItem -Url http://sp.district.local:3000/sites/Config -ListName "Server Inventory" -ItemName "Server10"
How to create a sharepoint Contenttype using powershell?
New-SpcontentType -Name "NewContentType" -Description "My new ContentType" -Group "DistrictCTs" -web $Web
How to list all sharepoint contentTypes using powershell?
Get-SpContentType -Web $web
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)PowerShell
1 Add-PSSnapin microsoft.sharepoint.powershell
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