I have the following script which I use as a detection rule for an application:
if ([version]((Get-AppxPackage *app.name*).Version) -ge ([version]("10.2103.8.0"))) { write-output $true }
I want it to ignore any digits prior to the first decimal point (the 10
in this case). Think wildcard, like "*.2103.8.0"
. How can I do that?
As clarification: this script checks the version number of a specified application and if the number is greater than or equal to the [version]
it prints true
in the console. I wish to only check the value after the first decimal. So regardless if the version is equal to 1.2103.8.0
or 99.2103.8.0
, it will be valid.
CodePudding user response:
If you really only want to compare by the minor, build and revision fields of the version numbers, normalize the major component to 0
:
[version] ((Get-AppxPackage *app.name*).Version -replace '^\d ', '0') -ge
[version] '0.2103.8.0'
-replace
'^\d ', '0'
, replaces one or more (\d
) at the start of (^
) the string value that the.Version
property returns with string0
.