Enable SharePoint PowerShell Commandlets in the PowerShell ISE


In SharePoint 2010 we now have the ability to administrate our farms using PowerShell which is significantly more powerful than STSADM (out of box anyways). After working with PowerShell and figuring out the basics, you'll probably want to write a few scripts of your own. If you try to use the PowerShell ISE to author your scripts, you notice that none of your SharePoint commandlets are available to you by default. This is because the ISE has not loaded up the SharePoint PowerShell Snap-ins. To get the snap in loaded you'll need to add the snap-in in your PowerShell ISE profile. Here's a quick script to get this done from within the ISE, just type this in the ISE command window:

if (!(test-path $profile )) 
{ 
    new-item -type file -path $profile -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
 

Run the commands then close and open the ISE. You now should have the SharePoint snapin loaded and you should get the friendly auto complete functionality you're used to in the SharePoint PowerShell command window.

 

Happy Scripting!

Comments (2)
  1. Is there a way to administer SharePoint using PowerShell on my Windows 7 workstation as opposed to logging on to the SharePoint Server locally?

  2. TomWis says:

    Powershell 2.0 supports remote execution. Look into Invoke-Command, Invoke-Expression and PSSession commandlets

Comments are closed.

Skip to main content