Introduction
With the release of PowerShell 7, a new executable named pwsh.exe was introduced, which can be used to run PowerShell commands instead of the traditional powershell.exe. While powershell.exe is still available and continues to support Windows PowerShell, the pwsh.exe executable is the recommended way to run PowerShell 7 and above, including PowerShell Core and PowerShell 7. This article will cover the benefits of using pwsh.exe and how it differs from the traditional powershell.exe.
What is pwsh.exe?
pwsh.exe is the executable for running PowerShell 7 and above. It is the successor to the Windows PowerShell powershell.exe executable and is designed to be cross-platform, meaning it can run on Windows, Linux, and macOS. pwsh.exe supports all the features of Windows PowerShell and adds new ones, including performance improvements, new cmdlets, and support for new operating systems.
Benefits of using pwsh.exe
There are several benefits of using pwsh.exe over powershell.exe:
pwsh.exeis cross-platform, meaning it can be used on Windows, Linux, and macOS.pwsh.exesupports all the features of Windows PowerShell and adds new ones, including performance improvements, new cmdlets, and support for new operating systems.pwsh.exeuses less memory and starts faster thanpowershell.exe.pwsh.exesupports side-by-side installation, meaning multiple versions of PowerShell can be installed on the same machine.
How to use pwsh.exe
Using pwsh.exe is similar to using powershell.exe, with a few key differences:
- To run
pwsh.exe, open a command prompt or terminal window and enterpwsh.exe. - To run a PowerShell command, enter the command after
pwsh.exe. For example, to run theGet-WmiObjectcmdlet, enterpwsh.exe Get-WmiObject -query "select * from Win32_OperatingSystem". - To run a PowerShell script, use the
-Fileparameter. For example, to run a script namedtest.ps1, enterpwsh.exe -File test.ps1.
Differences between pwsh.exe and powershell.exe
While pwsh.exe and powershell.exe are similar in many ways, there are some key differences:
pwsh.exesupports cross-platform operation, whilepowershell.exeis only available on Windows.pwsh.exeuses less memory and starts faster thanpowershell.exe.pwsh.exesupports side-by-side installation, meaning multiple versions of PowerShell can be installed on the same machine.pwsh.exesupports new cmdlets and features, such aspwsh.exe -Commandto run a single command, andpwsh.exe -Versionto specify the version of PowerShell to use.- The behavior of some cmdlets, such as
Get-Process, may differ betweenpwsh.exeandpowershell.exe.
In this article, we have covered the benefits of using pwsh.exe over powershell.exe, how to use pwsh.exe, and the differences between the two executables. By using pwsh.exe, you can take advantage of the new features and performance improvements in PowerShell 7 and above, and run PowerShell on multiple platforms.