Powershell resolving C:\Program Files path to C:\Program Files (x86)

When i try to give "$($env:ProgramFiles)\Tableau" it should resolve to "C:\Program Files\Tableau" on any architecture machine (64 bit or 32 bit). But it is resolving to: "C:\Program Files (x86)\Tableau" 

I tried with different methods:


$test=$env:ProgramFiles + "\abc"

but same problem persists.. 

P.S. I am running script with Psexec.

Thanks in advance.

5 Comments   [ + ] Show comments
  • I'm pretty sure PSExec is a 32bit program, so that might affect the results. Are you also sure that you are always installing the 64bit version of Tableau on 64bit machines? - chucksteel 4 years ago
  • okay... Yes I am installing 64 bit tableau on 64 bit machine.. - Ishita Tripathi 4 years ago
  • i tried with 64 bit Psexec, still it is resolving to Program Files (x86) - Ishita Tripathi 4 years ago
  • Why are you using PSExec with powershell? You should just use Enter-PSSession instead, or Invoke-Command. Also, are you using KACE with this or is this just a question regarding Powershell? - Drave 4 years ago
  • I am using PS AppDeployment Toolkit. So, to execute it, i am opening cmd through Psexec and then running the command "Deploy-Application.exe Install" which will in turn invoke Deploy-Application.ps1" and start its installation. - Ishita Tripathi 4 years ago

Answers (2)

Answer Summary:
Posted by: Drave 4 years ago
Purple Belt
Open Powershell and use Invoke-Command

If you don't know how to use Invoke-Command, I'd encourage you to use the Get-Help Cmdlt to get info on how to use Invoke-Command. To do that, enter the the following into powershell.

Get-Help Invoke-Command

Now this is the command you'll want to use to deploy tableau, though you'll need to make some modifications.

Invoke-Command -ComputerName <computername> -ScriptBlock {"<Directory of Tableau EXE>\TableauDesktop-64bit.exe /install /norestart /quiet AUTOUPDATE=0 ACCEPTEULA=1"}

Replace <computername> with the name of the machine you want to install tableau on.

Replace <Diractory of Tableau EXE> with the directory where the Tableau executable is

Finally replace TableauDestop-64bit.exe with the name of the tableau install file.

The /norestart switch disables restarting, the /quiet switch ensures the user doesn't see the install occuring, the AUTOUPDATE=0 option disables auto-updating, and the ACCEPTEULA=1 option prevents the User from having to click "accept" on the end user license agreement which helps prevent them from getting confused.

  • Thanks for the help. But, this is not about the tableau install. Actually, I wanted to remove the empty folders tableau is leaving after the uninstall. So, I need it to resolve to C:\Program Files\.. but it is resolving to C:\Program Files (x86)\.. - Ishita Tripathi 4 years ago
Posted by: rad33k 4 years ago
Fourth Degree Brown Belt

Top Answer

Please keep in mind that environment variables are resolved according to the parent's process architecture/bitness. For example env. variable "ProgramFiles" is resolved to "C:\Program Files(x86)" by 32bit processes and as "C:\Program Files" for 64bit processes.
To list all environment variables for 64bit processes (ofc on 64 bit OS) you could run C:\WIndows\System32\cmd.exe type a 'set' command and hit Enter. For 32bit type a 'set' in the C:\Windows\SysWOW64\cmd.exe.

I'm guessing that you are starting your script from 32bit parent process and then (usually, if you do not use SYSNATIVE call) child process inherits the architecture/bitness of the execution environment - in this case 32 bit environment and that's why "ProgramFiles" variable is resolved to "C:\Program Files (x86)\"

Please see a simple test with your script. Left window presents 64bit parent process (cmd.exe) while on the right side you can see 32 bit environment (\SysWOW64\CMD.EXE) - the second execution in the 32bit env (marked in blue) shows usage of SYSNATIVE which allows to jump out of the 32bit env to the native architecture:

As you have mentioned that you need to run your script on both (32 and 64 bit) OSes I would suggest to add some logic to OS Architecture detection and then use "ProgramFiles" on a 32bit OS and "ProgramW6432" on a 64 bit OS. Something like this:

$OSArch = (Get-WmiObject Win32_OperatingSystem).OSArchitecture
If ($OSArch -like '64*') {
} else

  • Thanks a lot..!!! You made me the happiest girl today!!! :) It worked perfectly..!!!!! - Ishita Tripathi 4 years ago

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