@@ -69,17 +69,39 @@ export function getDefaultPowerShellPath(
69
69
70
70
// Find the path to powershell.exe based on the current platform
71
71
// and the user's desire to run the x86 version of PowerShell
72
- if ( platformDetails . operatingSystem === OperatingSystem . Windows ) {
73
- if ( use32Bit ) {
74
- powerShellExePath =
75
- platformDetails . isOS64Bit && platformDetails . isProcess64Bit
76
- ? SysWow64PowerShellPath
77
- : System32PowerShellPath ;
72
+ if ( platformDetails . operatingSystem === OperatingSystem . Windows ) {
73
+ const psCoreInstallPath =
74
+ ( ! platformDetails . isProcess64Bit ? process . env . ProgramW6432 : process . env . ProgramFiles ) + "\\PowerShell" ;
75
+ if ( fs . existsSync ( psCoreInstallPath ) ) {
76
+ const arch = platformDetails . isProcess64Bit ? "(x64)" : "(x86)" ;
77
+ const psCorePaths =
78
+ fs . readdirSync ( psCoreInstallPath )
79
+ . map ( ( item ) => path . join ( psCoreInstallPath , item ) )
80
+ . filter ( ( item ) => {
81
+ const exePath = path . join ( item , "pwsh.exe" ) ;
82
+ return fs . lstatSync ( item ) . isDirectory ( ) && fs . existsSync ( exePath ) ;
83
+ } )
84
+ . map ( ( item ) => ( {
85
+ versionName : `PowerShell Core ${ path . parse ( item ) . base } ${ arch } ` ,
86
+ exePath : path . join ( item , "pwsh.exe" ) ,
87
+ } ) ) ;
88
+
89
+ if ( psCorePaths ) {
90
+ powerShellExePath = psCorePaths [ 0 ] . exePath ;
91
+ }
92
+
78
93
} else {
79
- powerShellExePath =
80
- ! platformDetails . isOS64Bit || platformDetails . isProcess64Bit
81
- ? System32PowerShellPath
82
- : SysnativePowerShellPath ;
94
+ if ( use32Bit ) {
95
+ powerShellExePath =
96
+ platformDetails . isOS64Bit && platformDetails . isProcess64Bit
97
+ ? SysWow64PowerShellPath
98
+ : System32PowerShellPath ;
99
+ } else {
100
+ powerShellExePath =
101
+ ! platformDetails . isOS64Bit || platformDetails . isProcess64Bit
102
+ ? System32PowerShellPath
103
+ : SysnativePowerShellPath ;
104
+ }
83
105
}
84
106
} else if ( platformDetails . operatingSystem === OperatingSystem . MacOS ) {
85
107
// Always default to the stable version of PowerShell (if installed) but handle case of only Preview installed
0 commit comments