Step 1: Install PowerShellPowerShell is standard on Windows Server 2008, Windows Vista and Windows 7. Any other Windows Operating Systems will require a 32-bit or 64-bit download of it from Microsoft web site Step 2: Execution PolicyTo do a lot of things in SharePoint you will need to modify the Execution Policy. This is talked about more here Set-ExecutionPolicy Unrestricted
Step 3: Create your PowerShell ProfileWhen PowerShell is installed you can create a profile so that everytime you run PowerShell common things are created. New-Item -path $profile -type file -force It will be located at C:\Documents and Settings{username}\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1. More information on Profiles is available here Step 4: Modify your profileOpen up your profile file and add these common functions and parameters ############################################################################ # Assumptions: # - Running on machine with WSS/MOSS # - C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN in path # - For development servers only, does not dispose of objects ############################################################################ # Example usage: # $list = get-splist -webUrl "http://site" -listName "Announcements" ############################################################################ $12HiveDir = "${env:CommonProgramFiles}\Microsoft Shared\web server extensions\12\" cd $12HiveDir [void][reflection.assembly]::Loadwithpartialname("Microsoft.SharePoint") | out-null [void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server.Search") | out-null [void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server") | out-null # Returns the SPSite at the specified URL function get-spsite ([String]$webUrl=$(throw 'Parameter -webUrl is missing!')) { return New-Object -TypeName "Microsoft.SharePoint.SPSite" -ArgumentList "$webUrl" } # Returns the SPSite object from the specified URL function get-spweb ([String]$webUrl=$(throw 'Parameter -webUrl is missing!')) { $site = New-Object -TypeName "Microsoft.SharePoint.SPSite" -ArgumentList "$webUrl" return $site.OpenWeb() } # Returns the SPList object from the specified URL and list name function get-splist ([String]$webUrl=$(throw 'Parameter -webUrl is missing!'), [String]$listName=$(throw 'Parameter -listName is missing!')) { $site = New-Object -TypeName "Microsoft.SharePoint.SPSite" -ArgumentList "$webUrl" $web = $site.OpenWeb() return $web.Lists[$listName] } Step 5: Inspect your Site CollectionYou can now run up PowerShell and calls these functions
$site = get-spsite "http://yourserver"
$site
$site.Features
This should output some information on your Site Collection Labels |
Getting started with PowerShell and SharePoint

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Hosted generously by CustomWare









Comments (4)
Jun 26, 2009
Jonathan Roussel says:
Aren't these functions a bit dangerous as they don't allow for easy disposing of...Aren't these functions a bit dangerous as they don't allow for easy disposing of the SPWeb and Site objects ?
I am not what one would called an experienced SP or PowerShell Dev, so I prefered to add a comment instead of modifying the page with what I think might be nice to add :
$site = get-spsite "http://yourserver"
.... Do your Stuff
$site.Dispose
$web = get-spweb "http://yourserver"
.... Do your Stuff with the web
.... As we lost reference to the SPSite object, I think (not sure at all) that we might get it back by using the SPWeb.Site property
$site = $web.site
$web.Dispose()
$site.Dispose()
$list = get-splist "http://yourserver" "MyListName"
.... Do your Stuff with the list
$web = $list.ParentWeb
$site = $web.site
$web.Dispose()
$site.Dispose()
Jun 26, 2009
Keith Dahlby says:
You are correct that the objects should be disposed, with two caveats: SharePo...You are correct that the objects should be disposed, with two caveats:
In practice, it's probably safe to let the objects leak as long as you don't leave PowerShell open on the server. These memory leaks only really matter if the code is called thousands of times, which most PoSh code isn't. On the other hand, if you have a long-running script that will open lots of SPSites/Webs, you will probably want to dispose properly.
Other dispose-related links:
Jun 26, 2009
Anonymous says:
To install PowerShell on Windows 2008, you can use the command "ServerManagerCmd...To install PowerShell on Windows 2008, you can use the command "ServerManagerCmd -install PowerShell".
(My SharePoint Blog) and @michaelbl on Twitter.
I have some examples of using PowerShell with SharePoint at codeplex.com/psbb (PowerShell Building Blocks for SharePoint).
-Michael Blumenthal, http://blumenthalit.net
Oct 16, 2009
Ricky Elias says:
Niklas Goude has written many helpful PowerShell scripts for SharePoint (Link).Niklas Goude has written many helpful PowerShell scripts for SharePoint (Link)
.