Running PowerShell Commands with pwsh.exe instead of powershell.exe

Abstract: Resolve compatibility issues by running modern PowerShell 7 scripts using pwsh.exe instead of the legacy powershell.exe.

Created: 2026-09-15 by
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.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More