Home > Software design >  How to get powershell or pwsh exe file path in debian/linux
How to get powershell or pwsh exe file path in debian/linux

Time:02-10

Need to run build script in both the environment (windows and Linux).Build script is pointing to the powershell.exe path in window environment and working fine. But at the same time, same build script is not getting the powershell path and throwing error.

Executing task in folder root: PowerShell /home/userName/FolderName/Assetmonitor/scripts/build/client/build-client-dev.ps1 <

The terminal process failed to launch: Path to shell executable "PowerShell" does not exist.

CodePudding user response:

It sounds like your script is trying to call the PowerShell executable, but "powershell" (technically powershell.exe) only exists on Windows and is the executable for powershell 5.x and earlier. The executable for PowerShell 7, which is the only version I'm familiar with that's available on Linux, is named "pwsh"(pwsh.exe on Windows).

I would recommend either: 1) installing PowerShell 7 on your Windows boxes and changing the script to call for pwsh instead of "PowerShell" (remember that Linux is case-sensitive), or 2) creating a symbolic link to somewhere in your existing $PATH environment variable (like /usr/local/bin/) that points "PowerShell" to wherever your PowerShell 7 is installed on Linux.

The default path to the actual pwsh program, if you use the latest build files from Microsoft, is /opt/microsoft/powershell/7/pwsh, but that's already symlinked to /usr/bin/pwsh so you could link there instead:

    sudo ln -s /opt/microsoft/powershell/7/pwsh /usr/local/bin/PowerShell
  • Related