To execute PowerShell commands using the cross-platform engine, you must invoke
pwsh.exe rather than the legacy
powershell.exe. This binary is located in the installation directory of PowerShell 7 and supports Linux and macOS environments alongside Windows. Using this executable ensures your scripts run on the modern .NET runtime, providing access to newer cmdlets and improved performance compared to the Windows PowerShell 5.1 version.
Locating the pwsh.exe Binary
Before running commands, you need to identify where the
pwsh.exe file resides on your system. Unlike
powershell.exe, which is part of the operating system core,
pwsh.exe is installed separately as an optional feature or application. On Windows systems, the default installation path typically places the executable in the Program Files directory. You can find it by navigating to
C:\Program Files\PowerShell\7\ or
C:\Program Files (x86)\PowerShell\7\ depending on whether you installed the 64-bit or 32-bit version. If you are using a package manager like Winget or Chocolatey, the location might vary slightly, but it will generally remain within the PowerShell folder structure.
Verifying the existence of this file is crucial before attempting to run scripts. If the directory does not exist, you likely do not have PowerShell 7 installed. In such cases, you should download the installer from the official GitHub releases page for PowerShell. Once installed, ensure that the installation completed successfully by checking for the presence of
pwsh.exe in the expected directory.
Differences Between pwsh.exe and powershell.exe
Understanding the distinction between these two executables helps prevent compatibility issues.
powershell.exe refers to Windows PowerShell 5.1, which runs on the older .NET Framework. It is deeply integrated into Windows Server and client operating systems, often serving as the default shell for administrative tasks via Task Scheduler or Group Policy. In contrast,
pwsh.exe is the entry point for PowerShell Core, now simply called PowerShell 7+. It runs on .NET Core or .NET 5+, making it cross-platform capable.
The primary benefit of using
pwsh.exe is access to the latest language features and modules. Many new Microsoft Azure modules and community-driven tools require PowerShell 7 because they depend on APIs unavailable in the .NET Framework version. Additionally,
pwsh.exe starts faster and consumes less memory in many scenarios. However, some legacy scripts relying on COM objects or specific .NET Framework assemblies may fail when run under
pwsh.exe. Always test critical automation scripts in both environments if you maintain mixed infrastructure.
Executing Commands via Command Prompt
You can launch PowerShell 7 directly from the standard Windows Command Prompt (
cmd.exe) or from the newer Windows Terminal. To do this, simply type the full path to the executable followed by your desired command. For example, to check the version, you would run:
"C:\Program Files\PowerShell\7\pwsh.exe" -Version
If you added PowerShell 7 to your system PATH during installation, you can simply type
pwsh or
pwsh.exe without the full path. This makes it easier to integrate into batch files or simple one-liners. When passing complex arguments, always quote the path to the executable to avoid issues with spaces in directory names. This method allows you to leverage the power of PowerShell 7 within traditional Windows scripting workflows without changing your default shell environment.
For more advanced automation involving scheduled tasks, you might need to configure the task to specifically call
pwsh.exe instead of the default host. This ensures that your scheduled jobs benefit from the performance improvements and module availability of the newer engine. See our guide on
Stopping a Windows 11 PowerShell Script Task in Task Scheduler for details on configuring task execution paths.
Running Interactive Sessions and Scripts
When you start
pwsh.exe without arguments, it opens an interactive console session identical in appearance to the classic PowerShell window, but powered by the newer engine. You can verify this by running
$PSVersionTable; the
PSEdition property will display "Core" instead of "Desktop". This interactive mode is useful for testing commands and exploring new features before incorporating them into larger scripts.
To run a script file, use the invocation operator or pass the file path as an argument. The following command executes a script named
test.ps1 located in the current directory:
.\pwsh.exe -File .\test.ps1
Note that execution policies still apply. If you encounter permission errors, you may need to adjust the policy using
-ExecutionPolicy Bypass or sign your scripts. Remember that scripts written for PowerShell 5.1 might throw errors if they use deprecated cmdlets. Reviewing documentation for each cmdlet is essential when migrating workflows. For instance, if you are automating system configurations, you might also want to explore how to
programmatically change the Windows 11 color scheme using compatible methods in PowerShell 7.
Configuration and Environment Variables
PowerShell 7 uses a different profile configuration than Windows PowerShell 5.1. Profiles stored in the
Microsoft.PowerShell_profile.ps1 file under the PowerShell 7 directory are only loaded when using
pwsh.exe. This separation allows you to maintain distinct customizations for each engine. You can locate your profile by checking the
$PROFILE variable inside the
pwsh.exe session.
Environment variables set within a
pwsh.exe session do not persist in the parent command prompt unless explicitly exported. This behavior is consistent across platforms and ensures that each session remains isolated. When debugging issues related to missing modules or variables, always verify that you are running in the correct context. Mixing variables from
powershell.exe into
pwsh.exe scripts can lead to unexpected failures if those variables are not defined in the Core environment.
Frequently Asked Questions
Can I replace powershell.exe with pwsh.exe globally?
No, you cannot simply rename or replace
powershell.exe with
pwsh.exe in the System32 folder. Many built-in Windows components and third-party applications hardcode references to
powershell.exe and expect the Windows PowerShell 5.1 engine. Replacing it could break system stability or cause application failures.
Does pwsh.exe support all Windows PowerShell 5.1 modules?
Most common modules work, but some rely on .NET Framework-specific technologies like WMI or certain COM interfaces. Modules requiring deep OS integration may need alternative approaches or wrappers. Always test critical modules in the new engine to ensure compatibility before full deployment.
How do I check if pwsh.exe is installed?
Open any command line interface and type
where pwsh or
Get-Command pwsh in PowerShell. If the command returns a path, the executable is available in your PATH. If it returns nothing, you likely need to install PowerShell 7 or add its directory to your system environment variables.
Is pwsh.exe slower than powershell.exe?
Generally,
pwsh.exe starts faster due to improvements in the .NET Core startup process. However, raw execution speed depends on the specific task and module usage. For most administrative tasks, the difference is negligible, but the cross-platform capabilities often outweigh minor performance variations.
Can I use pwsh.exe on Linux and macOS?
Yes,
pwsh.exe is the Windows-specific binary name. On Linux and macOS, the executable is simply
pwsh without the extension. The functionality remains identical, allowing you to write cross-platform scripts that behave consistently across all three operating systems.