FIM 2010 R2 – Interesting and helpful FIM XPath queries

I really have to re-blog this post from Ryan. The FIM XPath query has been at best limited in what you can do with it. For instance while in C#, we have the Dotnet functions like IsPresent or IsnotPresent for making programming easy, in XPath we have to go this round about way for several queries.

Well Ryan has dissected and broken down the XPath with an update to his FIM PowerShell tool. It really simplifies a lot. Lets take a couple of examples
1/ Is manager present?
I actually did not know you could do this in the default Xpath, Ryan showed me
/Person[(Manager = /*)]
Well Ryan’s new code makes it simpler
$q1 = New-XpathQuery -AttributeName Manager -Operator IsPresent
$exp = New-XpathExpression -ObjectType Person -QueryObject $q1
$exp.tostring()

2/ De-referencing an object?
Arguably one of the more cumbersome, with several lines of code needed, say I want to get the displayname field of the manager of a person
# Creates an expression that returns the displayname manager of a user who has the account name ‘ryan’
$query = New-XPathQuery -AttributeName “AccountName” -Operator Equals -Value “ryan”
$expression = New-XPathExpression -ObjectType “Person” -QueryObject $query -DereferenceAttribute “Manager”
$expression.Displayname.Value
3/ Clearing a reference attribute such as Manager?
Easy. It was a process that took writing a function evaluator work flow to first clear it because the default FIM PowerShell could not write to the Manager field if there was an existing value. Then you have to find a way to link you PowerShell to the Function Evaluator possibly via a workflow, a long convoluted process. here is the way via the Lithnet Powershell
$MyManagerObjectID = Get-Resource -ObjectType Person -AttributeName $mysearchid -AttributeValue $mysam
$MyManagerObjectID.Manager=”1d329608-1c9b-4124-ad6a-d796eb4b73e6″
save-resource $mymanagerobjectID

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s