Microsoft MVP Logo

In the last interview I did with the Rob Foster on the SharePoint PodShow (#17), I mentioned a PowerShell script I use to prep my PowerShell command environment with stuff I need. Got a few hits on Twitter requesting this so here ya go.

Namely, it loads common SharePoint assemblies and sets an alias to STSADM. I got the idea from an old post on Karine Bosch's blog (note, she has a new blog here).

Copy the contents of this file into a new text file and save it to a common place on your machine. I call mine LoadSPAssemblies.ps1 and put it into a SharePoint utility folder I have in Mesh (sync'd to all my dev machines... both physical and virtual):

set-executionpolicy unrestricted

[System.Reflection.Assembly]::Load("Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c")[System.Reflection.Assembly]::Load("Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c")

new-alias "stsadm" ($env:CommonProgramFiles + "\Microsoft Shared\web server extensions\12\BIN\stsadm.exe")

Then, when I need to use it I just type the path to the PS1 file and it loads the assemblies and sets an alias to STSADM. Of course, your assemblies may differ... I just do a lot of work with the Publishing namespace. :)

[Updated 3/12/2009] Updated to no longer use the LoadWithPartialName and instead use the Load method. Thanks to the commenter below.

Comments powered by Disqus