1. File and Directory Management
Get-ChildItem (gci / ls / dir) – Lists files and directories.
Syntax: Get-ChildItem [-Path] <string> [-Recurse] [-Force]
Examples:
Get-ChildItem→ List items in current directoryGet-ChildItem -Path C:Users -Recurse→ Recursively list itemsGet-ChildItem -Force→ Include hidden files
Set-Location (cd / sl) – Change current directory.
Syntax: Set-Location [-Path] <string>
Examples:
Set-Location C:Users→ Move to folderSet-Location ..→ Move to parent directory
Copy-Item (cp / copy) – Copies files or folders.
Syntax: Copy-Item [-Path] <string> [-Destination] <string> [-Recurse] [-Force]
Examples:
Copy-Item .file.txt C:Backupfile.txtCopy-Item .* C:Backup -Recurse→ Copy all files recursively
Move-Item (mv / move) – Moves files or directories.
Syntax: Move-Item [-Path] <string> [-Destination] <string> [-Force]
Examples:
Move-Item .file.txt C:Archivefile.txt
Remove-Item (rm / del / rmdir) – Deletes files or directories.
Syntax: Remove-Item [-Path] <string> [-Recurse] [-Force]
Examples:
Remove-Item .temp.txt→ Delete a fileRemove-Item C:Temp -Recurse -Force→ Delete folder with all contents
New-Item – Creates a new file or directory.
Syntax: New-Item [-Path] <string> [-ItemType <string>]
Examples:
New-Item -Path . -Name "NewFolder" -ItemType DirectoryNew-Item -Path . -Name "file.txt" -ItemType File
2. System and Process Management
Get-Process (ps / gps) – Lists running processes.
Syntax: Get-Process [-Name] <string>
Examples:
Get-Process→ Show all processesGet-Process -Name notepad
Stop-Process (kill) – Stops a process.
Syntax: Stop-Process [-Name] <string> [-Id] <int> [-Force]
Examples:
Stop-Process -Name notepadStop-Process -Id 1234 -Force
Get-Service – Lists Windows services.
Syntax: Get-Service [-Name] <string>
Examples:
Get-Service→ List all servicesGet-Service -Name wuauserv
Start-Service / Stop-Service – Starts or stops a service.
Syntax: Start-Service [-Name] <string> / Stop-Service [-Name] <string>
Examples:
Start-Service wuauservStop-Service wuauserv
Restart-Computer – Restarts the system.
Syntax: Restart-Computer [-Force] [-Wait] [-Delay <int>]
Example:
Restart-Computer -Force
Get-EventLog – Retrieves event logs.
Syntax: Get-EventLog -LogName <string> [-Newest <int>]
Example:
Get-EventLog -LogName System -Newest 10→ Last 10 system events
3. Network Management
Test-Connection (ping) – Tests connectivity.
Syntax: Test-Connection [-ComputerName] <string> [-Count <int>]
Example:
Test-Connection google.com -Count 4
Get-NetIPAddress – Shows IP configuration.
Syntax: Get-NetIPAddress
Example:
Get-NetIPAddress→ List all IP addresses
Resolve-DnsName – DNS query.
Syntax: Resolve-DnsName [-Name] <string>
Example:
Resolve-DnsName google.com
Get-NetTCPConnection – Displays TCP connections (like netstat).
Syntax: Get-NetTCPConnection
Example:
Get-NetTCPConnection
4. Environment and Variables
Get-Variable / Set-Variable / Remove-Variable – Manage PowerShell variables.
Syntax:
Get-Variable -Name <string>Set-Variable -Name <string> -Value <object>Remove-Variable -Name <string>
Example:Set-Variable -Name myVar -Value 42Get-Variable -Name myVarRemove-Variable -Name myVar
Get-ChildItem Env: – List environment variables.
Syntax: Get-ChildItem Env:
Example:
Get-ChildItem Env:PATH
5. Output and Formatting
Write-Output / Write-Host – Print text to console.
Syntax:
Write-Output "text"Write-Host "text"
Example:Write-Output "Hello World"Write-Host "Warning!" -ForegroundColor Red
Format-Table / Format-List – Format output.
Example:
Get-Process | Format-Table -AutoSizeGet-Service | Format-List Name, Status
Out-File / Tee-Object – Redirect output to file.
Example:
Get-Process | Out-File C:tempprocesses.txtGet-Process | Tee-Object -FilePath C:tempprocesses.txt
6. Scripting & Control Flow
If / Else – Conditional execution.
Example:
if (Test-Path "C:tempfile.txt") {
Write-Host "File exists"
} else {
Write-Host "File not found"
}
ForEach-Object / ForEach – Loop through collection.
Example:
Get-ChildItem | ForEach-Object { Write-Host $_.Name }
Switch – Multi-condition branching.
Example:
switch ($day) {
"Mon" { Write-Host "Monday" }
"Tue" { Write-Host "Tuesday" }
}
Try / Catch / Finally – Error handling.
Example:
try {
Remove-Item "C:tempnofile.txt"
} catch {
Write-Host "File not found"
} finally {
Write-Host "Operation finished"
}
