Title of the question is pretty simple, I have 18000 site collections and this script is showing 1GB of ram used, so I wonder how can I dispose correctly the spweb and spsite object
$webapplication = Get-SPWebApplication http://xxx
foreach($site in $webapplication.Sites)
{
foreach($subWeb in $site.AllWebs)
{
if($subWeb.AllProperties["WebTemplate"] -eq "Client" -or $subWeb.AllProperties["WebTemplate"] -eq "Job")
{
if($subWeb.AllProperties["WebTemplate"] -eq "Client")
{
$infoList = $subWeb.Lists["Client Info"]
}
if($subWeb.AllProperties["WebTemplate"] -eq "Job")
{
$infoList = $subWeb.Lists["Job Info"]
}
if($infoList -ne $null)
{
$InfoItem = $infoList.Items[0]
if($InfoItem -ne $null)
{
$clientCode = $InfoItem["Client Code"]
$quicklaunchnavigationnodes= $subWeb.Navigation.QuickLaunch
foreach($navNode in $quicklaunchnavigationnodes)
{
if($navNode.Title.Contains("Tax Invoices"))
{
$clientcodefromurl = $navNode.Url.Substring($navNode.Url.IndexOf("=")+1,8)
if($clientCode -ne $clientcodefromurl)
{
Write-Host 'Processing site ' $subWeb.Url
Write-Host ' Info list found for ' $subWeb.Url
Write-Host ' Info item found '
Write-Host ' Client code from url: ' $clientcodefromurl
Write-Host ' There is a difference' -ForegroundColor Red
Write-Host ' Incorrect Navigation Url: ' $navNode.Url
Write-Host ' New Url: ' $navNode.url.Replace($clientcodefromurl, $clientCode)
#$navNode.url.Replace($clientcodefromurl, $clientCode)
#$navNode.Update()
Write-Host ' Url updated' -ForegroundColor Green
}
}
}
}
else
{
Write-Host ' Info item not found '$spWeb.Url
}
}
else
{
Write-Host 'Info list not found for ' $subWeb.Url
}
}
}
}