Daniel4711
Daniel4711

Reputation: 422

PowerShell: Check if Variable is smaller than 15.0.0.152

How can I test which version number is bigger?

$Variable1:15.0.0.152
$Variable2:15.0.1.153

If want to write a simple if question like ($Variable1 -gt $Variable2)

Upvotes: 0

Views: 290

Answers (1)

ojk
ojk

Reputation: 2542

Probably not the best solution, but you could try this:

[int]($Variable1.Split('.') -Join '') -gt [int]($Variable2.Split('.') -Join '')

UPDATE! This is what you want:

[System.Version]$Version = "15.0.0.15"
[System.Version]$Version2 = "15.0.1.15"
$Version -gt $Version2

Upvotes: 3

Related Questions