PowerShell
- Pronunciation
- POW-er-shel
In short
PowerShell is Microsoft's command-line shell and scripting language for automating administration, passing objects rather than plain text between commands.
What is PowerShell?
Windows PowerShell 1.0 was released in 2006 as a modern replacement for the old Windows command prompt. In 2016 Microsoft made it open source and cross-platform; the current line, PowerShell 7, runs on Windows, macOS and Linux and is started with the pwsh command.
Its commands, called cmdlets, follow a Verb-Noun pattern that makes them easy to guess: Get-Process, Stop-Service, New-Item. The big difference from Unix shells is the object pipeline. Get-Process | Where-Object CPU -gt 100 | Sort-Object CPU passes .NET objects with properties from one command to the next, so there is no need to parse text with tools such as awk.
PowerShell is the standard way to automate Windows servers, Active Directory, Microsoft 365, Exchange and Azure, and many administrators use it daily. Scripts are saved as .ps1 files, modules are shared through the PowerShell Gallery, and it can call any .NET library directly.
A common misconception is that PowerShell is only for Windows. PowerShell 7 runs on Linux and macOS too, although some Windows-specific modules don't. Its default execution policy on Windows can block unsigned scripts, which surprises newcomers; it is a safety setting, not a sign that scripts are broken.
Key takeaways
- PowerShell is Microsoft's shell and scripting language, first released in 2006.
- PowerShell 7 is open source and runs on Windows, macOS and Linux.
- Cmdlets use Verb-Noun names such as Get-Process.
- The pipeline passes .NET objects, not text, between commands.
- It is the standard tool for automating Windows, Microsoft 365 and Azure.
Example
# The five processes using the most memory, as objects with properties
Get-Process |
Sort-Object WorkingSet64 -Descending |
Select-Object -First 5 Name, Id, @{ Name = 'MemoryMB'; Expression = { [math]::Round($_.WorkingSet64 / 1MB) } }
# Find large log files and export the list to CSV
Get-ChildItem -Path C:\Logs -Filter *.log -Recurse |
Where-Object Length -gt 50MB |
Export-Csv -Path big-logs.csv -NoTypeInformationReaders ask
What is the difference between PowerShell and Bash?
Bash passes plain text between commands, while PowerShell passes structured objects. Bash is the standard on Linux and macOS; PowerShell is the standard on Windows and also runs on other systems.
What is the difference between Windows PowerShell and PowerShell 7?
Windows PowerShell 5.1 ships with Windows and is built on the .NET Framework. PowerShell 7 is the newer, open-source, cross-platform version built on modern .NET, and it is where new features are added.
What is a cmdlet?
A built-in PowerShell command, named in Verb-Noun form, such as Get-ChildItem or Set-Location. Cmdlets take parameters and output objects that the next command can use.
See also
- ShellOperating Systems, p. 27A shell is a program that reads commands typed by a user or written in a script and asks the operating system to run them, usually through a text interface.
- BashProgramming Languages, p. 2Bash is a Unix shell and scripting language, the default on most Linux systems, used both to type commands interactively and to automate tasks with scripts.
- .NETBackend & APIs, p. 1.NET is Microsoft's free, open-source developer platform for building web, desktop, mobile, cloud and game applications, mainly in C#.
- AzureDevOps & Cloud, p. 4Microsoft Azure is Microsoft's cloud computing platform, offering hundreds of on-demand services such as virtual machines, databases and AI models worldwide.
- C#Programming Languages, p. 4C# is a statically typed, object-oriented language that runs on the .NET runtime with garbage collection and is used for web backends, desktop apps, and games.
- Configuration ManagementDevOps & Cloud, p. 11Configuration management is the practice of defining the desired state of servers and software in code and using tools to apply and keep it automatically.
Spotted a mistake or something missing on this page?Suggest an edit