Home › Templates › PowerShell commands

🪟 PowerShell commands cheat sheet: everyday one-liners you can copy

PowerShell is powerful, but nobody remembers every cmdlet and parameter. These are the one-liners people reach for most often when working on Windows machines and servers.

Replace the [brackets] with your own values. Save the pack to CopyCat and the command you need is always one click away. Be careful with commands that delete or stop things: read them before you run them.

List files, newest first

Get-ChildItem -Force | Sort-Object LastWriteTime -Descending | Select-Object -First 20 Name, Length, LastWriteTime

Find files by name

Get-ChildItem -Path [C:\path] -Recurse -Filter "[*.log]" -ErrorAction SilentlyContinue | Select-Object FullName, Length

Search text inside files

Select-String -Path "[C:\path\*.txt]" -Pattern "[text]" -Recurse | Select-Object Path, LineNumber, Line

Show what is using a port

Get-NetTCPConnection -LocalPort [3000] | Select-Object LocalPort, State, OwningProcess, @{n='Process';e={(Get-Process -Id $_.OwningProcess).ProcessName}}

Stop a process

Stop-Process -Name "[processname]" -Force

Kill whatever holds a port

Stop-Process -Id (Get-NetTCPConnection -LocalPort [3000]).OwningProcess -Force

Test a connection

Test-NetConnection -ComputerName [hostname] -Port [443]

Tail a log file

Get-Content "[C:\path\app.log]" -Tail 50 -Wait

Top processes by memory

Get-Process | Sort-Object WorkingSet -Descending | Select-Object -First 10 Name, Id, @{n='MemoryMB';e={[math]::Round($_.WorkingSet / 1MB)}}

Restart a service

Restart-Service -Name "[ServiceName]" -Force; Get-Service -Name "[ServiceName]"

More template packs

Stop retyping these

Add the whole "PowerShell commands" pack to CopyCat in one click and edit anything you like.

Add this pack