Updating Policies

A common task if you use Revisions of Software Packages is to update the Policy to reflect the change of the Revision of the associated Software Package. To fulfill this task you have to set the property AssignedObjectId of the Policy object to the ID of the new Software Package Revision and then propagate the changes back to the DSMDB using the method Update().


Hint: Every new Revision of a Software Package also has a new ID applied.


The task is extensive, because of the involved Software Package. The following steps are necessary:

1. Retrieve the Policy object and store it in a variable

2. Retrieve the assigned Software Package using the method GetAssignedObject() and store it in a variable

3. Determine the target Revision ID

4. Set the property AssignedObjectId to the determined Revision ID

5. Invoke the method Update() with the required parameters


Examples:


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


Retrieve the assigned Software Packages of a Policy and its Revisions:


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

$MyAssignedPackage = $MyPolicy.GetAssignedObject()

$MyAssignedPackage.GetRevisions()


To update the Policy to e.g. Revision 2 of the Software Package, you first have to retrieve the Revision id:


$MyNewRevisionID = $MyAssignedPackage.GetRevisions() | Where-Object {$_.SoftwareRevision -eq 2} | Select-Object PackageId


Next you can perform the Policy update. Similar to the procedure in the DSMC, you can now specify if the update is critical and how the update process should behave. The method Update() accepts the following parameters: 


1. Is the update critical? Valid values for this parameter are NonCriticalUpdate and CriticalUpdate

2. If the update is critical, which Policy-Instances should be updated? Valid values are None and All and SamePreviousValue

3.Should the updated Policy-Instances be deactivated? Valid values are $True (Policy-Instances are deactivated) and $False (will stay active)


In the next example, the Policy is updated to Revision 2 of the assigned Software Package. The update is specified as critical, all Policy-Instances should be updated, too, and they should be deactivated:


$MyPolicy.AssignedObjectId = $MyNewRevisionID

$MyPolicy.Update("CriticalUpdate", "All", $True)