Altering Policy Target Lists

As depicted in section Policy Basics, Policies are an association between exactly one Software Package and one or more Policy Targets objects. Usually Policies might be assigned to only one target object. But technically multiple target objects are possible and therefore must be considered.


To alter the Target List of a Policy object you might want to store the Policy object into a PowerShell variable first. Then you can use the method AddTarget() to add target objects to the Policy. Consequently the method RemoveTarget() can be used to remove targets from the Policy Target List. The current entries of the target object's Target List can be retrieved by using the method GetTargetObjects(). Alternatively the IDs of the Policy targets resp. their names are available via the property TargetObjectList resp. the property TargetObjectNameList of the Policy object.


Examples:


Hint: The execution of these examples requires a connected PowerShell drive.


Add an additional target object to the Policy created in section Creating Policies:


$MyPolicy = Get-EmdbPolicy "emdb:\rootDSE\Managed Users & Computers\solys.local\Adobe Reader 9.0 systems" | Where-Object {$_.AssignedObjectName -eq "Adobe Reader 9.0"}

$MyNewPolicyTarget = Get-EmdbGroup "emdb:\rootDSE\Managed Users & Computers\solys.local\Adobe Reader 8.0 systems"

$MyPolicy.AddTarget($MyNewPolicyTarget)


Retrieve the current Policy targets:


$MyPolicy = Get-EmdbPolicy "emdb:\rootDSE\Managed Users & Computers\solys.local\Adobe Reader 9.0 systems" | Where-Object {$_.AssignedObjectName -eq "Adobe Reader 9.0"}

$MyPolicy.GetTargetObjects()


Remove the Group named "Adobe Reader 8.0 systems" from the list of policy targets:


$MyPolicy = Get-EmdbPolicy "emdb:\rootDSE\Managed Users & Computers\solys.local\Adobe Reader 8.0 systems" | Where-Object {$_.AssignedObjectName -eq "Adobe Reader 9.0"}

$MyPolicyTarget = Get-EmdbGroup "emdb:\rootDSE\Managed Users & Computers\solys.local\Adobe Reader 8.0 systems"

$MyPolicy.RemoveTarget($MyPolicyTarget)