Thursday, September 29, 2011

Can’t Use XPath Contains Function to Query Sets in FIM

This kinda surprised me.  I tried to do this and it failed:

001
002
003
004

###
### Find all Sets where the Filter uses 'myAttribute'
###

Export-FIMConfig -CustomConfig "/Set[contains(Filter, 'myAttributeName')]"

Thinking I had a problem with my syntax (the usual suspect) I changed the attribute from Filter to DisplayName and the query succeeded.  It wasn’t the query that I wanted, but it demonstrated that my syntax was correct.  I guess this means you can’t make this query in FIM.  This was a bit annoying, but there is a simple workaround.

The workaround is to just export ALL the Set objects, then use the PowerShell Where-Object cmdlet to do the filter.  Way more expensive, but who cares?  I’m not doing this all that often and I take slight pleasure in punishing the service for not accepting my leaner query to start with.

Here is the workaround script:

001
002
003
004
005
006

###
### Find all Sets where the Filter uses 'myAttribute'
###

Export-FIMConfig -CustomConfig "/Set" |
    Convert-FimExportToPSObject |
    Where-Object {$_.Filter -ilike "*myAttribute*"}

NOTE: find the Convert-FimExportToPSObject here.

2 comments:

Brad Turner said...

Yes, because Filter is not an indexed string, it is not a valid attribute in the predicate.

Craig Martin said...

Very interesting, I knew there were restrictions on XPath filters for Sets, but didn't know they pertained to XPath filters outside of Sets too.