Quantcast
Channel: psappdeploytoolkit Discussions Rss Feed
Viewing all articles
Browse latest Browse all 1769

New Post: Can I use an IF statement Install only on systems not present

$
0
0
Sorry, I was on my phone at the time. Here's an example:
[version]$visualCappVersion = Get-InstalledApplication "Visual C++ 2008" | select "DisplayVersion" -expand "DisplayVersion" 

If ($visualCappVersion -lt [version]"9.0.30729.4148" -or $visualCAppVersion -eq $null) {
     Execute-MSI -Action Install "Microsoft_VisualC++_2008.msi" }    
} 
So you're casting to a datatype of [version] instead of [string] (default). [version] can handle multiple decimal points in a comparison operator like Less Than, whereas [string] cant. You can prove this with the following code:
[string]$test1 = "11.22.33.44"
[string]$test2 = "11.22.133.44"
if ($test1 -lt $test2) { Write-Host "Correct" }
You won't get any output. But if you do this:
[version]$test1 = "11.22.33.44"
[version]$test2 = "11.22.133.44"
if ($test1 -lt $test2) { Write-Host "Correct" }
You'll see "Correct" displayed.

Viewing all articles
Browse latest Browse all 1769

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>