I was on a client site doing a PowerShell script for an application that could potentially be deployed to either a Windows 7 32-bit or a Windows 7 64-bit, and I was looking for a very simple method of checking to see whether the Operating System was 32-bit or 64-bit, as that would dictate the package to install onto the client’s workstation. I read an article about KISS (Keep It Simple Stupid) whilst looking for the answer, and I found that the below PowerShell code was the simplest way to check if the O/S is a 32-bit O/S:

PowerShell

1

2

3

4

5

6

7

8

9

10

11

functionOSBitness64

{

if(Test-Path-Path"C:\Program Files (x86)")

{

return$true;

}

else

{

return$false;

}

}

As you can see very simple! If the “Program Files (x86)” folder exists, we are assuming that the O/S is 64-bit and we return $true. At that point you can then do an if statement:

PowerShell

1

2

3

4

5

6

7

8

if(OSBitness64-eq$true)

{

DOSOME64-BITSTUFF

}

else

{

DOSOME32-BITSTUFF

}

Test deployed on a 100 workstations, which was a mix of 32 and 64-bit workstations and worked like a charm with no issues thus far.