Common Operations

Help Commands

Get-Help <cmd>
Get-Help <cmd> -Examples
Get-Help -Name Get-Process -Parameter Id

Command Discovery

Get-Command -Module ActiveDirectory
Get-Module --ListAvailable
Get-Alias | Select-Object Name, Definition

Object Operations

Get-Process | Get-Member
Get-Process | Select-Object Name, CPU
Get-Service | Where-Object { $PSItem.Status -eq 'Running' }

System Administration

System Information

Get-CimInstance -ClassName Win32_BIOS
Get-CimInstance -ClassName Win32_DiskDrive
Get-CimInstance -ClassName Win32_PhysicalMemory

Network Management

Test-Connection -ComputerName google.com
Get-NetAdapter
Get-NetIPAddress
Test-NetConnection google.com -Port 80

User & Group Management

Get-LocalUser
New-LocalUser -Name NewUser -Password (ConvertTo-SecureString "Password123" -AsPlainText -Force)
Get-LocalGroup

File System

New-Item -path file.txt -type 'file' -value 'contents'
Copy-Item <src> -destination <dest>
Move-Item -path <src> -destination <dest>
Remove-Item <file>
Test-Path <path>

Using .NET Classes

[System.IO.File]::WriteAllText('test.txt', '')
[System.IO.File]::Delete('test.txt')

Import/Export

Get-Content -Path "test.txt"
Get-Process | Out-File -FilePath "processes.txt"
Get-Process | Export-Csv -Path "processes.csv"

Scripting

Variables

$var = 0
[int] $var = 42
$arrayvar = @('val1','val2')
$dict = @{k1 = 'test'; k2 = 'best'}

Operators

Operator Description
-eq / -ne Equal / Not equal
-lt / -gt Less than / Greater than
-le / -ge Less or equal / Greater or equal
-like / -match Wildcard matching / Regex matching
-and / -or Logical AND / OR

Functions

function MyFunction {
  param([string]$Name)
  Write-Host "Hello $Name"
}

Common Verbs

Verb Description
Get Retrieve information
Set Configure or change settings
New Create new objects
Remove Delete or remove items
Invoke Execute specific operations
Start Start processes or operations
Stop Stop processes or operations

Note

PowerShell commands follow a Verb-Noun format (e.g., Get-Process, Set-Service)

Useful Tips

Command History

Get-History
Invoke-History -Id 5

Filtering & Sorting

Get-ChildItem | Sort-Object Length -Descending
Get-Service | Format-Table -AutoSize
Get-Process | Format-List -Property Name, CPU

Execution Policy

Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned

Escape Character

In PowerShell, the escape character is the backtick ` (not backslash)