SharePoint: Powershell Get-SPSite in WSS 3.0

This simple Powershell snipplet gets the SPSite site instance in Windows SharePoint Services 3.0. Script also traps the exception in case of non-existence of SharePoint
site located at $url.

function global:Get-SPSite([string]$url) {
$site = $null
trap [Exception] {
continue;
}
$site = new-object Microsoft.SharePoint.SPSite($url)
return $site
}

… and here is an implementation:

$site = Get-SPSite($URL)
if ($site) {
#your code
}
else {
Write-Host -ForegroundColor Red "ERROR: Site $URL has not been found"
}
Trefný Luděk

Author Trefný Luděk

More posts by Trefný Luděk

Leave a Reply