Version comaprison for powershell

how to compare a powershell version in the system as if it > “5” then true else false??

q:(value “PowerShellVersion” of key “PowerShellEngine” of key ((it as string) of maximum of (it as integer) of names of keys of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell” of registry) of key “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell” of registry)
A: 5.1.14393.0
T: 1.001 ms

Q: if ((value "PowerShellVersion" of key "PowerShellEngine" of key ((it as string) of maximum of (it as integer) of names of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell" of registry) of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell" of registry)) > "5.1" then True Else False
A: True
T: 0.343 ms
4 Likes

Have the debugger display type information (View | Show Type Information)

q:(value "PowerShellVersion" of key "PowerShellEngine" of key ((it as string) of maximum of (it as integer) of names of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell" of registry) of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell" of registry)
A: 5.1.18362.1
T: 0.779 ms
I: singular registry key value

There is little that can really be done with a registry key value other than look at it or cast is to string.

https://developer.bigfix.com/relevance/reference/registry-key-value-type.html

Having cast it to a string, you can then cast to type ‘version’ and then do your comparison.

q: (("5.0" < value "PowerShellVersion" of it as string as version ) of key "PowerShellEngine" of key ((it as string) of maximum of (it as integer) of names of keys of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell" of registry) of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell" of registry)
A: True
T: 0.365 ms
I: singular boolean

@vk.khurava quicker on the draw…

4 Likes

BigFixers from around the globe coalesce in our community forum to geek out and try to “win the race” to help the next person. This is truly “the good stuff”.

4 Likes

Yeah, we are not such a bad lot :smile:

4 Likes