I am looking to create some scripts that I will need for my SharePoint, but my power-shell skills are very bad. Is there any good tutorial that will help me become better at it ? It can be anything and it should start from the basics. I have windows server 2012 r2 and SharePoint 2013.

2 Answers 2


I think it's very hard to have a comprehensive tutorial for SharePoint 2013 powershell. There's so much you can do and to condense all of that into a guide is hard. I would try starting at Technet: Google tasks that you might think you'd need to complete. (Again, everyone uses SharePoint for different reasons, and so that'd also make a 'complete guide' hard to come by).

A simple start is:

  • Start-Transcript - Always keep a record of what you type in! It might come in handy one day. This isn't strictly SharePoint 2013, but..... still handy :)
  • Get-SPContentDatabase / Get-SPWebApplication / Get-SPServiceApplicationPool / Get-SPSite - ETC. The "get" commands are good to start with because it shows how much information you can retrieve without really changing anything on your farm. PowerShell is both, well, POWERful (haha), and also dangerous as it gives you more room to complete large tasks.

Once you get comfortable, trying (perhaps in a sandbox environment) to create items using PowerShell. These all start with New-SP___________. Try New-SPWebApplication (http://technet.microsoft.com/en-us/library/ff607931(v=office.15).aspx) to start and get a feel for PowerShell syntax and what will usually happen.

It's important to keep in mind that some tasks don't happen automatically, so when in doubt, wait a few minutes to see if PowerShell responds before going to drastic measures.

I haven't written extremely nice scripts like experts on the internet, so I'm only a provision-farm-and-service-applications-and-web-applications kind of PowerShell user. I hope that helps, though.

Sorry I can't help with more complicated scripts.


there are a few introductory things you need to be aware of

  • executionpolicy: you will probably disable it completely (set-executionpolicy unrestricted) or set a temporary state and revert back when you are done. this is a must in order for you to run your own scripts inside a sharepoint farm
  • Understand you can use logging (start, stop transcript), exception handling, multiple script files (include with . .\myscript.ps1), variables and functions for reusability
  • you still need to worry about disposing your objects, such as spweb
  • powershell is much more to it than coding. you should master piping, regular expressions and know the common operations, such as -gt, -lt, -eq, etc
  • you can load numerous assemblies on top of powershell. smtp libraries, openxml for office documents, etc
  • on the top of my scripts I tend to validate if the sharepoint dll was loaded, and load it if it is required. I also move the path to the location of the current running script so that I am sure about where I am (available below)
  • make sure sp administration and sp timer services are running
  • im sure there are tons of other things Im forgetting. anyway, If you are new, start with regular powershell and then move to sharepoint. there are really good courses for both on the microsoft virtual academy, and check channel 9 and pluralsight videos as well



#go to me
$currentFolder = Get-Location -PSProvider FileSystem
$invokedFolder = [regex]::Replace($MyInvocation.MyCommand.Definition, "\\nameOfThisScript.ps1", "")
if($invokedFolder -ne $currentFolder){ cd $invokedFolder }

#enable sp snappin
If ((Get-PsSnapin |?{$_.Name -eq "Microsoft.SharePoint.PowerShell"})-eq $null)
    Write-Host -ForegroundColor White " - Loading SharePoint Powershell Snapin"
    $PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null

btw, Catherine made some good points herself, specially about verbs (get, set, new), so make sure to check them out

this is getting too long but i still want to point out a few common cmdlets

#add wsp package (takes fullname)
Add-SPSolution -LiteralPath (gi ./MySolution.wsp).FullName

#deploy wsp package (global or web app scope)
Install-SPSolution MySolution.wsp -GACDeployment
Install-SPSolution -WebApplication http://MyWebAppUrl MySolution.wsp -GACDeployment

#activate wsp package feature (specific site)
Enable-SPFeature MySolution -Url http://myurl

#update existing deployed solution
Update-SPSolution -Identity MySolution.wsp -LiteralPath (gi ./MySolution.wsp).FullName -GACDeployment

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.