PowerShell: Synchronizing a Folder (and Sub-Folders) Part 11

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.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s