Tag: IP

Get-NetIPConfiguration

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-NetIPConfiguration

Get the IP Configuration (ipconfig with PowerShell)

Get-NetIPConfiguration

List all Network Adapters

Get-NetAdapter

Get a spesific network adapter by name

Get-NetAdapter -Name *Ethernet*

Get more information VLAN ID, Speed, Connection status

Get-NetAdapter | ft Name, Status, Linkspeed, VlanID

Get driver information

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.

Get-NetAdapterHardwareInfo

Disable and Enable a Network Adapter

Disable-NetAdapter -Name "Wireless Network Connection"
Enable-NetAdapter -Name "Wireless Network Connection"

Rename a Network Adapter

Rename-NetAdapter -Name "Wireless Network Connection" -NewName "Wireless"

IP Configuration using PowerShell

PowerShell Networking Get-NetIPAddress

Get IP and DNS address information

Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress

Get IP address only

(Get-NetAdapter -Name "Local Area Connection" | Get-NetIPAddress).IPv4Address

Get DNS Server Address information

Get-NetAdapter -Name "Local Area Connection" | Get-DnsClientServerAddress

Set IP Address

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

Set-NetIPAddress -InterfaceAlias "Wireless" -IPv4Address 192.168.12.25 -PrefixLength "24"

Remove IP Address

Get-NetAdapter -Name "Wireless" | Remove-NetIPAddress

Set DNS Server

Set-DnsClientServerAddress -InterfaceAlias "Wireless" -ServerAddresses "10.10.20.1","10.10.20.2"

Set interface to DHCP

Set-NetIPInterface -InterfaceAlias "Wireless" -Dhcp Enabled

Clear DNS Cache with PowerShell

You can also manage your DNS cache with PowerShell.

List DNS Cache:

 
Get-DnsClientCache

Clear DNS Cache

 
Clear-DnsClientCache

Ping with PowerShell

PowerShell Networking Test-NetConnection Ping

How to Ping with PowerShell. For a simple ping command with PowerShell, you can use the Test-Connection cmdlet:

 
Test-Connection thomasmaurer.ch

There is an advanced way to test connection using PowerShell

Test-NetConnection -ComputerName www.thomasmaurer.ch

Get some more details from the Test-NetConnection

Test-NetConnection -ComputerName www.thomasmaurer.ch -InformationLevel Detailed

Ping multiple IP using PowerShell

1..99 | % { Test-NetConnection -ComputerName x.x.x.$_ } | FT -AutoSize

Tracert

PowerShell Tracert

Tracert with PowerShell

Test-NetConnection www.thomasmaurer.ch –TraceRoute

Portscan with PowerShell

PowerShell Portscan

Use PowerShell to check for open port

Test-NetConnection -ComputerName www.thomasmaurer.ch -Port 80
Test-NetConnection -ComputerName www.thomasmaurer.ch -CommonTCPPort HTTP

NSlookup in PowerShell

PowerShell Networking NSlookup

NSlookup using PowerShell:

Resolve-DnsName www.thomasmaurer.ch
Resolve-DnsName www.thomasmaurer.ch -Type MX -Server 8.8.8.8

Route in PowerShell

PowerShell Networking Route

How to replace Route command with PowerShell

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

PowerShell Networking Netstat

How to replace NETSTAT with PowerShell

Get-NetTCPConnection
Get-NetTCPConnection –State Established

NIC Teaming PowerShell commands

Create a new NIC Teaming (Network Adapter Team)

New-NetLbfoTeam -Name NICTEAM01 -TeamMembers Ethernet, Ethernet2 -TeamingMode SwitchIndependent -TeamNicName NICTEAM01 -LoadBalancingAlgorithm Dynamic

SMB Related PowerShell commands

SMB PowerShell SMB Client Configuration

Get SMB Client Configuration

Get-SmbClientConfiguration

Get SMB Connections

Get-SmbConnection

Get SMB Mutlichannel Connections

Get-SmbMutlichannelConnection

Get SMB open files

Get-SmbOpenFile

Get SMB Direct (RDMA) adapters

Get-NetAdapterRdma

Hyper-V Networking cmdlets

Hyper-V PowerShell Get-VMNetwork Adapter

Get and set Network Adapter VMQ settings

Get-NetAdapterVmq
# Disable VMQ
Set-NetAdapterVmq -Enabled $false
# Enable VMQ
Set-NetAdapterVmq -Enabled $true

Get VM Network Adapter

Get-VMNetworkAdapter -VMName Server01

Get VM Network Adapter IP Addresses

(Get-VMNetworkAdapter -VMName NanoConHost01).IPAddresses

Get VM Network Adapter Mac Addresses

