PowerShell Commands: A Comprehensive Guide
PowerShell is a powerful task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework.
Core Concepts
Understanding basic PowerShell concepts is crucial for effective command usage. Key elements include:
- Cmdlets: These are the native PowerShell commands. They are typically verb-noun pairs (e.g.,
Get-Process
,Set-Location
). - Providers: These allow you to access data stores (like the file system or registry) as if they were file systems.
- Objects: Unlike traditional shells that output text, PowerShell passes objects between cmdlets, preserving their properties and methods.
- Pipeline: This is the mechanism for chaining commands together, where the output of one command becomes the input of the next.
Commonly Used Cmdlets
Here are some of the most frequently used PowerShell cmdlets that every user should be familiar with:
Get-Command
Finds PowerShell commands. You can use it to search for cmdlets, functions, aliases, and more.
Get-Command -Name *process*
Get-Help
Displays information about PowerShell commands and concepts.
Get-Help Get-Process -Examples
Get-Process
Gets the processes running on the local or remote computer.
Get-Process -Name notepad
Get-Service
Gets the services on a local or remote computer.
Get-Service -DisplayName *web*
Get-ChildItem
Gets the items and their hierarchical structure in one or more specified locations (like files and folders).
Get-ChildItem C:\Windows -Filter *.log
Set-Location
Changes the current working location to a specified location.
Set-Location C:\Users\Me\Documents
New-Item
Creates a new item, such as a file or directory.
New-Item -Path .\NewFolder -ItemType Directory
Remove-Item
Deletes one or more specified items.
Remove-Item C:\Temp\oldfile.txt
Copy-Item
Copies items from one location to another.
Copy-Item -Path .\source.txt -Destination .\backup\
Move-Item
Moves items from one location to another.
Move-Item -Path .\draft.docx -Destination .\final\
Select-Object
Selects objects that contain specified properties from the input.
Get-Process | Select-Object -Property Name, Id, CPU
Where-Object
Filters objects based on their property values.
Get-Process | Where-Object {$_.CPU -gt 100}
Scripting and Automation
PowerShell's true power lies in its scripting capabilities. You can create scripts to automate repetitive tasks, manage configurations, and perform complex operations.
For advanced scripting, consider learning about:
- Variables and data types
- Control flow (If, For, While loops)
- Functions and modules
- Error handling
- Remoting
Explore the official Microsoft PowerShell documentation for in-depth guides and examples.