Connecting To Sharepoint
The first time i came in contact with PowerShell was when i started working with SharePoint Services 3.0 Since WSS 3.0 has great .NET support, it felt like the obvious approach to manage WSS 3.0 through PowerShell.
There are two great sites on the internet that contain loads of information on PowerShell and SharePoint. First we got Adventures In SPWonderLand. This is Colin Byrne’s blog and it’s one of the best sites on PowerShell and SharePoint containing tons of examples, functions and explanations. So i strongly recommend that you visit his blog.
Microsoft have a virtual lab thats based on Colins blog. Running through this Virtual Lab is a great starting point when working with SharePoint through PowerShell: TechNet Virtual Lab
Anyway, lets start off by connecting to a sharepoint site. Through Internet Explorer, the site looks like this:

It’s a a newly installed site, http://wss/
at the moment it doesn’t contain any data except for the standard Sharepoint stuff.
In order to connect to the site through Powershell, we have to make Powershell aware of Sharepoint.
this is done through the Reflection.Assembly Class.
PS > [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
GAC Version Location --- ------- -------- True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\Microsoft.SharePoint\12.0.0.0...
Now that we’ve made PowerShell aware of the Sharepoint classes, we can start a connection to the site through PowerShell.
PS > $SPSite = New-Object Microsoft.SharePoint.SPSite("http://wss"); $SPSite; $SPSite.Dispose()
The connection above is the startingpoint when interacting with Sharepoint through PowerShell. The object contains alot of interesting information about the site. The output is shown below.
Note that the command is written on a single line and the Dispose() method is called in the end. This is because of a memory leakage issue. You can read more about it here.ApplicationRightsMask : FullMask ID : 878764e2-8460-4402-8776-ea82051e7ab4 SystemAccount : SHAREPOINT\system Owner : BPA\sharepoint SecondaryContact : GlobalPermMask : FullMask IISAllowsAnonymous : False Protocol : http: HostHeaderIsSiteName : False HostName : wss Port : 80 ServerRelativeUrl : / UpgradeRedirectUri : Zone : Default Url : http://wss Impersonating : False Audit : Microsoft.SharePoint.SPAudit AllWebs : {} Features : {695b6570-a48b-4a8e-8ea5-26ea7fc1d162, ca7bd552-10b PortalUrl : PortalName : LastContentModifiedDate : 1/5/2009 10:21:57 PM LastSecurityModifiedDate : 1/5/2009 10:17:25 PM CatchAccessDeniedException : False AllowUnsafeUpdates : True UserToken : Microsoft.SharePoint.SPUserToken IsPaired : False SearchServiceInstance : SPSearchServiceInstance Parent=SPServer Name=WSS WebApplication : SPWebApplication Name=SharePoint - 80 Parent=SPWebS ContentDatabase : SPContentDatabase Name=WSS_Content Parent=SPDatabas Quota : Microsoft.SharePoint.Administration.SPQuota RootWeb : Team Site LockIssue : Usage : Microsoft.SharePoint.SPSite+UsageInfo ReadLocked : False WriteLocked : False ReadOnly : False WarningNotificationSent : False SyndicationEnabled : True AllowRssFeeds : True CertificationDate : 1/5/2009 10:17:13 PM DeadWebNotificationCount : 0 RecycleBin : {} CurrentChangeToken : 1;1;878764e2-8460-4402-8776-ea82051e7ab4;6336679091 WorkflowManager : Microsoft.SharePoint.Workflow.SPWorkflowManager

