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;
<#
.SYNOPSIS
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
{
param
(
[PSObject]$Queryobject,
[string]$PropertyName
)
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.
$CurrentExceptions=$CurrentFilter=$Null
If(Get-PropertyExists -Queryobject $Pair -PropertyName ExceptionList)
{
$CurrentExceptions=@($Pair.ExceptionList.Exception)
}
If(Get-PropertyExists -Queryobject $Pair -PropertyName Filter)
{
$CurrentFilter=$Pair.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.