@@ -66,27 +66,55 @@ export function getDefaultPowerShellPath(
6666 use32Bit : boolean = false ) : string | null {
6767
6868 let powerShellExePath ;
69+ let psCoreInstallPath ;
6970
70- // Find the path to powershell.exe based on the current platform
71+ // Find the path to the powershell executable based on the current platform
7172 // and the user's desire to run the x86 version of PowerShell
7273 if ( platformDetails . operatingSystem === OperatingSystem . Windows ) {
7374 if ( use32Bit ) {
74- powerShellExePath =
75- platformDetails . isOS64Bit && platformDetails . isProcess64Bit
76- ? SysWow64PowerShellPath
77- : System32PowerShellPath ;
75+ psCoreInstallPath =
76+ ( platformDetails . isProcess64Bit ? process . env [ "ProgramFiles(x86)" ] : process . env . ProgramFiles )
77+ + "\\PowerShell" ;
7878 } else {
79- powerShellExePath =
80- ! platformDetails . isOS64Bit || platformDetails . isProcess64Bit
81- ? System32PowerShellPath
82- : SysnativePowerShellPath ;
79+ psCoreInstallPath =
80+ ( platformDetails . isProcess64Bit ? process . env . ProgramFiles : process . env . ProgramW6432 ) + "\\PowerShell" ;
8381 }
84- } else if ( platformDetails . operatingSystem === OperatingSystem . MacOS ) {
82+
83+ if ( fs . existsSync ( psCoreInstallPath ) ) {
84+ const arch = platformDetails . isProcess64Bit ? "(x64)" : "(x86)" ;
85+ const psCorePaths =
86+ fs . readdirSync ( psCoreInstallPath )
87+ . map ( ( item ) => path . join ( psCoreInstallPath , item ) )
88+ . filter ( ( item ) => {
89+ const exePath = path . join ( item , "pwsh.exe" ) ;
90+ return fs . lstatSync ( item ) . isDirectory ( ) && fs . existsSync ( exePath ) ;
91+ } )
92+ . map ( ( item ) => ( {
93+ versionName : `PowerShell ${ path . parse ( item ) . base } ${ arch } ` ,
94+ exePath : path . join ( item , "pwsh.exe" ) ,
95+ } ) ) ;
96+
97+ if ( psCorePaths ) {
98+ return powerShellExePath = psCorePaths [ 0 ] . exePath ;
99+ }
100+ }
101+
102+ // No PowerShell 6+ detected so use Windows PowerShell.
103+ if ( use32Bit ) {
104+ return platformDetails . isOS64Bit && platformDetails . isProcess64Bit
105+ ? SysWow64PowerShellPath
106+ : System32PowerShellPath ;
107+ }
108+ return ! platformDetails . isOS64Bit || platformDetails . isProcess64Bit
109+ ? System32PowerShellPath
110+ : SysnativePowerShellPath ;
111+ }
112+ if ( platformDetails . operatingSystem === OperatingSystem . MacOS ) {
85113 // Always default to the stable version of PowerShell (if installed) but handle case of only Preview installed
86114 powerShellExePath = macOSExePath ;
87115 if ( ! fs . existsSync ( macOSExePath ) && fs . existsSync ( macOSPreviewExePath ) ) {
88116 powerShellExePath = macOSPreviewExePath ;
89- }
117+ }
90118 } else if ( platformDetails . operatingSystem === OperatingSystem . Linux ) {
91119 // Always default to the stable version of PowerShell (if installed) but handle case of only Preview installed
92120 // as well as the Snaps case - https://snapcraft.io/
@@ -179,7 +207,7 @@ export function getAvailablePowerShellExes(
179207 return fs . lstatSync ( item ) . isDirectory ( ) && fs . existsSync ( exePath ) ;
180208 } )
181209 . map ( ( item ) => ( {
182- versionName : `PowerShell Core ${ path . parse ( item ) . base } ${ arch } ` ,
210+ versionName : `PowerShell ${ path . parse ( item ) . base } ${ arch } ` ,
183211 exePath : path . join ( item , "pwsh.exe" ) ,
184212 } ) ) ;
185213
@@ -200,7 +228,7 @@ export function getAvailablePowerShellExes(
200228 exePaths . forEach ( ( exePath ) => {
201229 if ( fs . existsSync ( exePath ) ) {
202230 paths . push ( {
203- versionName : "PowerShell Core " + ( / - p r e v i e w / . test ( exePath ) ? " Preview" : "" ) ,
231+ versionName : "PowerShell" + ( / - p r e v i e w / . test ( exePath ) ? " Preview" : "" ) ,
204232 exePath,
205233 } ) ;
206234 }
0 commit comments