Monday, January 28, 2013

Load SharePoint PowerShell Commandlets in the PowerShell ISE

We know that Windows PowerShell ISE is a nice editor for writing and executing PowerShell scripts. But for SharePoint Administrators/Developers none of the SharePoint PowerShell Command-lets are loaded by default, so need to Add the Snap-In explicitly. But I wanted to load the SharePoint snap-in to ISE one-time and use it further without loading again-and-again.

Execute the below PowerShell script in ISE to load the snap-in to ISE profile.
if (!(test-path $profile.AllUsersAllHosts)) 
{
   new-item -type file -path $profile.AllUsersAllHosts-force
}

$cmd = 'if((Get-PSSnapin | Where-Object {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) { Add-PSSnapIn "Microsoft.SharePoint.Powershell" }'

out-file -FilePath $profile -InputObject $cmd -Append
Now close and open the ISE, It will load SharePoint snap-in automatically. Intellisense is available for all the SharePoint Command-lets.

Alternatively a single line of statement can be added to ISE to load the SharePoint SnapIn
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
Hope this saves your time... 

No comments:

Post a Comment