Skip to content

Show warning if powerShellDefaultVersion is set but not found #4295

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 1 commit into from
Nov 30, 2022
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
9 changes: 7 additions & 2 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,17 +492,22 @@ export class SessionManager implements Middleware {
let foundPowerShell: IPowerShellExeDetails | undefined;
try {
let defaultPowerShell: IPowerShellExeDetails | undefined;
if (this.sessionSettings.powerShellDefaultVersion !== "") {
const wantedName = this.sessionSettings.powerShellDefaultVersion;
if (wantedName !== "") {
for await (const details of powershellExeFinder.enumeratePowerShellInstallations()) {
// Need to compare names case-insensitively, from https://stackoverflow.com/a/2140723
const wantedName = this.sessionSettings.powerShellDefaultVersion;
if (wantedName.localeCompare(details.displayName, undefined, { sensitivity: "accent" }) === 0) {
defaultPowerShell = details;
break;
}
}

}
foundPowerShell = defaultPowerShell ?? await powershellExeFinder.getFirstAvailablePowerShellInstallation();
if (defaultPowerShell === undefined && foundPowerShell !== undefined) {
void this.logger.writeAndShowWarning(`The 'powerShellDefaultVersion' setting was '${wantedName}' but this was not found!`
+ ` Instead using first available installation '${foundPowerShell.displayName}' at '${foundPowerShell.exePath}'!`);
}
} catch (e) {
this.logger.writeError(`Error occurred while searching for a PowerShell executable:\n${e}`);
}
Expand Down