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

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”
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 AccountName -AttributeValue $mysam
save-resource $mymanagerobjectID