2

I currently have this code below in my powershell script that installs for all versions of IE under 11, so it would rule out installing for windows 8.

# Get the Internet Explorer version $ieVersion = Get-Item "HKLM:Software\Microsoft\Internet Explorer" -ErrorAction SilentlyContinue | Get-ItemProperty | Select "svcVersion" -ExpandProperty "svcVersion" $ieSubstringPos = $ieVersion.IndexOf(".") [int]$ieShortVersion = $ieVersion.Substring(0, $ieSubstringPos) ## <Perform Installation tasks here> If ($ieShortVersion -lt 11) { Execute-MSI -Action Install -Path "install_flash_player_18_active_x.msi" -Parameters "/qn" } 

Now we are upgrading to IE11 in our environment so that will no longer work. Is there a way I can do the same thing but detect for windows 7 x64 and x32

1
  • 2
    double the code... double the fun! Commented Jul 23, 2015 at 16:12

2 Answers 2

1

If you want to get Windows version, you can simply query WMI. Example:

$OS = Get-WmiObject -Class Win32_OperatingSystem ` | Select-Object -Property @("Version", "OSArchitecture") $OS | Format-List 

Output (for Win7 x64):

Version : 6.1.7601 OSArchitecture : 64-bit 

Then you can use switch or if statements to execute different code depending on version and or arch. Example:

switch -Regex ($OS.Version ) { "^6\.1\." { # Windows 7 if ($OS.OSArchitecture -eq "64-bit") { # do something } else { # do something else } } "^6\.[23]\." { # Windows 8 or Windows 8.1 if ($OS.OSArchitecture -eq "64-bit") { # do something } else { # do something else } } default { Write-Error "Unexpected OS version." } } 

Win32_OperatingSystem class have many other properties you might find useful if you need to narrow the conditions further. See MSDN reference for details.

Sign up to request clarification or add additional context in comments.

4 Comments

This will fail with "Unexpected OS version" the moment you move to Windows 10 (which releases in six days). Checking for OS version is not the right solution to this problem. You should check for the feature you need (Flash, in this case)
Windows 10 wont be an issue as SCCM dictates where this script can run. I guess another way to solve this would be to keep your script alexander as is but just add an "all other os versions" do this statement. is there a way to do that?
@Ryan Bemrose You're right of course. This is just an example and its purpose was to showcase the possibilities. However, Windows 10 will have internal version number too (most probably starting with 10.0 if tech previews are any indication) so it's just a matter of adding yet another script block like "^10\.0\." { ... } to the switch.
@Josh D'Ambrosio Yes, you can put "all other versions" code into the default { ... } script block. My Write-Error there is yet again just to illustrate the possibility. It can really be anything.
0

Trying to detect which version you're on is almost always the wrong solution to your problem. As you learned, the version of the OS is no guarantee about what software is installed, and your code will most likely break in the future when the next version of the OS is out and Microsoft starts backporting features.

If I read this right, the problem you want to solve is making sure that Flash is installed on machines with IE11. For this, you should not try to detect the OS. Instead, try to detect whether Flash is installed.

$FlashIsInstalled = $true try { $flashobject = new-object -ComObject "shockwaveflash.shockwaveflash" $version=$flashobject.getvariable("`$version") # Optional: Check for correct version here } Catch{ $FlashIsInstalled = $false } If (-not $FlashIsInstalled) { Execute-MSI -Action Install -Path "install_flash_player_18_active_x.msi" -Parameters "/qn" } 

Solution from http://andrewmorgan.ie/2012/01/retrieve-adobe-flash-version-with-powershell/

1 Comment

Actually i test on x32,x64 versions of windows 7 and 8.1 and it seems to work fine. I actually do not want flash to install for windows 8.1 since it is already installed with windows "active_x" and updates through wsus. But I want it to install the active_X on windows 7 since it is not. Hence I would need to detect OS's. I also have detection methods in SCCM to only run on the version i specify in the script.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.