Forum Discussion

Cole_McDonald's avatar
Cole_McDonald
Icon for Professor rankProfessor
2 years ago

Reversing property inheritance appliesTo Boolean "or" evaluation hack

We found a need to build dynamic groups to drive overnight patching SDTs for client environments.  This was going to end up being a very manual process adding properties to client parent folders to populate the patch day and the timezone they're in.  We were able to cut our effort in half by building a propertySource to gather the timezone of the server from WMI using win32_timezone and some basic text parsing.  But, we have instances where the client's timezone doesn't match the timezone of the servers (Central TZ, but servers in UTC).  To account for these, we'd need to be able to add an override at the client's parent folder level.  Unfortunately, the appliesTo would use the inheritance, which prefers the resource rather than the parent.  I was able to use a Boolean OR's evaluation order of operations to cheat that system:

(clientTZ=="Central" || resourceTZ=="Central)

If there is no clientTZ set at the group level, the first part of the OR evaluates as False the processor looks to the second part for the solution.  If the first part evaluates as True, the processor stops processing and  solves the whole clause (...) as True.

Thus, an unset group property prefers the resource, but a set group property prefers the parent.

1 Reply

  • Small correction.  Inherited Group properties can't be used in a dynamic Group appliesTo... so I've added property sources to pull an inherited property forward to the resource.

    $patchDay = "##clientTZ##"
    
    if ( $patchDay -ne "" ) {
        write-output "clientTZ=$patchDay"
    }

    As a result, have to change the OR clause:

    (auto.clientTZ=="Central" || auto.resourceTZ=="Central)