PowerShell and Winget Cheat Sheet
Copy-paste commands with a one-line explanation each. Run PowerShell as Administrator where noted. Read each command before running it, especially anything that restarts services or installs software. New to this pillar? Start at SysAdmin Start Here, or build a full install script with the Script Stack Generator.
1. Winget
Section titled “1. Winget”Search, inspect, install
Section titled “Search, inspect, install”| Command | What it does |
|---|---|
winget search vscode |
Search the configured sources for a package |
winget show Microsoft.VisualStudioCode |
Show details for a package ID |
winget install --id Microsoft.VisualStudioCode -e |
Install by exact ID (-e means exact match) |
winget list |
List installed apps that winget can see |
winget upgrade |
List apps with available updates |
winget uninstall --id <ID> |
Remove an app by ID |
Upgrade everything
Section titled “Upgrade everything”winget upgrade --allUpgrades all apps that have updates. Review the list first with winget upgrade.
Export and import (rebuild a machine)
Section titled “Export and import (rebuild a machine)”# On the old machine: write installed apps to a filewinget export -o apps.json
# On the new machine: install everything from the filewinget import -i apps.json --accept-package-agreements --accept-source-agreementsEdit apps.json before importing to remove apps you do not want. Some apps may fail to import if they are not available in your sources; the command reports which ones.
2. Network port inspection
Section titled “2. Network port inspection”What is listening
Section titled “What is listening”Get-NetTCPConnection -State ListenLists listening TCP ports with the owning process ID.
Map ports to process names
Section titled “Map ports to process names”Get-NetTCPConnection -State Listen | Select-Object LocalAddress, LocalPort, OwningProcess, @{Name='Process'; Expression={ (Get-Process -Id $_.OwningProcess).ProcessName }} | Sort-Object LocalPortAdds a process name column. Some system processes may need an elevated prompt to resolve.
Who owns one specific port
Section titled “Who owns one specific port”Get-NetTCPConnection -LocalPort 1883 | Select-Object State, OwningProcessGet-Process -Id <PID>Replace 1883 with your port, then look up the PID it returns.
Test reachability of a remote port
Section titled “Test reachability of a remote port”Test-NetConnection 192.168.1.20 -Port 502Look for TcpTestSucceeded : True. A False can mean a closed port, a firewall, or a wrong address. Port numbers for common industrial and IoT protocols are in the ports cheat sheet.
3. Service triage
Section titled “3. Service triage”| Command | What it does |
|---|---|
Get-Service |
List all services and their state |
Get-Service -Name Spooler |
Show one service |
Get-Service | Where-Object Status -eq 'Running' |
Only running services |
Restart-Service -Name Spooler |
Restart a service (admin) |
Stop-Service -Name Spooler / Start-Service -Name Spooler |
Stop or start a service (admin) |
Get-Service -Name Spooler | Select-Object * |
All properties, including dependencies |
Event log queries with Get-WinEvent
Section titled “Event log queries with Get-WinEvent”# System errors in the last 24 hoursGet-WinEvent -FilterHashtable @{ LogName = 'System' Level = 2 StartTime = (Get-Date).AddHours(-24)} | Select-Object TimeCreated, Id, ProviderName, Message -First 20Level values: 1 Critical, 2 Error, 3 Warning, 4 Information.
# Service Control Manager events (service crashes and state changes)Get-WinEvent -FilterHashtable @{ LogName = 'System' ProviderName = 'Service Control Manager' StartTime = (Get-Date).AddDays(-1)} | Select-Object TimeCreated, Id, Message -First 20# Failed logons (Security log requires an elevated prompt)Get-WinEvent -FilterHashtable @{ LogName='Security'; Id=4625 } -MaxEvents 20Event ID 4625 is a failed logon. If you see many from one source, treat it as a security matter; see Cybersecurity start.
4. Linux services and logs
Section titled “4. Linux services and logs”| Command | What it does |
|---|---|
systemctl status NAME |
State of a service plus the last few log lines |
sudo systemctl restart NAME |
Restart a service |
sudo systemctl enable --now NAME |
Start now and on every boot |
systemctl list-units --type=service --state=failed |
Show failed services |
journalctl -u NAME -f |
Follow a service’s log live |
journalctl -u NAME --since "1 hour ago" |
Recent log entries only |
journalctl -p err -b |
Errors since the current boot |
For network commands on Linux (ip, ss, ping), see the Linux networking CLI cheat sheet.
5. Docker
Section titled “5. Docker”| Command | What it does |
|---|---|
docker ps |
Running containers (add -a to include stopped) |
docker logs -f --tail 100 NAME |
Follow the last 100 log lines of a container |
docker stats |
Live CPU, memory and network use per container |
docker stats --no-stream |
One snapshot, then exit |
docker inspect NAME |
Full JSON configuration and state |
docker inspect -f '{{.State.Status}}' NAME |
Pull out a single field |
docker exec -it NAME sh |
Open a shell inside a running container |
docker restart NAME |
Restart a container |
Practise these on a safe target such as the virtual Modbus Docker lab.
Quick triage flow
Section titled “Quick triage flow” Service down? | +-- Windows: Get-Service -> Get-WinEvent (System, last 24 h) -> Restart-Service +-- Linux: systemctl status -> journalctl -u NAME -> restart +-- Docker: docker ps -a -> docker logs -> docker inspect | +-- Still failing? Is the port listening (Get-NetTCPConnection / ss -tulpn) and reachable from the client (Test-NetConnection)?Next: assemble these into a repeatable script with the Script Stack Generator, and keep the Tools hub handy.