Powershell tidbit: hacky way to find the 32-bit Program Files directory
In the process of tidying up another function for posting, I found that there is no clean way to get a Powershell variable from the system that:
- Points to â€œC:\program files (x86)â€ regardless whether youâ€™re in a 32-bit or 64-bit process.
- Exists on legacy 32-bit operating systems.
Sounds like a common thing youâ€™d need: to find the location where 32-bit programs are installed regardless of any other factors. Powershellâ€™s $env:ProgramFiles(x86) variable comes close, but even if it were present on 32-bit OSes -- honestly not sure about that -- the parentheses in the variable name present a nasty parse problem. No amount of quoting or backtick`ing or $()â€™ing got me the result I was looking for. If you have more patience than me, have at it.
And oh yeah, did I mention I was shopping for a better null coalescing operator than the one that comes with PSCX? Note to PSCX folks: I hate wrapping stuff in scriptblocks when thereâ€™s no real need for them. Thanks, Richardâ€™s pinky finger.
So anyway, I resorted to putting this abomination in my $profile:
Yes, itâ€™s ugly and nonstandard (in the sense that I canâ€™t rely on this being present in other peopleâ€™s script environments)â€¦suggestions welcome...