Sometimes we need to perform small administrative tasks in SharePoint. A simple PowerShell script is a really good tool for that. For instance, such script can enumerate event handlers of a list:
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$site = new-object Microsoft.SharePoint.SPSite($args[0])
$site.RootWeb.Lists["MyList"].EventReceivers > C:\MyListHandlers.txt
It's known that objects like SPSite
and SPWeb
have to be Dispose()
-d after a call, otherwise memory leaks occur. The best would be to call
$site.RootWeb.dispose()
$site.dispose()
at the end of this script. But if this is a Powershell script which will only be run once, and we know that PowerShell cleans up after execution - is it so bad to not call dispose()?
So, my question is - is there some danger if sometimes I run scripts like this; will it affect the overall stability of SharePoint farm (or of the server on which I'm running the script)?