harbar.net component based software & platform hygiene

Adding SharePoint 2010 PoweShell cmdlets to your PowerShell ISE

Print | posted on Monday, May 03, 2010 11:55 PM

PowerShell for SharePoint 2010 rocks. No, really it does. You hate it at first, but then it’s all pure goodness. But boy, does the UI SUCK! Crap for productivity, crap for demos, just about crap for anything other than lame jokes about old skool shell scripting.

Sure, there are funky PowerShell GUIs out there, but they appear to cost money. The good news is Windows ships with it’s own IDE. This thing is called an ISE – prey how much do marketing people get paid?

Anyway – that’s what I’ve been using for all my demos to show the PowerShell stuff that I do. Better than a command prompt. Trouble is this bad boy doesn’t load the SharePoint cmdlets, so you have to do that before working with SharePoint.

The good news is you can add the guff necessary to load the DLL in a PowerShell ISE profile. It’s a very basic thing, but you may find it useful. To set it up, use the following PowerShell. This one is a user profile, you can change this to be a machine wide one if you wish (refer to this article).

# creates a local user powershell ISE profile
if (!(test-path $profile )) 
{new-item -type file -path $profile -force} 

# opens it for edit
psEdit $profile

# copy the following into the new file and save it
cd 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration'
.\SharePoint.ps1
cd \

# now everytime you run powershell ise as the same user - it will load the SP cmdlets automatically on start up

Happy ISEing!

Feedback

Gravatar

# re: Adding SharePoint 2010 PoweShell cmdlets to your PowerShell ISE

To avoid errors with the snap-in being loaded more than once try adding this code instead of referencing the sharepoint.ps1 script (basically recreates the contents of that script and only loads if the snap-in isn't loaded and if you're not in the management shell as the management shell will execute your profile code first so the sharepoint.ps1 script will error otherwise):

if ($host.UI.RawUI.WindowTitle -ne "Administrator: SharePoint 2010 Management Shell") {
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$host.Runspace.ThreadOptions = "ReuseThread"}
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null) {
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
}

5/4/2010 1:55 AM | Gary Lapointe
Gravatar

# re: Adding SharePoint 2010 PoweShell cmdlets to your PowerShell ISE

> This thing is called an ISE – prey how much do marketing people get paid?

ha ha ha. Us Engineers came up with that term. We didn't want to call it an "IDE" and confuse people by
1) thinking that it was for developers
2) confusing it with Visual Studio

Experiment! Enjoy! Engage!

Jeffrey Snover [MSFT]
Distinguished Engineer
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: www.microsoft.com/.../msh.mspx

5/5/2010 4:57 AM | Jeffrey Snover
Gravatar

# re: Adding SharePoint 2010 PoweShell cmdlets to your PowerShell ISE

"old skool shell scripting" - cracked me up.

5/26/2012 7:14 AM | Doug

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 7 and 8 and type the answer here: