Scripting inside SharePoint with PowerShell - PART I Getting Started...
By Michael on Saturday 17 October 2009, 18:41 - Windows SharePoint Service 3.0 - Permalink
Download the following tools:
_PowerShell for windows 2003: http://www.microsoft.com/downloads/details.aspx?FamilyID=10EE29AF-7C3A-4057-8367-C9C1DAB6E2BF&displaylang=en
_Powergui: http://www.powergui.org/downloads.jspa , this is optional but is a very useful gui for scripting and navigating between methods and class...
_Powerpacks for SharePoint: http://www.powergui.org/kbcategory.jspa?categoryID=354
Install all products and when you are finished to install Powergui, add the SharePoint packages.
Note:Keep in mind, you can write yourscript only on the WSS server because the remote commands does not exists, all tools must be installed on one of WSS server who is member of your farm.
The basics...
When you write a script for WSS, the first line begin by:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") | Where-Object { $_.GetType().FullName -ne "System.Reflection.Assembly" } --->Recomended
OR
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") --->In some examples through Internet...
After loading into the GAC the DLL for SharePoint, you must to connect on the site where you need to script...
$SiteUrl = http://yoursite
#Creating your SP site object....
$Site = new-object Microsoft.SharePoint.SPSite($Site)
After that, you can display for example the site properties:
$Site.AllWebs | format-table | URL, LastItemModifiedDate, Created
Note: If you use the SharePoint PowerPack, you can browse through the $Site variable and you can see all propreties and methods.