Skip to content

Using PowerShell to query Request objects

I’ve been finding it useful to query Request objects for various reasons, mostly to get pending or historical changes out of them. This post contains a few script snippets and examples. Note I have developed and used these on FIM 2010 R2 only.

Get Requested Value

This function takes a Request object and an Attribute name and returns the requested value for the attribute. If there are multiple new values in the one Request they are returned as a semi-colon separated string.

Function RequestedValue
{
    PARAM($ReqObj, $Attribute)
    END
    {
        $Changes = ($ReqObj.ResourceManagementObject.ResourceManagementAttributes | where {$_.AttributeName -eq 'RequestParameter'}).Values

        $ReturnVal = ""
        $Xpath = "/RequestParameter[PropertyName='" + $Attribute + "' and Operation='Create']/Value"
        foreach ($change in $Changes)
        {
            $value = (Select-Xml -content $change -Xpath $Xpath).Node."#text"
            if ($value)
            {
                if ($ReturnVal -eq ""){$ReturnVal = $value}
                else {$ReturnVal = $ReturnVal + ";" + $value}
            }
        }
        Return $ReturnVal
    }
}

Retrieving Request Objects

You’re going to want a pretty precise filter with Export-FIMConfig as there will be lots of Request objects in your Portal. Also make sure you use the OnlyBaseResources switch so you don’t get all the referenced objects as well.

Some examples:

All Requests against a particular Target

/Request[Target='5efd9c95-05f1-49a4-9c57-38788c7259db']

All Requests against a particular Target with status of ‘Authorizing’

/Request[Target='5efd9c95-05f1-49a4-9c57-38788c7259db' and RequestStatus='Authorizing']

All Requests from a particular Requestor in the last 10 days

/Request[Creator='5efd9c95-05f1-49a4-9c57-38788c7259db' and CreatedTime >= op:subtract-dayTimeDuration-from-dateTime(fn:current-dateTime(), xs:dayTimeDuration('P10D'))]

All Requests from a particular Requestor against a particular object type

/Request[Creator='5efd9c95-05f1-49a4-9c57-38788c7259db' and TargetObjectType='WorkflowDefinition']

All Requests that involve a particular MPR

/Request[ManagementPolicy='bae9fd09-e2c7-49f9-b4ae-bc22c9bec6f7']

Selecting Requests based on the Attribute being changed

Unfortunately you can’t query inside the Request details as part of the XPath filter, so if you’re after all requests that update a particular attribute you’re going to have to make your XPath broad enough to catch them all (while not so broad you kill your server trying to execute the request), and then add an extra for loop.

In this example I want to get all the changes to EmployeeEndDate from the Requests I’ve retrieved.

$requests = export-fimconfig -customconfig $filter -onlybaseresources
$AttributeName = 'EmployeeEndDate'

foreach ($request in $requests)
{
    $ReqValue = RequestedValue -ReqObj $request -Attribute $AttributeName
    if ($ReqValue)
    {
        $CreatedTime = ($request.ResourceManagementObject.ResourceManagementAttributes | where {$_.AttributeName -eq 'CreatedTime'}).Value
        $Target = ($request.ResourceManagementObject.ResourceManagementAttributes | where {$_.AttributeName -eq 'Target'}).Value
        $Creator = ($request.ResourceManagementObject.ResourceManagementAttributes | where {$_.AttributeName -eq 'Creator'}).Value
        $Status = ($request.ResourceManagementObject.ResourceManagementAttributes | where {$_.AttributeName -eq 'RequestStatus'}).Value

        # Get the Creator Object so we can show its DisplayName instead of the ResourceID
        $filter = "/Person[ObjectID='" + $Creator.Replace("urn:uuid:","") + "']"
        $TargetObj = export-fimconfig -customconfig $filter -onlybaseresources
        $CreatorName =  ($TargetObj.ResourceManagementObject.ResourceManagementAttributes | where {$_.AttributeName -eq 'DisplayName'}).Value

        # Get the Target Object so we can show its DisplayName instead of the ResourceID
        $filter = "/Person[ObjectID='" + $Target.Replace("urn:uuid:","") + "']"
        $TargetObj = export-fimconfig -customconfig $filter -onlybaseresources
        $TargetName =  ($TargetObj.ResourceManagementObject.ResourceManagementAttributes | where {$_.AttributeName -eq 'DisplayName'}).Value

        write-host "Request" $request.ResourceManagementObject.ObjectIdentifier
        write-host "`t Requestor:" $CreatorName
        write-host "`t Request Time:" $CreatedTime
        write-host "`t Target:" $TargetName
        write-host "`t Status:" $Status
        write-host "`t Attribute:" $AttributeName
        write-host "`t Value:" $ReqValue
        write-host "`n"
    }
}

{ 1 } Comments

  1. Craig Martin | January 15, 2013 at 12:34 am | Permalink

    Should also consider using Get-FimRequestParameter from the FIM PowerShell Module:

    .EXAMPLE
    Export-FIMConfig -only -CustomConfig (“/Request[TargetObjectType = 'Person']“) |
    Convert-FimExportToPSObject |
    Get-FimRequestParameter

    Output:

    Value PropertyName Operation
    —– ———— ———
    HoofHearted AccountName Create
    HoofHearted DisplayName Create
    Hoof FirstName Create
    Hearted LastName Create
    Person ObjectType Create
    4ba58a6e-5953-4c03-af83-7dbfb94691d4 ObjectID Create
    7fb2b853-24f0-4498-9534-4e10589723c4 Creator Create

Post a Comment

Your email is never published nor shared. Required fields are marked *

Spam comments will be blocked by Akismet

*

Endep online order buy prednisone online canada order buy Endep online purchase Endep online without script buy generic Endep from india buy in Endep uk where to buy Endep without a prescription Endep from canada buy 10 mg Aricept generic Aricept cost order Nizoral no visa Nizoral 200 mg buy cheap Nizoral line Nizoral on line online ordering Famvir buy Famvir without a rx overnight shipping Requip Requip free Requip Nizoral online buy saturday delivery buy Nizoral in mo how to buy Cytotec online without a rx order Aricept pharmacy buy Aricept with no prescription buy Amitriptyline no perscription cod Online us Requip how to buy Amitriptyline without a prescription Maxalt cheap buy cipro online buy line Amitriptyline buy Amitriptyline money buy purchase Accutane 40 mg on line no rx Accutane 40 mg sale order 40 mg Accutane online next day delivery 40 mg Accutane online buy accutane online