Wierd results from Get-TaskResult
Hello,
I am getting some unexpected results using the
Get-TaskResult cmdlet. What I am looking for are the task results that
do not have a particular string of text (ex.:
System.DiscoveryData) in the task’s Output field.
Sounds simple enough, but check out the following results:
>(Get-TaskResult).Count
168
PS Monitoring:\PPD%002dHQ%002dA45.CNPPD.LAB
>(Get-TaskResult -Criteria "Output LIKE '%System.DiscoveryData%'").Count
28
PS Monitoring:\PPD%002dHQ%002dA45.CNPPD.LAB
>(Get-TaskResult -Criteria "Output NOT LIKE '%System.DiscoveryData%'").Count
73
One would normally expect something more like 140 (168-28) at this point.
MSDN document entitled “Criteria Expression Syntax” does not seem to support the “NOT LIKE”, which might explain the incorrect result.
I therefore attempted the same task using regular expressions.
The only way I found to return a successful “match” for a pattern that does not match (i.e. the target string does not contain the supplied pattern), is to use the RegEx “negative lookahead” feature, which is apparently supported
by .NET’s RegEx implementation.
PS Monitoring:\PPD%002dHQ%002dA45.CNPPD.LAB
>(Get-TaskResult -Criteria "Output MATCHES 'System\.DiscoveryData'").Count
28
PS Monitoring:\PPD%002dHQ%002dA45.CNPPD.LAB
>(Get-TaskResult -Criteria "Output MATCHES '^((?!System\.DiscoveryData).)*$'").Count
PS Monitoring:\PPD%002dHQ%002dA45.CNPPD.LAB
Any ideas?
Larry
January 17th, 2011 3:04pm
If you want to test out criteria syntax, run a query against the DB directly. The criteria is essentially just the "where" clause of a SQL query, and it uses the same wildcards and operators. Try running "select * from JobStatus where
Output LIKE '%System.DiscoveryData%'", along with corresponding NOT LIKE and see what kind of results you get. If I'm not mistaken, the LIKE / NOT LIKE operators always return false when the field is NULL - so those task results with NULL Output
might make up the remainder.
It might be easier to work only in powershell-land. Something like:
Get-TaskResult |?{$_.Output –notmatch ‘System\.DiscoveryData’}
# or
Get-TaskResult |?{$_.Output –notlike ‘*System.DiscoveryData*’}
Thanks,
-Lincoln
Free Windows Admin Tool Kit Click here and download it now
January 17th, 2011 4:12pm
Good morning Lincoln,
As you suggested, I really wanted to avoid querying the database directly, preferring a PowerShell solution to all others.
A glance at your solution (which works BTW) has led me to a more efficient solution, which leverages Get-TaskResult’s –Criteria option, follows:
Get-TaskResult -Criteria "Output
NOTMATCHES 'System\.DiscoveryData'"
Note that the
undocumented NOTMATCHES operator (at least I did not find it on Microsoft’s
Criteria Expression Syntax online document on MSDN; http://msdn.microsoft.com/en-us/library/bb437603.aspx)
does away with the necessity of using RegEx’s negative lookahead assertions to find task results
not containing a particular string.
Sadly, this functionality does not appear to be supported by .NET’s RegEx implementation.
Thanks again for your input.
Larry
January 18th, 2011 11:53am
Good morning Lincoln,
As you suggested, I really wanted to avoid querying the database directly, preferring a PowerShell solution to all others.
A glance at your solution (which works BTW) has led me to a more efficient solution, which leverages Get-TaskResult’s –Criteria option, follows:
Get-TaskResult -Criteria "Output
MATCHES 'System\.DiscoveryData'"
Or
Get-TaskResult -Criteria "Output
NOTMATCHES 'System\.DiscoveryData'"
Note that the
undocumented NOTMATCHES operator (at least I did not find it on Microsoft’s
Criteria Expression Syntax online document on MSDN;
http://msdn.microsoft.com/en-us/library/bb437603.aspx) does away with the necessity
of using RegEx’s negative lookahead assertions to find task results
not containing a particular string. Sadly, this functionality does not appear to be supported by .NET’s RegEx implementation.
Thanks again for your input.
Larry
Free Windows Admin Tool Kit Click here and download it now
January 18th, 2011 11:53am