diff --git a/src/session.ts b/src/session.ts index 811e355f43..005b447131 100644 --- a/src/session.ts +++ b/src/session.ts @@ -604,6 +604,27 @@ export class SessionManager { } } + private getPowerShellCorePaths(): string[] { + var paths: string[] = []; + if (this.isWindowsOS) { + const is64Bit = process.env.hasOwnProperty('PROCESSOR_ARCHITEW6432'); + const rootInstallPath = (is64Bit ? process.env.ProgramW6432 : process.env.ProgramFiles) + '\\PowerShell'; + + if (fs.existsSync(rootInstallPath)) { + var dirs = + fs.readdirSync(rootInstallPath) + .map(item => path.join(rootInstallPath, item)) + .filter(item => fs.lstatSync(item).isDirectory()); + + if (dirs) { + paths = paths.concat(dirs); + } + } + } + + return paths; + } + private getBuiltInPowerShellPath(use32Bit: boolean): string | null { // Find the path to powershell.exe based on the current platform @@ -711,6 +732,19 @@ export class SessionManager { "Switch to Windows PowerShell (x64)", () => { this.restartSession({ type: SessionType.UseBuiltIn, is32Bit: false }) }); + var pscorePaths = this.getPowerShellCorePaths(); + for (var pscorePath of pscorePaths) { + var pscoreVersion = path.parse(pscorePath).base; + var pscoreExePath = path.join(pscorePath, "powershell.exe"); + var pscoreItem = new SessionMenuItem( + `Switch to PowerShell Core ${pscoreVersion}`, + () => { this.restartSession({ + type: SessionType.UsePath, path: pscoreExePath, isWindowsDevBuild: false }) + }); + + menuItems.push(pscoreItem); + } + // If the configured PowerShell path isn't being used, offer it as an option if (this.sessionSettings.developer.powerShellExePath !== "" && (this.sessionConfiguration.type !== SessionType.UsePath ||