Cheat sheets for various stuff
Useful PowerShell and cmd-shell commands.
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 |
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 |
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 |
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 |
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.
List installed programs:
Get-ItemProperty
HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*
| Select-Object DisplayName, DisplayVersion, Publisher, InstallDate
| Sort -Property DisplayName
| Format-Table -AutoSize
List all store-installed programs:
Get-AppxPackage | Select-Object Name, PackageFullName, Version
| Sort -Property Name
| Format-Table -AutoSize
Remove program: Get-AppxPackage *PACKAGE_PATTERN* | Remove-AppxPackage
Install Chocolatey
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Install BoxStarter
choco install Boxstarter
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 |
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 |
Remark: pipe symbol inside tables: use |
(but outside of code blocks!)