Problems with compare "Caption from Win32_OperatingSystem" and it result

I have problem with part of action in task.
Can some one help ? :slight_smile:

–[ Action ]----------------------------------------------------------------

 if { ( string value of selects "caption from win32_operatingsystem" of wmi as lowercase ) = "microsoft windows server 2008 r2 standard " }
	parameter "WIN_KEY" = "12345"
else 
	parameter "WIN_KEY" = "{ string value of selects "caption from win32_operatingsystem" of wmi as lowercase }"
endif

–[ Result ] ---------------------------------------------------------------

STATUS: Running action...
Command succeeded parameter "WIN_KEY" = "microsoft windows server 2008 r2 standard "

and I do not know why it do not want to “work” :slight_smile:
I am trying to get only letters and number from string, but result is the same :frowning:

–[ Action ]---------------------------------------------------------------

if ( concatenation "" of matches ( regex "[a-zA-Z0-9]" ) of ( string value of select "Caption from Win32_OperatingSystem" of wmi ) as lowercase ) = "microsoftwindowsserver2008r2standard" ) 
	parameter "W_KEY" = "12345"
else 
	parameter "W_KEY" = "{ concatenation "" of matches ( regex "[a-zA-Z0-9]" ) of ( string value of select "caption from win32_operatingsystem" of wmi ) as lowercase }"
endif

–[ Result ]---------------------------------------------------------------
STATUS: Running action…

Command succeeded parameter "W_KEY" = "microsoftwindowsserver2008r2standard"

I’m not sure that I’m understanding exactly what you’re trying to achieve, but in your first example above, you have a trailing space in the string being compared against the value from the WMI which will likely cause the ‘if’ statement to return False, and therefore evaluate the ‘else’ portion of the conditional. In the 2nd example above, there are no curly braces around the relevance of the ‘if’ statement, and so it is not being properly evaluated as a conditional. I found the following 2 examples seem to work as I’d expect in my environment:

if { ( string value of selects "caption from win32_operatingsystem" of wmi as lowercase ) = "microsoft windows server 2008 r2 standard" }
    parameter "WIN_KEY" = "12345"
else
    parameter "WIN_KEY" = "{ string value of selects "caption from win32_operatingsystem" of wmi as lowercase }"
endif

if {(( concatenation "" of matches ( regex "[a-zA-Z0-9]" ) of ( string value of select "Caption from Win32_OperatingSystem" of wmi ) as lowercase ) = "microsoftwindowsserver2008r2standard")}
    parameter "W_KEY" = "12345"
else
    parameter "W_KEY" = "{ concatenation "" of matches ( regex "[a-zA-Z0-9]" ) of ( string value of select "caption from win32_operatingsystem" of wmi ) as lowercase }"
endif
1 Like

You can test this using the Fixlet Debugger / QnA to test relevance results without having to use an action to do the testing. It is a much faster way to do this.


This is how I would get the result generally:

(it as lowercase) of concatenations "" of matches ( regex "[a-zA-Z0-9]" ) of string values of selects "Caption from Win32_OperatingSystem" of wmis

Though I prefer not to use RegEx in most cases:

unique value of (it as lowercase) of concatenations "" of characters whose(it != " ") of string values of selects "Caption from Win32_OperatingSystem" of wmis

Then to do the comparison: (in the case of my system)

Q: "microsoftwindows10pro" = unique value of (it as lowercase) of concatenations "" of matches ( regex "[a-zA-Z0-9]" ) of string values of selects "Caption from Win32_OperatingSystem" of wmis
A: True
T: 161.934 ms
I: singular boolean

Once you have relevance that works like you want in QnA, you can put it in an analysis to make sure it returns TRUE everywhere you want it to for validation reasons. Only then do I put it in an actionscript substitution:

if {( "microsoftwindows10pro" = unique value of (it as lowercase) of concatenations "" of matches ( regex "[a-zA-Z0-9]" ) of string values of selects "Caption from Win32_OperatingSystem" of wmis )}
	parameter "W_KEY" = "12345"
else 
	parameter "W_KEY" = "{ (it as lowercase) of concatenations "" of matches ( regex "[a-zA-Z0-9]" ) of string values of selects "Caption from Win32_OperatingSystem" of wmis }"
endif