diff --git a/src/platform.ts b/src/platform.ts index 2ade340989..b1877501d3 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -116,11 +116,17 @@ export class PowerShellExeFinder { * @param configuredPowerShellPath the PowerShell path configured by the user. */ public fixWindowsPowerShellPath(configuredPowerShellPath: string): string { + const altWinPS = this.findWinPS({ useAlternateBitness: true }); + + if (!altWinPS) { + return configuredPowerShellPath; + } + + const lowerAltWinPSPath = altWinPS.exePath.toLocaleLowerCase(); const lowerConfiguredPath = configuredPowerShellPath.toLocaleLowerCase(); - const lowerAltWinPSPath = this.alternateBitnessWinPS.exePath.toLocaleLowerCase(); if (lowerConfiguredPath === lowerAltWinPSPath) { - return this.winPS.exePath; + return this.findWinPS().exePath; } return configuredPowerShellPath; @@ -180,7 +186,7 @@ export class PowerShellExeFinder { // Currently it cannot take startup arguments to start PSES with. // // Look for the .NET global tool - // yield this.pwshDotnetGlobalTool; + // yield this.findPSCoreDotnetGlobalTool(); // Look for PSCore preview yield this.findPSCorePreview(); diff --git a/test/platform.test.ts b/test/platform.test.ts index e141795029..f6226f634e 100644 --- a/test/platform.test.ts +++ b/test/platform.test.ts @@ -594,4 +594,47 @@ suite("Platform module", () => { }); } }); + + suite("Windows PowerShell path fix", () => { + teardown(() => { + sinon.restore(); + mockFS.restore(); + }); + + for (const testPlatform of successTestCases + .filter((tp) => tp.platformDetails.operatingSystem === platform.OperatingSystem.Windows)) { + + test(`Corrects the Windows PowerShell path on ${testPlatform.name}`, () => { + setupTestEnvironment(testPlatform); + + function getWinPSPath(systemDir: string) { + return path.join( + testPlatform.environmentVars.windir, + systemDir, + "WindowsPowerShell", + "v1.0", + "powershell.exe"); + } + + const winPSPath = getWinPSPath("System32"); + + let altWinPSPath; + if (testPlatform.platformDetails.isProcess64Bit) { + altWinPSPath = getWinPSPath("SysWOW64"); + } else if (testPlatform.platformDetails.isOS64Bit) { + altWinPSPath = getWinPSPath("Sysnative"); + } else { + altWinPSPath = null; + } + + const powerShellExeFinder = new platform.PowerShellExeFinder(testPlatform.platformDetails); + + assert.strictEqual(powerShellExeFinder.fixWindowsPowerShellPath(winPSPath), winPSPath); + + if (altWinPSPath) { + assert.strictEqual(powerShellExeFinder.fixWindowsPowerShellPath(altWinPSPath), winPSPath); + } + }); + } + }); });