How does the PowerShell Core function get the path of PowerShell Core? #949

Closed
opened 2026-01-30 22:12:12 +00:00 by claunia · 4 comments
Owner

Originally created by @hbjydev on GitHub (May 10, 2019).

The function in question is in Terminal/TerminalApp/CascadiaSettings.cpp (line 328). I wondered... Does it check for an environment variable called PowerShell, or is it looking for that in PATH?
I'm asking because I want to try and detect installed WSL environments to script in an automatic profile creation function for WSL distros.

Originally created by @hbjydev on GitHub (May 10, 2019). The function in question is in Terminal/TerminalApp/CascadiaSettings.cpp (line 328). I wondered... Does it check for an environment variable called `PowerShell`, or is it looking for that in PATH? I'm asking because I want to try and detect installed WSL environments to script in an automatic profile creation function for WSL distros.
claunia added the Issue-Question label 2026-01-30 22:12:12 +00:00
Author
Owner

@zadjii-msft commented on GitHub (May 10, 2019):

I believe what's happening in CascadiaSettings::_IsPowerShellCoreInstalled is we're trying to expand any environment variables that are in the path in programFileEnv, then appending "Powershell" to that path, and checking if pwsh.exe exists underneath that path.

I don't believe there's a %Powershell% we're checking for. We're actually just looking in either "%ProgramFiles%" or "%ProgramFiles(x86)%"

@zadjii-msft commented on GitHub (May 10, 2019): I believe what's happening in `CascadiaSettings::_IsPowerShellCoreInstalled` is we're trying to expand any environment variables that are in the path in `programFileEnv`, then appending "Powershell" to that path, and checking if `pwsh.exe` exists underneath that path. I don't believe there's a `%Powershell%` we're checking for. We're actually just looking in either `"%ProgramFiles%"` or `"%ProgramFiles(x86)%"`
Author
Owner

@hbjydev commented on GitHub (May 10, 2019):

Ah, so could I do something similar but look for %Windows\System32% and then ubuntu, wsl, debian, etc.?

@hbjydev commented on GitHub (May 10, 2019): Ah, so could I do something similar but look for `%Windows\System32%` and then `ubuntu`, `wsl`, `debian`, etc.?
Author
Owner

@zadjii-msft commented on GitHub (May 10, 2019):

Ah see, that's not where those actually live. The wsl exe's are actually App Execution Aliases, and they live in %localappdata%\Microsoft\WindowsApps\. Note that all app execution aliases live there, not just the WSL distros.

@zadjii-msft commented on GitHub (May 10, 2019): Ah see, that's not where those actually live. The wsl exe's are actually App Execution Aliases, and they live in `%localappdata%\Microsoft\WindowsApps\`. Note that _all_ app execution aliases live there, not just the WSL distros.
Author
Owner

@hbjydev commented on GitHub (May 10, 2019):

Right. So going straight to the WSL exe's would be a bad idea then? 😅

@hbjydev commented on GitHub (May 10, 2019): Right. So going straight to the WSL exe's would be a bad idea then? 😅
Sign in to join this conversation.
No Label Issue-Question
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#949