I want to use PowerShell to loop through my SharePoint and dispose all objects properly.
I don´t want to generate entrys in the SharePoint log like this:
An SPRequest object was not disposed before the end of this thread. To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it. Due to flags specified at object creation, this will not be freed until processed by garbage collection.
Is the following PowerShell code ok?
$WebApps = Get-SPWebApplication
foreach($WebApp in $WebApps)
{
$Sites = $WebApp.sites
foreach($Site in $Sites)
{
$Webs = $Site.AllWebs
foreach($Web in $Webs)
{
Write-Host "Url: " $Web.url
$Web.Dispose()
}
$Site.Dispose()
}
}
$WebApps = $Null