23
votes

Simple question:

If I use the ${env:ProgramFiles(x86)} variable in a PowerShell script on a 32-bit system does it return "C:\Program Files" or is it undefined?

On a x64 system it will be mapped to "C:\Program Files (x86)" when running in both x64 and x86 mode. I don't have a 32bit system to test on, but I hope that it will be mapped to the "C:\Program Files" folder so I can use it to refer to x86 programs on any system.

1
If you're developing for both architectures you should really test on both.Ash Burlaczenko
I have a request in for an x86 environment but figured this would be documented somewhere. Couldn't find it online anywhere :-(Greg Bray

1 Answers

33
votes

${env:ProgramFiles(x86)} is not defined on a 32-bit machine. You can test against $null to verify that.