Command Shell: Matching NULL NoteProperty with –Criteria Expression
I was helping someone out in a Technet Forum thread recently, and learned something new about filtering objects with a NULL NoteProperty using the Command Shell –Criteria expression filter.
Initially, I was thinking in terms of Where-Object, which works great for filtering whether an object has a NULL NoteProperty.
Without going into great detail, I’ll just say that if you’re using the –Criteria option in Command Shell, it is possible to filter objects that have a NULL NoteProperty, but we need to be aware of the differences in how the SDK forms these queries sent to the Operations Manager database.
Bottom line
A command that filters whether a NoteProperty is NULL using Where-Object looks like this:
get-alert | where {($_.principalname -ne $null) -and ($_.resolutionstate -eq '0')}
A command that filters whether a NoteProperty is NULL using the –Criteria option looks like this:
get-alert -criteria 'PrincipalName is not null and ResolutionState = 0'
The difference in using –Criteria vs. Where-Object is a significant performance improvements.