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"
}