Powershell¶
Keyboard shortcuts for Powershell and Windows Terminal App¶
Normal shortcuts like CTRL+A / CTRL+C / CTRL+V
CTRL+Shift+T new tab
ALT+- new pane
CTRL+TAB to switch tabs
CTRL+ALT+1 goto first tab
ALT+up/down switch panes
CTRL+Shift+W close focused pane
CTRL+left/right jump word back-/forwards
CTRL+Backspace delete word
Profile handling¶
Edit profile
notepad.exe $profile
Reload profile
&$profile
Find a command¶
Get-Command -Noun <search_string>
To find it’s location
Get-Command <cmd>
Read manual page¶
Get-Help <command> -Examples
Show end of file with continuos entries¶
Get-Content -Tail 10 -Wait <Filename>
List directory sorted by last updated timestamp¶
Get-ChildItem | Sort-Object LastWriteTime
List running processes¶
Get-Process
List logged in users¶
query user /server:$SERVER
Run command as another user¶
As normal user
Start-Process -FilePath "path\to\exe" -ArgumentList "parameter1", "parameter2" -Verb RunAs -Credential <username>
As administrator
Start-Process -FilePath "path\to\exe" -ArgumentList "parameter1", "parameter2" -Verb RunAs
Run command every x seconds¶
while($true) { Get-Process | findstr /s foo; Start-Sleep -Seconds 10 }
Measure execution time of a command¶
Measure-Command {some.exe param1 param2}
Get current user¶
env:username
Print all environment variables¶
Get-ChildItem env:
Start a service¶
Start-Service -Name "sshd"
Set-Service -Name "sshd" -StartupType Automatic
Show Routing table¶
Get-NetRoute
Show IP adresses¶
Get-NetIPAddress
List all member (methods and properties) of an object¶
e.g. from process edge
Get Process -Name msedge | Get-Member
Filter objects¶
Get-PSDrive | Where-Object { $_.free -gt 1 }
Count lines¶
netstat -an | findstr /s LISTEN | Measure-Object -line
Loop¶
Get Process -Name msedge | ForEach-Object { $_.Kill() }
Recursive directory actions¶
get-childitem -Recurse C:\Users | foreach-object { S_.Name }
File Operations¶
Copy-Item
Move-Item
Rename-Item
Remove-Item
Get product id of an app¶
get-wmiobject Win32_Product | Format-Table IdentifyingNumber, Name -AutoSize