Skip to content

Display installed PowerShell Core builds in session selection menu #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 30, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ||
Expand Down