How to Run a Power Shell Script in SharePoint 2010


In this article I am showing you how to execute power shell scripts. It is useful if you want to do the same set of command regularly. You don't have to type the entire command again just run the script as I shown below

Here I am taking the example of creating a site collection using power shell I already have an article for it Please find the article url below


The command to create a site collection is

$template = Get-SPWebTemplate "STS#0"
New-SPSite -Url "your Site collection URL" -OwnerAlias "domain\user" -Template $template
  1. First step is to copy your script to a note pad and save as with .ps1 extension

  2. In my case I saved the script as SiteCollection.PS1 and saved in my D drive under the folder Script. Now we have to open the power shell.

  3. On the Start menu, click All Programs.

  4. Click Microsoft SharePoint 2010 Products.

  5. Click SharePoint 2010 Management Shell.

  6. At the Windows Power Shell command prompt type the following command: 

    1.gif

  7. You will get a Power shell command prompt like below

    2.gif

  8. The command to run Power shell script is 

    &"D:\Script\siteCollection.ps1"

  9. Please find below the script in action

    3.gif