Hello readers/viewers! No video today, but I will be covering a fairly interesting topic. I realize that this may be an edge case, but I thought it would good to have something on the blog to reference for related topics.
SCENARIO:
EXAMPLE SCENARIO CONFIGURATION: If we take something like the “Query WMI” object, which produces output with the new line character, and attempt to filter the “WMI Query Result as a string” by “Matches Pattern” \n in the link, it does not work:
EXAMPLE SCENARIO RESULTS: During execution, this link filter configuration results in no data progressing past the link, even though the results look like this (where matching pattern would normally contain the \n):
POSSIBLE CAUSE: I do not know the root cause for this behavior, but it may be that the Regular Expression implementation for Link Properties in OIS does not support “multiline mode” (search on this page for “multiline”).
MATCHES PATTERN DOES WORK: I do know that “Match Pattern” in Link Properties Filtering does work, as I use it frequently to filter out “null” values from Published Data fields:
Usage for field “Is Null”:
Usage for field “Is Not Null”:
ALTERNATE REGEX TOOL RESULTS: Now, if we take a portion of that same output and put it in an online .NET RegEx tester, you can see that the highlighted areas are where the \n character exists in the output sample (first 5 lines of the output from the Query WMI object).
NOTE: Lines copied from “Query WMI” object:
Caption=System Idle Process Caption=System Caption=smss.exe Caption=csrss.exe Caption=csrss.exe
WORKAROUND: This does not mean that you are left with no ability filter based on the \n character; you simply have to use a workaround. The good news is, the workaround is pretty simple.
For those of you who do not yet know, there are a couple CodePlex releases which allow you to work with RegEx as a workaround:
If you would like to use Foundation Objects for the workaround, see the following steps:
Workaround Steps:
NOTE: PowerShell from the Details tab in this example (where $hasnewline will return “True” or “False”):
$inputdata = "{PUBLISHED DATA HERE}" $hasnewline = $inputdata -match "\n" $hasnewline
WORKING WITH \n CHARACTER IN PUBLISHED DATA: Now that you can filter based on the \n character, you may want to know how to work with it.
Examples: The following C# usage with the “Run .Net Script” object examples (OIS_EXPORT attached) parse the following output (from an example query WMI object):
string res = @"PUBLISHED DATA HERE"; string[] results = res.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries); foreach (string r in results) { lstResults.Add(r); }
string res = @"PUBLISHED DATA HERE"; string[] results = res.Split(new string[] {"\n", "\r\n"}, StringSplitOptions.RemoveEmptyEntries); foreach (string r in results) { string[] parsedResults = r.Split('='); lstResults.Add(parsedResults[1]); }
NOTE: For a more detailed video example of C# usage with the “Run .Net Script” object, please refer to the following post: http://blogs.technet.com/b/charlesjoy/archive/2010/07/14/8-minute-demo-net-scripting-object-c.aspx
enJOY!