Retrieving Policies

The PowerShell Extensions for Ivanti DSM provide the cmdlet Get-EmdbPolicy for retrieving Policies. You have to supply the object in the Policies of which you are interested as a parameter. As result, the cmdlet returns a collection of Policy objects that are suitable for further processing. For instance, you can redirect the results of the cmdlet into a PowerShell pipe or store it into a local variable and process it separately.


As an alternative, you can retrieve the Policies that are associated with an object, by invoking the method GetPolicies() of the object. This method is supported for objects of the Organization Directory, e.g. a Computer, an Organizational Unit, a Group object and for objects of the Global Software Library, that is a Software Package.


Examples:


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


Retrieve all Policies associated with the object named "Managed Users & Computers" using the cmdlet Get-EmdbPolicy. This command returns all Policy objects, including Software Policies, Shop Policies, Job Policies etc.:


Get-EmdbPolicy "emdb:\rootDSE\Managed Users & Computers"


To limit the result set to a certain type of Policies, you can supply the parameter -PolicyType and the Policy type you are interested in. In the following example only Software Policies are retrieved:


Get-EmdbPolicy "emdb:\rootDSE\Managed Users & Computers" -PolicyType "SwPolicy"


Valid arguments to the parameter PolicyType are:


Argument

Type of Policy

SwPolicy

Software Policies

JobPolicy

Job Policies

DenyPolicy

Deny Policies

SwSetComponentPolicy

Software-Set-Component Policies

PnpPolicy

Device Driver Policies

PatchPolicy

Patch Policies

CitrixFarmPolicy

Citrix Farm Policies

CitrixUserPolicy

Citrix User Policies


Hint: The Policy types involved in Patch Management and Citrix Farm Management are only available if you have installed the corresponding modules.


For performance reasons, only the IDs of the associated objects, that is the ID of the Software Package and the IDs of the target objects,  are displayed while retrieving Policies. To gain more clearness, you might want to retrieve the properties AssignedObjectName resp. TargetObjectNameList, too. They contain the names of the associated objects. This leads to the expanded example:


Get-EmdbPolicy "emdb:\rootDSE\Managed Users & Computers" -PolicyType "SwPolicy" | Select-Object AssignedObjectName, TargetObjectNameList


Hint: Additional server requests are required for retrieving the names of the associated objects of a Policy. This might lead to a performance penalty. So you might want to retrieve the names only, if you really need them in your application.


The next example illustrates how to reach the result from the above example using the method GetPolicies():


$MyDomain = Get-EmdbDomain "emdb:\rootDSE\Managed Users & Computers"

$MyDomain.GetPolicies("SwPolicy") | Select-Object AssignedObjectName, TargetObjectNameList


Starting with PSX 3.1, Policies can also be retrieved using their ID. The following example retrieves the Policy Object with ID 976. The context is not relevant in this case:


Get-EmdbPolicy -ID 976