PowerShell gurus

Soldato
Joined
28 Sep 2008
Posts
14,190
Location
Britain
Sup!

Got a script that installs an application. It needs to be OS agnostic, in as much as, it should work on both x64 and x86 platforms.

The script installs the app fine, but the next part of the script needs to go the application folder and run additional steps. Obviously, here, the path will either be:

PHP:
C:\Program Files

or

PHP:
C:\Program Files x86

Is there a way to programatically get Powershell to know which program files folder to use?

I'd like to avoid two scripts if possible :)

I'm assuming architecture variable or similar?
 
Last edited:
There's a few ways to do this...

Environment variables, as mentioned above.

Testing to see if the path(s) are already there.

Check the default locations in the registry.

WMI queries to check the architecture.



WMI is probably the best way to see if x86 or x64 but the registry and env vars can be better for checking the paths encase someone has changed their default locations.
 
Ok, issue here, (with test path) is that we might have some sort of application or program scripted during deployment which creates a "Program Files" folder (even on an x64 machine). If that happened, then this Powershell script would run without error (but the installation would actually fail).

I guess I need to look down the WMI route?
 
I ran an "if" statement to check the address space. ie 4=32bit and 8=64bit. If it's 4, install to Prog Files, else, Prog Files x86
 
Back
Top Bottom