PowerShell SharePoint snapin adding scriptlet

If you ever tried to run a SharePoint script, and did not do it from the “SharePoint 2010 Management Shell”, you know what I mean. You got something in the lines of:

“The term x is not recognized as a cmdlet, function, operable program, or script file, blah blah blah”

That’s because the “SharePoint 2010 Management Shell” besides running PowerShell also loads a snapin with SharePoint cmdlets. You have to do that too. Behold the code:

$snapin = Get-PSSnapin | Where-Object {$_.Name -eq ‘Microsoft.SharePoint.Powershell’}

if ($snapin -eq $null)
{
Write-Host “Loading SharePoint Powershell”
Add-PSSnapin “Microsoft.SharePoint.Powershell”
}

You just copy and paste this on the beginning of your PowerShell script, and voila. You can now say bye bye to the “SharePoint 2010 Management Shell” shortcut.

Leave a Reply

Your email address will not be published. Required fields are marked *


+ one = 5

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>