PowerShell and SharePoint, Step 1: Loading the DLLs and Snap-Ins

Windows PowerShell has come to SharePoint, for real, cmdlets and all, with SharePoint 2010. Over the coming weeks and months, you’ll get lots of guidance about when, how, and why to use PowerShell to administer and automate SharePoint. Today, let’s start at the very beginning: Getting PowerShell up and running to manage SharePoint.

Before you begin, you have to make sure that Windows PowerShell is installed on your computer. If you’re working directly on a SharePoint 2010 server—for example, in development or in a lab—then you have PowerShell, because it’s a prerequisite for installing SharePoint 2010, so it’s got to be there already!

If you’re working on a computer that doesn’t have PowerShell, you need to install it. Windows PowerShell v2, included with Windows Server 2008 R2, supports remoting, meaning you can run PowerShell on your computer against another system—a server for example—without having PowerShell on that system.  If you’re familiar with PSExec, it’s a similar idea, but on steroids.  We’ll cover remoting in a later column.

After PowerShell is installed, you need to ensure that you can actually touch and manipulate SharePoint. There are three ways to do this.

First, you can load the SharePoint DLLs. This is akin to what is done to use PowerShell in SharePoint 2007. Open PowerShell and type the following command:

[AppDomain]::CurrentDomain.GetAssemblies() | ForEach-Object 
  { Split-Path $_.Location -Leaf } | Sort

You’ll see that no SharePoint DLLs are loaded by default. Then type the following:

Then repeat the first command, and you’ll see that DLL loaded.

Unfortunately, you would have to do this for each of the SharePoint DLLs, and there are many (as you’ll see). That gets mighty dull.

Now, with SharePoint 2010, there is a SharePoint snap-in for PowerShell that does all the work for you. Type the following command:


The snap-ins that are loaded in the current session are listed. Now type:

Get-PSSnapin –Registered

You’ll see all of the available snap-ins. Add what you need by typing:

Add-PSSnapin Microsoft.SharePoint.PowerShell 

Now repeat the Get-PSSnapin command, and then the GetAssemblies() call that was listed earlier. You’ll see that a LOT more is loaded.

Still too much work for you? Me too! So just open the SharePoint 2010 Management Shell.

This beautiful new “command prompt” is Windows PowerShell with everything you need pre-loaded (so the shell takes a few moments to open), plus it can support command-line commands including stsadm, because it has the %PATH% variable set to include the location of stsadm.exe. Sweet! So that, really, is the answer.

Next, you’ll need to be sure that you’ve delegated administrators the ability to actually use PowerShell. You’ll find out that even you cannot use it until you’ve given yourself permissions (unless you happen to “own” the entire SQL server). Learn how to delegate the ability to use PowerShell at the article titled "T'is a Privilege to PowerShell."


Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.