PowerShell Quick Tip: Accessing the ProgramFiles(x86) Environment Variable

Accessing environment variables in PowerShell is easy, either:

dir env:

to view all of them, or:

dir env:ProgramFiles

to access a specific one. However, if you try that for the ProgramFiles(x86) environment variable you are greeted with the following error:view sourceprint?

PS C:\> dir env:ProgramFiles(x86)
x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the
path is correct and try again.

There are a few ways around this:

1)

dir env:ProgramFiles`(x86`)

2)

dir "env:ProgramFiles(x86)"

3)

${Env:ProgramFiles(x86)}

4)

[Environment]::GetEnvironmentVariable("ProgramFiles(x86)")
https://www.jonathanmedd.net/2013/03/powershell-quick-tip-accessing-the-programfilesx86-environment-variable.html

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *