I am an nube to Powershell, so I think I have a pretty basic question here....
How do I determine if a SPWeb exists? I want to perform some operations on a site based on a URL passed in as a parameter. However, there are instances where the site may not exist. I have tried something like
$test = Get-SPWeb($siteToGet)
if ($test -eq $null ) {
Write-Host Site $siteToGet does not exist
}
else {
Write-Host Site $siteToGet DOES exist
}
where $siteToGet is not a valid site. However, I get an error message on the Get-SPWeb saying in red saying the site does not exist. The rest of the code then runs. Is this okay? I would prefer to log a message instead of display the error message from Get-SPWeb. It also causes more error messages as my script continues to run, but by checking for $null I can at least make sure I am not executing further code.
Any ideas how to check for the existence of a site using PowerShell and SharePoint 2010?
Thanks