I was trying to update a script so it could resolve references to various resource types. I’d seen in the help that you can do this:
Export-FIMConfig -customConfig ("/ConstosoCustomResource", "/Group")
So in my script I spent ages trying to construct a string like “(“/ConstosoCustomResource”, “/Group”)” and then wondering why it wouldn’t work.
The answer was right there in the help all along – the customConfig parameter takes a string array as argument. D’uh!
So here’s my function which returns the ObjectID based on DisplayName, where the object may be any of the types defined in $RefObjectTypes.
$RefObjecTypes = @('Person','Role','CostCentre')
Function ObjectReference
{
PARAM($DisplayName)
END
{
$filter = @()
foreach ($ObjectType in $RefObjecTypes)
{
$filter = $filter + "/$ObjectType[DisplayName = '$DisplayName']"
}
$FIMObject = Export-FIMConfig -customConfig ($filter) -OnlyBaseResources
if ($FIMObject -eq $null)
{
write-host "No match found for referenced object $DisplayName"
}
elseif ($FIMObject.Count -eq $null)
{
$FIMObject.ResourceManagementObject.ObjectIdentifier
}
else
{
write-host "Multiple matches found for referenced object $DisplayName"
}
}
}
Two other ways to get ‘unions’ of objects:
(1) Use the ‘|’ operator as follows:
/Person[AccountName=’a_name’] | /SomeObject[SomeAttribute=’b_value’]
(2) Use the ‘or’ method:
/*[(ObjectType=Group and DisplayName=’some group name’) or
(ObjectType – Person and some_Person_attribute = some_value)]
Thanks Joe, that’s a good tip.