Skip to content

Commit 11c7f3a

Browse files
Show warning if powerShellDefaultVersion is set but not found (#4295)
1 parent 104c0a8 commit 11c7f3a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/session.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -492,17 +492,22 @@ export class SessionManager implements Middleware {
492492
let foundPowerShell: IPowerShellExeDetails | undefined;
493493
try {
494494
let defaultPowerShell: IPowerShellExeDetails | undefined;
495-
if (this.sessionSettings.powerShellDefaultVersion !== "") {
495+
const wantedName = this.sessionSettings.powerShellDefaultVersion;
496+
if (wantedName !== "") {
496497
for await (const details of powershellExeFinder.enumeratePowerShellInstallations()) {
497498
// Need to compare names case-insensitively, from https://stackoverflow.com/a/2140723
498-
const wantedName = this.sessionSettings.powerShellDefaultVersion;
499499
if (wantedName.localeCompare(details.displayName, undefined, { sensitivity: "accent" }) === 0) {
500500
defaultPowerShell = details;
501501
break;
502502
}
503503
}
504+
504505
}
505506
foundPowerShell = defaultPowerShell ?? await powershellExeFinder.getFirstAvailablePowerShellInstallation();
507+
if (defaultPowerShell === undefined && foundPowerShell !== undefined) {
508+
void this.logger.writeAndShowWarning(`The 'powerShellDefaultVersion' setting was '${wantedName}' but this was not found!`
509+
+ ` Instead using first available installation '${foundPowerShell.displayName}' at '${foundPowerShell.exePath}'!`);
510+
}
506511
} catch (e) {
507512
this.logger.writeError(`Error occurred while searching for a PowerShell executable:\n${e}`);
508513
}

0 commit comments

Comments
 (0)