There are two separate issues with the path logic.
-
When witadmin.exe is in the path, Test-Path will fail, so it will still throw even though it's valid and can do the work.
-
In 32-bit PowerShell processes, $env:ProgramFiles resolves to C:\Program Files (x86), so $VSDirectories is built with the wrong path.
There are two separate issues with the path logic.
When
witadmin.exeis in the path,Test-Pathwill fail, so it will still throw even though it's valid and can do the work.In 32-bit PowerShell processes,
$env:ProgramFilesresolves toC:\Program Files (x86), so$VSDirectoriesis built with the wrong path.