Adding a -PassThru option and fixed a very odd bug.
The new updated script is here.
The bug was peculiar. It seems in some cases, PowerShell will add $Null to an array. You then have a $Null object as a member of the array, which is different to an empty array! The problem occurs when I tried to enumerate through all the changes made for the report;
Foreach ($Change in $Changes) { switch ($Change.Process)
If $Change was $Null then $Change.Process would cause an error! I tracked it down to the Tee-Object command and I added the following just afterwards;
if($FolderChanges -ne $Null) { $Changes+=$FolderChanges }
Problem solved!
The last addition was to make the script outputting all the report objects it generates optional. If you specify -PassThru as a switch it will return all the objects as before. But if you don’t, you just get the report written to the host at the end which makes it easier to see what’s going on.