pwsh
Run PowerShell Core
TLDR
Start an interactive shell session
Start an interactive shell session without loading startup configs
Execute specific commands
Execute a specific script
Start a session with a specific version of PowerShell
Prevent a shell from exit after running startup commands
Describe the format of data sent to PowerShell
Determine how an output from PowerShell is formatted
SYNOPSIS
pwsh [-Command <scriptBlock> | -File <filePath> [<args>]] [-NoProfile] [-NonInteractive] [-Help | -?]
PARAMETERS
-Command <scriptBlock>
Executes specified PowerShell commands or scripts. The script block can be a string literal or a reference to a variable.
-File <filePath> [<args>]
Runs a PowerShell script file at the specified path. Any subsequent arguments are passed to the script.
-NoProfile
Prevents loading the user's PowerShell profile script at startup, which can speed up execution for simple tasks.
-NonInteractive
Runs PowerShell in a non-interactive mode, suitable for automation scripts that should not prompt for user input.
-Help, -?
Displays command-line help for pwsh, detailing available options and their usage.
-ExecutionPolicy <policy>
Sets the execution policy for the current session, controlling which scripts PowerShell will run. Policies include Bypass, RemoteSigned, etc.
-Version
Displays the PowerShell version information and then exits.
DESCRIPTION
pwsh is the command-line executable for PowerShell, Microsoft's powerful cross-platform automation and configuration tool. It provides a rich, interactive shell experience and a scripting language built on .NET. PowerShell is designed for system administrators and developers to manage systems, automate tasks, and build complex solutions. Unlike traditional Unix shells, PowerShell treats everything as an object, allowing for structured data manipulation through a pipeline. It supports a vast ecosystem of modules and cmdlets, enabling deep integration with various services and technologies, both on-premises and in the cloud. It is available on Linux, macOS, and Windows.
CAVEATS
While pwsh provides cross-platform compatibility, some modules and cmdlets designed exclusively for Windows environments might not function or behave as expected on Linux. Its startup time can be slightly longer compared to traditional Unix shells like bash or zsh. Proper installation of the .NET runtime is a prerequisite for pwsh to function.
MODES OF OPERATION
pwsh can be used in two primary modes: as an interactive shell for immediate command execution and system administration, or as a scripting engine for executing PowerShell scripts (.ps1
files) for complex automation tasks. Its rich command history and tab completion enhance the interactive experience.
THE OBJECT PIPELINE
A fundamental difference between pwsh and traditional Unix shells is its object-based pipeline. Instead of passing text strings between commands, pwsh passes structured objects. This allows for powerful and precise data manipulation without the need for extensive text parsing, as demonstrated by commands like Get-Process | Where-Object {$_.CPU -gt 100} | Select-Object -First 5
.
HISTORY
PowerShell originated as Windows PowerShell, first released by Microsoft in 2006 as a command-line shell and scripting language built on the .NET Framework. In 2016, Microsoft open-sourced PowerShell and made it cross-platform by porting it to .NET Core (now simply .NET), renaming it PowerShell Core. The first stable cross-platform release was PowerShell Core 6.0 in January 2018. The executable name for this cross-platform version became pwsh, distinguishing it from the Windows-only `powershell.exe`. Its development continues with regular updates under the modern .NET platform.