(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.



Cisco UCS Hardware

Automate your Cisco UCS with System Center Orchestrator

Some days ago I posted an article how you can manage your Cisco UCS Blade Center directly from System Center Virtual machine Manager. Cisco also offers an Integration Pack for System Center Orchestrator which allows you to automate your Cisco UCS via Orchestrator Integration Packs, which is great if you are building your own Private Cloud based on Cisco hardware.

First step you have to download the Cisco UCS PowerTool (PowerShell Module) and the Cisco UCS Microsoft System Center Orchestrator Integration Pack.

After you have installed the Cisco UCS PowerTool on your System Center Orchestrator Runbook servers you now an import the Integration Pack via the System Center Orchestrator Deployment Manager. With a right click on Integration Packs you can Register the Cisco UCS IP.

Cisco UCS Integration Pack Orchestator Deployment Manager

After that you also have to deploy the IP to the Orchestrator Runbook servers.

Cisco UCS Integration Pack Orchestator Deployment Manager Deploy

You can start to create new Orchestrator Run Books with the Runbook Designer. First open the SCO Runbook Designer and in the Options menu select Cisco UCS to added the Path to the Cisco UCS PowerTool module (PowerShell module). The default path the Cisco UCS PowerTools are installed is: “C:\Program Files (x86)\Cisco\Cisco UCS PowerTool\Modules\CiscoUcsPS\CiscoUcsPS.psd1”

Cisco UCS Integration Pack Orchestator PowerTool Path

You can now start to automate your Cisco UCS with System Center Orchestrator.

If you are interested in how you monitor your Cisco UCS system with System Center Operations Manager Stefan Roth blogged about that.



Hyper-V Converged Fabric with System Center 2012 SP1 – Virtual Machine Manager

System Center Logo

This blog post is a part of a series of blog posts about System Center 2012 Virtual Machine Manager, I am writing together with Michel Luescher (Consultant from Microsoft Switzerland).

Hyper-V Converged Fabric

Last year I already wrote a blog post about Windows Server 2012 Hyper-V Converged Fabric or Converged Networking. Hyper-V Converged Fabric in a simple way allows you to use network adapters for different type of traffic. In Windows Server 2008 R2 Hyper-V we didn’t really had this capabilities because the network teaming relied on 3rd party software and Hyper-V itself didn’t offered a mature QoS solution. In other words, we had to go with what I now would call a traditional Hyper-V host design.

Traditional Design

traditional Hyper-V host

Each dedicated Hyper-V network such as CSV communication or the Live Migration network used an own dedicated physical network interface. These different network interfaces could also be teamed with third party software, example with the software from HP, Broadcom or Intel. This design is still a good design in Windows Server 2012 but there are other configurations which are a lot more flexible.

In Windows Server 2012 you can get much more out of your network configuration. First of all NIC Teaming is now integrated and therefor out-of-the-box supported in Windows Server 2012. Another cool feature is the use of virtual network adapters in the Management OS (a.k.a. Parent Partition). This allows you to create a Hyper-V Hosts with all the necessary networks (Management, Live Migration, Cluster,…) by teaming just two or more physical adapters for a virtual switch and then create the additional virtual network adapters (vNICs) for the Hyper-V Management OS.



Create Cisco VLAN Config with Powershell

Powershell HeaderSmall Script for creating a simple CISCO VLAN config.

# Create Cisco VLANs Config
#
# www.thomasmaurer.ch
# (c) 2010 Thomas Maurer
#
#
 
# First VLAN which should be created?
[int]$VLAN = 1201
# How many VLANs should be created?
[int]$VLANCount = 25
# Start IP Address
[int]$IP = 1
# Subnet
[string]$Subnetmaskv4 = "255.255.255.252"
[string]$Subnetmaskv6 = "64"
# Next IP (Its Important for Subnet)
[int]$AddtoIP = 4
# IPv4 Address Template
[string]$IPv4AddressTemplate = "192.168.1."
# IPv6 Address Template
[string]$IPv6AddressTemplate = "2002:1b50:251:22:192:168:1:"
# Config File Name
[String]$ConfigFile = "C:\Users\tm\Desktop\config.txt"
 
# Creats Config
for($counter = 0;$counter -le $VLANCount;$counter++) {
[string]$interfaceconf = "interface Vlan" + $VLAN
[string]$IPv4conf = "ip address " + $IPv4AddressTemplate + $IP + " " + $Subnetmaskv4
[string]$IPv6conf = "ipv6 address " + $IPv6AddressTemplate + $IP + "/" + $Subnetmaskv6
Add-Content $ConfigFile $interfaceconf
Add-Content $ConfigFile "no shutdown"
Add-Content $ConfigFile $IPv4conf
Add-Content $ConfigFile $IPv6conf
$IP = $IP + $AddtoIP
}