Thursday, September 12, 2013

Use PowerShell to Cancel a Bunch of FIM Requests

Sometimes you just want to cancel a bunch of FIM Requests.  You can do it in the FIM Portal using the handy ‘Cancel’ button when viewing Requests.  With almost everything in the FIM Portal it is pretty easy to see how that operation is performed by looking at the FIM Request that gets submitted.  In this case I cancelled a Request then looked at the FIM Request history in the FIM Portal.  Turns out that to cancel a Request, you have to submit a new Request.  I put in the GUID of that request then looked at it in PowerShell.  From the output we can see that changing the ‘RequestControl’ attribute to ‘CancelOperation’ tells FIM to cancel the Request (just like operational attributes in LDAP I guess).

 

###

### Export a specific FIM Request and look at the Request Parameters

###

Export-FIMConfig -OnlyBaseResources -CustomConfig "/Request[ObjectID='2d6611f4-60bc-4c23-8de7-1c5b41ea4064']" |

Convert-FimExportToPSObject |

Get-FimRequestParameter

 

 

 

Value           Mode   PropertyName   Operation

-----           ----   ------------   ---------

CancelOperation Modify RequestControl Create  

 

 

So, given that I just need to modify the ‘RequestControl’ attribute on the Request, I can query for FIM Requests that need cancelling, then for each one submit a Request as shown below.

 

###

### Query for all Requests in 'Authorizing'

### then Cancel each one

###

Export-FIMConfig -OnlyBaseResources -CustomConfig "/Request[RequestStatus='Authorizing']" |

Convert-FimExportToPSObject |

ForEach-Object {

    Write-Verbose "Canceling Request: $($_.DisplayName)" -Verbose:$true

    New-FimImportObject -State Put `

    -ObjectType $_.ObjectType `

    -TargetObjectIdentifier ($_.ObjectID -replace 'urn:uuid:') `

    -Changes @{

            RequestControl = 'CancelOperation'

    } -ApplyNow

}

 

 

VERBOSE: Canceling Request: Update to Group:  'hoofhearted' Request

VERBOSE: Canceling Request: Update to Group:  'icemelted' Request

VERBOSE: Canceling Request: Update to Group:  'hoofhearted' Request

VERBOSE: Canceling Request: Update to Group:  'icemelted' Request

VERBOSE: Canceling Request: Update to Group:  'hoofhearted' Request

VERBOSE: Canceling Request: Update to Group:  'icemelted' Request

VERBOSE: Canceling Request: Update to Group:  'hoofhearted' Request

VERBOSE: Canceling Request: Update to Group:  'icemelted' Request

 

Note: –Verbose was used in an awkward way here to prevent harm to any puppies.  Using Write-Verbose is a very good habit, even when you think you should just Write-Host.

No comments: