cheat-sheets

Cheat sheets for various stuff

View the Project on GitHub bertvv/cheat-sheets

Windows Shell Survival Guide

Useful PowerShell and cmd-shell commands.

Basic operations

Task Command
Shutdown Stop-Computer
Reboot Restart-Computer
Task Manager <Ctrl-Shift-Escape> or Start-Process Taskmgr
Get environment variable Get-Content env:VARIABLE
e.g. hostname Get-Content env:Computername
Set host name Rename-Computer -NewName NEWNAME -restart

Localization

Task Command
Get the date Get-Date
Set date/time Set-Date "MM/DD/YYYY hh:mm:ss PM"
Get timezone tzutil /g
Set timezone (Brussels) tzutil /s "Romance Standard Time"
Set keyboard layout Set-WinUserLanguageList nl-BE -force

Network interfaces

Task Command
List adapters Get-NetAdapter
Get connection profiles Get-NetAdapter | Get-NetConnectionProfile
Get IP addresses Get-NetIPAddress
Get routing table Get-NetRoute
DNS servers Get-DnsClientServerAddress
“netstat” Get-NetTCPConnection
Troubleshooting Test-NetConnection

Services

Task Command
List all services Get-Service | Format-Table -autosize
View single SERVICE Get-Service | Where name -eq SERVICE | Format-list
Start SERVICE Start-Service -name SERVICE
Stop SERVICE Stop-Service -name SERVICE
All service startup types Get-WmiObject win32_service | Format-Table -autosize
SERVICE startup type Get-WMIObject Win32_Service | where Name -eq SERVICE
Enable SERVICE at boot Set-Service -name SERVICE -StartupType Automatic
Disable SERCIE at boot Set-Service -name SERVICE -StartupType Disabled

Firewall

Task Command
Get FW state Get-NetFirewallProfile -PolicyStore ActiveStore
Get FW rules Get-netfirewallrule | format-table name,displaygroup,action,direction,enabled -autosize
Disable firewall Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled False
Enable firewall Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled True
Set default policy Set-NetFirewallProfile -DefaultInboundAction Block -DefaultOutboundAction Allow
Allow inbound ping Get-NetFirewallRule -DisplayName "*Echo Request*" | Set-NetFirewallRule -enabled true
Allow WinRM HTTPS netsh advfirewall firewall add rule name="Allow WinRM HTTPS"
  dir=in localport=5986 protocol=TCP action=allow
Allow RDP Get-NetFirewallRule -DisplayName "Remote Desktop*" | Set-NetFirewallRule -enabled true

TODO: netsh is the “old” way of manipulating firewall settings and may be removed in later Windows versions. There are CmdLets for the same tasks.

Package management

Windows

Chocolatey

Useful Chocolatey commands:

Task Command
List installed packages choco list --local-only (or -l)
Install choco install -y PACKAGE
Upgrade installed pkgs choco upgrade -y all

Miscellaneous

Task Command
Finding files Get-ChildItem -Path c:\ -Filter PATTERN -Recurse
Get Registry value Get-ItemProperty -Path "HKLM:\PATH\TO\PROP"
Set Registry value Set-ItemProperty -Path "PATH" -Name NAME -Value VALUE
SHA-256 checksum Get-FileHash FILE
MD5 checksum Get-FileHash -Algorithm MD5 FILE
  Also works for SHA1, SHA256
NetBIOS name resolution nbtstat -a NETBIOS_NAME -c

Resources

Remark: pipe symbol inside tables: use &#124; (but outside of code blocks!)