Basic Networking PowerShell cmdlets cheatsheet to replace netsh, ipconfig, nslookup and more
Around 4 years ago I wrote a blog post about how to Replace netsh with Windows PowerShell which includes basic powershell networking cmdlets. After working with Microsoft Azure, Nano Server and Containers, PowerShell together with networking becomes more and more important. I created this little cheat sheet so it becomes easy for people to get started.
Basic Networking PowerShell cmdlets
Get the IP Configuration (ipconfig with PowerShell)
1 | Get-NetIPConfiguration |
List all Network Adapters
1 | Get-NetAdapter |
Get a spesific network adapter by name
1 | Get-NetAdapter -Name *Ethernet* |
Get more information VLAN ID, Speed, Connection status
1 | Get-NetAdapter | ft Name, Status, Linkspeed, VlanID |
Get driver information
1 | Get-NetAdapter | ft Name, DriverName, DriverVersion, DriverInformation, DriverFileName |
Get adapter hardware information. This can be really usefull when you need to know the PCI slot of the NIC.
1 | Get-NetAdapterHardwareInfo |
Disable and Enable a Network Adapter
1 2 | Disable-NetAdapter -Name "Wireless Network Connection" Enable-NetAdapter -Name "Wireless Network Connection" |
Rename a Network Adapter
1 | Rename-NetAdapter -Name "Wireless Network Connection" -NewName "Wireless" |
IP Configuration using PowerShell
Get IP and DNS address information
1 | Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress |
Get IP address only
1 | (Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress).IPv4Address |
Get DNS Server Address information
1 | Get-NetAdapter -Name "Local Area Connection" | Get-DnsClientServerAddress |
Set IP Address
1 | New-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 10.0.1.95 -PrefixLength "24" -DefaultGateway 10.0.1.1 |
or if you want to change a existing IP Address
1 | Set-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 192.168.12.25 -PrefixLength "24" |
Remove IP Address
1 | Get-NetAdapter -Name "Wireless" | Remove-NetIPAddress |
Set DNS Server
1 | Set-DnsClientServerAddress -InterfaceAlias "Wireless" -ServerAddresses "10.10.20.1","10.10.20.2" |
Set interface to DHCP
1 | Set-NetIPInterface -InterfaceAlias "Wireless" -Dhcp Enabled |
Clear DNS Cache with PowerShell
You can also manage your DNS cache with PowerShell.
List DNS Cache:
1 | Get-DnsClientCache |
Clear DNS Cache
1 | Clear-DnsClientCache |
Ping with PowerShell
How to Ping with PowerShell. For a simple ping command with PowerShell, you can use the Test-Connection cmdlet:
1 | Test-Connection thomasmaurer.ch |
There is an advanced way to test connection using PowerShell
1 | Test-NetConnection -ComputerName www.thomasmaurer.ch |
Get some more details from the Test-NetConnection
1 | Test-NetConnection -ComputerName www.thomasmaurer.ch -InformationLevel Detailed |
Ping multiple IP using PowerShell
1 | 1..99 | % { Test-NetConnection -ComputerName x.x.x.$_ } | FT -AutoSize |
Tracert
Tracert with PowerShell
1 | Test-NetConnection www.thomasmaurer.ch –TraceRoute |
Portscan with PowerShell
Use PowerShell to check for open port
1 2 | Test-NetConnection -ComputerName www.thomasmaurer.ch -Port 80 Test-NetConnection -ComputerName www.thomasmaurer.ch -CommonTCPPort HTTP |
NSlookup in PowerShell
NSlookup using PowerShell:
1 2 | Resolve-DnsName www.thomasmaurer.ch Resolve-DnsName www.thomasmaurer.ch -Type MX -Server 8.8.8.8 |
Route in PowerShell
How to replace Route command with PowerShell
1 2 3 4 | Get-NetRoute -Protocol Local -DestinationPrefix 192.168* Get-NetRoute -InterfaceAlias Wi-Fi New-NetRoute –DestinationPrefix "10.0.0.0/24" –InterfaceAlias "Ethernet" –NextHop 192.168.192.1 |
NETSTAT in PowerShell
How to replace NETSTAT with PowerShell
1 2 | Get-NetTCPConnection Get-NetTCPConnection –State Established |
NIC Teaming PowerShell commands
Create a new NIC Teaming (Network Adapter Team)
1 | New-NetLbfoTeam -Name NICTEAM01 -TeamMembers Ethernet, Ethernet2 -TeamingMode SwitchIndependent -TeamNicName NICTEAM01 -LoadBalancingAlgorithm Dynamic |
SMB Related PowerShell commands
Get SMB Client Configuration
1 | Get-SmbClientConfiguration |
Get SMB Connections
1 | Get-SmbConnection |
Get SMB Mutlichannel Connections
1 | Get-SmbMutlichannelConnection |
Get SMB open files
1 | Get-SmbOpenFile |
Get SMB Direct (RDMA) adapters
1 | Get-NetAdapterRdma |
Hyper-V Networking cmdlets
Get and set Network Adapter VMQ settings
1 2 3 4 5 | Get-NetAdapterVmq # Disable VMQ Set-NetAdapterVmq -Enabled $false # Enable VMQ Set-NetAdapterVmq -Enabled $true |
Get VM Network Adapter
1 | Get-VMNetworkAdapter -VMName Server01 |
Get VM Network Adapter IP Addresses
1 | (Get-VMNetworkAdapter -VMName NanoConHost01).IPAddresses |
Get VM Network Adapter Mac Addresses
1 | (Get-VMNetworkAdapter -VMName NanoConHost01).MacAddress |
I hope you enjoyed it and the post was helpful, if you think something important is missing, please add it in the comments.