I have been doing a lot of scripting lately and came across memory considerations recently as we are in the phase of running scripts in production environments.
Basically what I do throughout my scripts is:
Start-SPAssignment -Global
Get-SPWebApplication $webApplicationUrl | Get-SPSite -Limit All | foreach {
$_.AllWebs | foreach {
$_.Lists | ? { $_.BaseType -eq "DocumentLibrary" } | foreach {
#Logic goes here like writing info about the list into CSV
}
}
}
Start-SPAssignment -Global
What we noticed after running above script in an environments with 3000+ site collections and 10000+ lists is that PowerShell process eats up to 1,5+ GB of memory, I guess I'm doing the disposal the wrong way! Or is that normal?
Should I try something like below instead?
Get-SPWebApplication $webApplicationUrl | Get-SPSite -Limit All | foreach {
$siteAssignment = Start-SPAssignment
$_.AllWebs | foreach {
$webAssignment = Start-SPAssignment
$_.Lists | ? { $_.BaseType -eq "DocumentLibrary" } | foreach {
#Logic goes here like writing info about the list into CSV
}
Stop-SPAssignment $webAssignment
}
Stop-SPAssignment $siteAssignment
}
Or should I try a whole different approach? Thankful for you ideas over this case!