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

This update corrects an issue where parts of the configuration XML are missing;  what if you don’t want Exceptions or Filters?I noticed when parts of the XML were missing errors were generated.  As the script imports XML into an object I needed a function to test the existing of properties on that object, as below;

    Returns if a property of an object exists.
.PARAMETER Queryobject
    The object to check the property on.
.PARAMETER PropertyName
    The name of the property to check the existance of.
function Get-PropertyExists
    Return (($Queryobject | Get-Member -MemberType Property) -contains $PropertyName)

It takes $QueryObject and gets a list of all the properties on it (via Get-Member) and checks if the passed $PropertyName is listed there.

        If(Get-PropertyExists -Queryobject $Pair -PropertyName ExceptionList)
        If(Get-PropertyExists -Queryobject $Pair -PropertyName Filter)
        Sync-OneFolder -SourceFolder $Pair.Source -TargetFolder $Pair.Target -PassedExceptions $CurrentExceptions -Filter $CurrentFilter |
             Tee-Object -Variable Changes

In the main body of the script it only sets $CurrentFilter and $CurrentExceptions if there’s an existing entry in the XML.

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 )

Connecting to %s

%d bloggers like this: