Thursday, January 15, 2015

Using PowerShell to Search FIM ExportObjects

The FIM Service enjoys some basic support for PowerShell in the fimautomation PowerShell snap-in.  One of the most useful commands is Export-FimConfig which essentially is a query tool for the FIM Service, returning objects of type ExportObject ([Microsoft.ResourceManagement.Automation.ObjectModel.ExportObject]).

Most often I convert the ExportObject objects to PSObjects which makes them way easier to use, but sometimes I want to work with ExportObject because of other commands that accept an ExportObject as input.

This little snippet shows how to use the PowerShell Where-Object command to filter through FIM ExportObjects.

The trick here is to dig through the ResourceManagementAttributes array using a nested Where-Object command. 

<# Now search for a specific object type - pretty easy #>

$aBunchOfExportObjects | Where {

    $_.ResourceManagementObject.ObjectType -eq 'WorkflowDefinition' `

    <# Now dig through the ResourceManagementAttriutes #>`

    -and ($_.ResourceManagementObject.ResourceManagementAttributes |

    <# Use a nested Where-Object to search for an attributeName and Value #>

    Where {

        $_.AttributeName -eq 'DisplayName' -and $_.Value -eq 'Some Fantastic Workflow'

    })

} 

 

No comments: