powershell
Run PowerShell commands and scripts
TLDR
View the documentation for the command referring to the latest, cross-platform version of PowerShell (version 6 and above)
View the documentation for the command referring to the legacy Windows PowerShell (version 5.1 and below)
SYNOPSIS
powershell { -Command <string> | -File <path> } [-NoProfile] [-NoExit] [-NonInteractive] [-Version <string>] [-EncodedCommand <string>] [-Help] [
PARAMETERS
-Command <string>
Executes the specified commands or script blocks. This is the primary way to run short commands or call scripts from the command line.
-File <path>
Runs the specified PowerShell script file. Any additional arguments following -File are passed as parameters to the script.
-NoProfile
Does not load the current user's PowerShell profile. Useful for clean environments or performance testing.
-NoExit
Does not exit after running startup commands. The PowerShell session remains open after the command or script finishes.
-NonInteractive
Prevents PowerShell from prompting for user input. Essential for automated scripts in CI/CD pipelines.
-EncodedCommand <string>
Accepts a base-64 encoded string version of a command. Useful for obfuscating commands or handling complex strings.
-Version <string>
Specifies the PowerShell version to use. For example, -Version 7.x.
-Help
Displays help information for the powershell command-line executable.
DESCRIPTION
PowerShell is a powerful cross-platform task automation and configuration management framework, developed by Microsoft. It includes a command-line shell, a scripting language, and a framework for processing cmdlets. On Linux, PowerShell enables administrators and developers to leverage its rich object-oriented pipeline and extensive cmdlet ecosystem to manage systems consistently across diverse environments, including cloud services and hybrid infrastructures.
It brings the capabilities of PowerShell, previously Windows-centric, to Linux, facilitating operations like system administration, deployment, and data processing with a unified scripting experience.
CAVEATS
While PowerShell offers powerful capabilities on Linux, users should be aware of a few points:
1. Platform Parity: Not all cmdlets available on Windows are present or function identically on Linux (e.g., cmdlets interacting with Windows-specific APIs).
2. Performance: For very simple tasks, native Linux utilities might offer better performance due to PowerShell's .NET runtime overhead.
3. Integration: Direct piping with traditional Linux text-based tools can require careful handling due to PowerShell's object-oriented pipeline.
INSTALLATION ON LINUX
PowerShell can be installed on various Linux distributions. The most common methods involve downloading official Microsoft packages (e.g., .deb, .rpm) or using a package manager after adding the Microsoft repository. Installation details vary by distribution.
CORE CONCEPTS
PowerShell's strength lies in its core concepts:
Cmdlets: Lightweight, single-function commands that often follow a Verb-Noun naming convention (e.g., Get-Process).
Pipeline: Commands can be chained together, passing objects (not just text) from one cmdlet to the next.
Object-Oriented: Commands output objects with properties and methods, enabling powerful filtering and manipulation.
HISTORY
PowerShell was originally developed by Microsoft for Windows, with its first stable version released in 2006. It was designed to provide a more consistent and powerful way to manage Windows systems than traditional command prompts.
In 2016, Microsoft open-sourced PowerShell and made it cross-platform, releasing PowerShell Core (now simply known as PowerShell) for Linux and macOS. This move aimed to provide a unified management experience across hybrid and cloud environments, bridging the gap between Windows and non-Windows systems.