Run PowerShell (pwsh) commands and scripts. Use when the user asks to automate Windows tasks, manage files/processes/services, query system info, or run .ps1 scripts. Also covers cross-platform pwsh on macOS/Linux.
Use pwsh (PowerShell Core 7+) for all commands — not powershell.exe (Windows PowerShell 5).
Run a one-liner:
pwsh -Command "Get-Date"
Run a script file:
pwsh -File ./script.ps1
Run with no profile (faster, avoids profile side-effects):
pwsh -NoProfile -Command "..."
$name = "world"
Write-Output "Hello, $name"
# Suppress output
$null = Some-Command
# Capture output
$result = Get-Process | Where-Object { $_.CPU -gt 10 }
# List files
Get-ChildItem -Path C:\Users -Recurse -Filter "*.log"
Get-ChildItem | Sort-Object LastWriteTime -Descending | Select-Object -First 10
# Copy / Move / Delete
Copy-Item src.txt dst.txt
Move-Item old.txt new.txt
Remove-Item file.txt
Remove-Item folder -Recurse -Force
# Read / Write files
Get-Content file.txt
Set-Content file.txt "content"
Add-Content file.txt "appended line"
"line1", "line2" | Out-File output.txt -Encoding UTF8
# List processes
Get-Process
Get-Process -Name chrome
# Kill a process
Stop-Process -Name notepad
Stop-Process -Id 1234
# Start a process
Start-Process notepad.exe
Start-Process pwsh -ArgumentList "-File script.ps1" -Wait
Get-Service
Get-Service -Name wuauserv
Start-Service -Name Spooler
Stop-Service -Name Spooler
Restart-Service -Name Spooler
Set-Service -Name Spooler -StartupType Automatic
# OS / hardware
Get-ComputerInfo | Select-Object WindowsVersion, TotalPhysicalMemory
[System.Environment]::OSVersion
$env:COMPUTERNAME; $env:USERNAME
# Disk usage
Get-PSDrive -PSProvider FileSystem
# Network
Get-NetIPAddress
Test-NetConnection google.com -Port 443
Resolve-DnsName google.com
# Read
Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" -Name ProductName
# Write
Set-ItemProperty -Path "HKCU:\Software\MyApp" -Name "Setting" -Value "Value"
# Create key
New-Item -Path "HKCU:\Software\MyApp" -Force
# GET request
$resp = Invoke-WebRequest -Uri "https://api.example.com/data" -UseBasicParsing
$resp.Content
# POST JSON
$body = @{ key = "value" } | ConvertTo-Json
Invoke-RestMethod -Uri "https://api.example.com" -Method POST -Body $body -ContentType "application/json"
# Download file
Invoke-WebRequest -Uri "https://example.com/file.zip" -OutFile "file.zip"
# Parse JSON
$data = '{"name":"Alice","age":30}' | ConvertFrom-Json
$data.name
# Build JSON
@{ name = "Alice"; scores = @(95, 87) } | ConvertTo-Json -Depth 5
# Filter objects
Get-Process | Where-Object { $_.WorkingSet -gt 100MB }
# Select columns
Get-Process | Select-Object Name, Id, CPU | Sort-Object CPU -Descending
# Group and count
Get-ChildItem -Recurse | Group-Object Extension | Sort-Object Count -Descending
# First / Last
Get-EventLog -LogName System -Newest 20 | Select-Object -First 5
try {
Get-Item "nonexistent" -ErrorAction Stop
} catch {
Write-Error "Failed: $_"
}
# Suppress non-terminating errors
Get-Item "missing" -ErrorAction SilentlyContinue
# List tasks
Get-ScheduledTask | Where-Object { $_.State -eq "Ready" }
# Create task
$action = New-ScheduledTaskAction -Execute "pwsh.exe" -Argument "-File C:\scripts\backup.ps1"
$trigger = New-ScheduledTaskTrigger -Daily -At "02:00AM"
Register-ScheduledTask -TaskName "NightlyBackup" -Action $action -Trigger $trigger -RunLevel Highest
# Check current policy
Get-ExecutionPolicy
# Allow local scripts (run once as admin)
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
# Bypass for a single run
pwsh -ExecutionPolicy Bypass -File script.ps1
# Find large files (>100 MB)
Get-ChildItem C:\ -Recurse -ErrorAction SilentlyContinue |
Where-Object { $_.Length -gt 100MB } |
Sort-Object Length -Descending |
Select-Object FullName, @{n="MB";e={[math]::Round($_.Length/1MB,1)}}
# Kill all processes matching a name
Get-Process chrome -ErrorAction SilentlyContinue | Stop-Process -Force
# Get public IP
(Invoke-RestMethod https://api.ipify.org?format=json).ip
# Measure command time
Measure-Command { Get-ChildItem C:\ -Recurse }
-ErrorAction SilentlyContinue to suppress non-fatal errors-WhatIf on destructive commands to preview without executing$_ is the current pipeline object; $? is last command success boolInvoke-RestMethod over Invoke-WebRequest for JSON APIs (auto-parses)