Getting Started: The Basics of Using PowerShell with SharePoint

I’m a SharePoint guy, and certainly no PowerShell expert. I know enough PowerShell to get things done in SharePoint from time to time. I can often go months without using PowerShell and talking to colleagues I don’t think I’m alone in the SharePoint community.

So if you are just starting out with using PowerShell to do something with SharePoint, or it’s been a while and you need a refresher on the basics then you’ve come to the right place.

Before we get started I’m writing this article based on SharePoint 2013 running on a Windows 2012 server.

The ground rules

1) Run your PowerShell scripts from the SharePoint server itself

It is possible to run PowerShell against a remote SharePoint server rather than on the server itself, but it requires some setup on the SharePoint server side and let’s face it, it’s not basic. If you need to do it you need to be searching for “Remote PowerShell in SharePoint”.

2) Use Windows PowerShell ISE (not SharePoint Management Shell)

PowerShell needs to be executed/run at a PowerShell Console or PowerShell Window – this window looks like a standard Command Line window and I don’t find it too inviting.

Instead of the SharePoint 2013 Management Shell, I use the Windows PowerShell ISE.


Why? It’s like comparing Visual Studio with Notepad. The ISE is an environment for developing PowerShell scripts that gives you nice syntax highlighting, debug with breakpoints, intellisense and more. It’s more like a development environment than a command line. I think you’d agree it looks slightly more advanced.


3) Ensure the SharePoint PowerShell snapin is loaded

When using the “SharePoint 2013 Management Shell” (the ugly black one) it automatically loads a “snapin” which is basically a PowerShell extension that gives you a series of commands for working with SharePoint objects. When you use the Windows PowerShell ISE it has no idea of SharePoint, so you need to load the SharePoint snapin manually. The simplest way to do this is just to add the following code snippet to the start of all your scripts.

if((Get-PSSnapin "Microsoft.SharePoint.PowerShell") -eq $null)
      Add-PSSnapin Microsoft.SharePoint.PowerShell


4) Save a script to file before you try to run it

Windows PowerShell ISE will have trouble running a script if you haven’t saved it to disk yet. PowerShell scripts are saved as files with a .ps1 extension.


5) Talk to SharePoint via the SharePoint PowerShell Cmdlets

Here’s a reference of all the SharePoint 2013 PowerShell Cmdlets you can use to work with SharePoint.


Your first script

Pre-flight checklist:

  • Start Windows PowerShell ISE
  • Add code snippet for loading the SharePoint snapin
  • Save the script as a .ps1 file


You can now start cutting and pasting examples from the internet and modifying them to work with your environment. The following 2 lines get a handle on the SharePoint website at the URL http://vs-server12 and then output the ID of the website.

To run the script and see if it work, click the Run button.


Any output from running your script is shown in the output window below the script editor.


You’re on your way, just remember you can only access the SharePoint server on which you are running your scripts. Accessing remote SharePoint servers is possible but you need to do special magic stuff to make that happen Smile


If you encounter an error along the lines of:

Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern “Microsoft.SharePoint.PowerShell” were found.

You’ve ignored ground rule 4 and the pre-flight checklist by forgetting to save your script before running it (yes, I still do this too).


About Cameron Dwyer

Architect and developer at OnePlace Solutions. Passionate about delivering compelling solutions on the Office 365/SharePoint platform. Addicted to coffee.

Posted on June 18, 2014, in PowerShell, SharePoint and tagged , , , , , , , , . Bookmark the permalink. 5 Comments.

  1. Hi, I’m on Windows 2012 but am running SharePoint 2010, is it possible to use Powershell or will I have to upgrade to SP2013?


  2. I didn’t ignore rule 4 and saved my file. I get an error message when running the SnapIn code.

    PS C:\> C:\Users\xyzUser\Downloads\Powershell\SPPowerShellSnapIn.ps1
    Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern
    ‘Microsoft.SharePoint.PowerShell’ were found. Check the pattern and then try
    the command again.
    At C:\Users\wongm03\Downloads\Powershell\SPPowerShellSnapIn.ps1:1 char:5
    + if((Get-PSSnapin “Microsoft.SharePoint.PowerShell”) -eq $null)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShel
    l:String) [Get-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.G

    Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version
    At C:\Users\wongm03\Downloads\Powershell\SPPowerShellSnapIn.ps1:3 char:7
    + Add-PSSnapin Microsoft.SharePoint.PowerShell
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShel
    l:String) [Add-PSSnapin], PSArgumentException
    + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.Ad


  1. Pingback: Sharepoint PowerShell – Getting started | Vikas D More

Leave a Reply

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

You are commenting using your 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: