Sunday 12 July 2015

Using PowerShell To Check The OS Architecture

This post was actually inspired by the previous post: 


I was thinking using Powershell instead, the previous batch file serves the purpose, check for that particular folder and wah la you got your program installed. But I want to tap on Powershell's advance feature to ensure that the machine is really on 64 bit OS to install. 

So here goes: 

$OSArchitecture = (Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture -ErrorAction Stop).OSArchitecture
if ($OSArchitecture -eq '64-bit')
{& path:\a.exe}
else
{& path:\b.exe}

The idea is to use Powershell to check on the OS architecture. The strings behind Win32_OperatingSystem can be found here

You will need to change the variable yourself for the software path. 

Afterwards you can deploy the a batch file to invoke the above Powershell script to install the programs. Make sure you add in the required installation parameters as well. 

In case you do not know how to use a batch file to run Powershell scripts you can take a look of my previous posts on simple scripting to get the job done: 




Enjoy!

SY

No comments:

Post a Comment