Remove-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinueAnd that's it, you can now loop through all SPWeb objects in your site.
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteUrl = read-host "What is your site url? Eg: http://mysharepointpotal"
$site= Get-SPSite $siteURL
$webs= $site.AllWebs
try
{
foreach ($web in $webs)
{
Write-Host $web.url
# Perform operation
}
}
catch
{
write-host -f Red "error" $_.exception
$errorlabel = $true
}
Happy scripting :-)