Skip to content

Instantly share code, notes, and snippets.

@jonashackt
Last active February 27, 2018 13:59
Show Gist options
  • Save jonashackt/bafddb98beeebcc244562824e812e484 to your computer and use it in GitHub Desktop.
Save jonashackt/bafddb98beeebcc244562824e812e484 to your computer and use it in GitHub Desktop.
Powershell cheatsheet

Start Powershell from cmd

start powershell

Resolve a DNS name:

Resolve-DnsName

Get PortMapping (e.g. if HNS error - object already exists occurs)

Get-NetNatStaticMapping

...and remove the failing PortMapping with (but LOOK, it goes through all mapping with the same NatName

- so if you only want to remove one, then just say Yes there)

Remove-NetNatStaticMapping [NatName]

Show Environment variables

Get-ChildItem Env:

Set Environment variable permanentely

[Environment]::SetEnvironmentVariable('DOCKER_HOME', 'c:\ProgramData\chocolatey\lib\docker\tools\docker', 'Machine')

Install something from the web to specific folder including usage of environment variable

iwr https://github.com/docker/compose/releases/download/1.11.2/docker-compose-Windows-x86_64.exe -OutFile $env:DOCKER_HOME\docker-compose.exe

Add content of environment variable to Windows Path

[Environment]::SetEnvironmentVariable('Path', $env:Path + ';' + $env:DOCKER_HOME, 'Machine')

Check, if Port of Windows Server 2016 is open from other Windows Server 2016

Test-NetConnection -ComputerName 192.168.0.1 -Port 7865 -InformationLevel Detailed

show Windows Licence expiration period on powershell/cmd

slmgr.vbs /dlv

Show firewall rules

Get-NetFirewallRule

Get IPv4 address from Ethernet adapter vEthernet (HNS Internal NIC) with Powershell

(Get-NetIPAddress -InterfaceAlias 'vEthernet (HNS Internal NIC)' -AddressFamily IPv4).IPAddress

Windows Updates

Install Windows Updates

choco install pswindowsupdate (to get https://gallery.technet.microsoft.com/scriptcenter/2d191bcd-3308-4edd-9de2-88dff796b0bc)

Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d

Get-WUInstall –MicrosoftUpdate –AcceptAll –AutoReboot -IgnoreUserInput -WhatIf -Verbose

Scan for Updates

Get-WUList

Show installed Updates

Get-WUHistory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment