PowerCLI: One-Liners Checking Host Network Information
Sometimes as a consultant when performing an initial look or a healthcheck on a new system you will want to confirm all hosts have the correct network information, if there is a mis-configured vmotion portgroup or something similar then this could impact HA or if there is an incorrect DNS server then this may also have issues further down the line with your service console.
The following quick one-liners display some vital information for each host, errors can be seen at a glance, rather than checking each host individually, for us to gain this information we use the wonderful Get-VMHostNetwork cmdlet and expand a few areas of interest:
- Remember these can be narrowed down further by adding the Get-Cluster “MyCluster” | to the start of the line.
- Also remember this information can also be exported to a csv by adding | Export-csv “C:\info.csv” to the end of the line.
To list all ESX Hosts and their Service console information:
Get-VMHost | Get-VMHostNetwork | Select Hostname, ConsoleGateway, DNSAddress -ExpandProperty ConsoleNic | Select Hostname, PortGroupName, IP, SubnetMask, ConsoleGateway, DNSAddress, Devicename
| HostName | PortGroupName | IP | SubnetMask | ConsoleGateway | DNS Address | DeviceName |
| esx01 | SC | 192.168.2.33 | 255.255.255.0 | 192.168.2.1 | 192.168.2.20 192.168.1.20 | vswif0 |
| esx01 | SC 2 | 192.168.3.43 | 255.255.255.0 | 192.168.2.1 | 192.168.2.20 192.168.1.20 | vswif1 |
| esx02 | SC | 192.168.1.12 | 255.255.255.0 | 192.168.1.254 | 192.168.1.20 | vswif0 |
| esx03 | SC | 192.168.2.34 | 255.255.255.0 | 192.168.2.1 | 192.168.2.20 192.168.1.20 | vswif0 |
| esx03 | SC 2 | 192.168.3.44 | 255.255.255.0 | 192.168.2.1 | 192.168.2.20 192.168.1.20 | vswif1 |
To list all ESX Hosts and their VMotion Enabled Networks information:
Get-VMHost | Get-VMHostNetwork | Select Hostname, VMkernelGateway -ExpandProperty VirtualNic | Where {$_.VMotionEnabled} | Select Hostname, PortGroupName, IP, SubnetMask, VMkernelGateway, Devicename
| HostName | PortGroupName | IP | SubnetMask | VMKernelGateway | DeviceName |
| esx01 | VMkernel | 192.168.3.33 | 255.255.255.0 | vmk0 | |
| esx02 | VMkernel | 192.168.3.34 | 255.255.255.0 | 192.168.3.1 | vmk0 |
vTip – A VMware Expert updating your VI PowerCLI: How many VMs on your Datastores ?











I’m getting this error…………….
[vSphere PowerCLI] C:\> Get-VMHost | Get-VMHostNetwork | Select Hostname, ConsoleGateway, DNSAddress -ExpandProperty ConsoleN
ic | Select Hostname, PortGroupName, IP, SubnetMask, ConsoleGateway, DNSAddress, Devicename
WARNING: ‘ConsoleNic’ property is obsolete. Use ‘Get-VMHostNetworkAdapter’ cmdlet instead.
This is not actually an error just a warning that in future versions the ConsoleNic property of this object may be made obsolete.
Hello ,
I really want to see:
PortGroupName:
IP:
Mask:
Gate:
VLAN:
Any ideas how to get VLAN and put it in same table.
Something like that:
$vm = get-vmhost 192.168.0.13
$net = $vm | Get-VirtualPortGroup
$net | Select-Object Name, VLanId | Format-Table -auto
$net2 = $net | Select-Object Name,IP,SubnetMask,Mac | ft -auto
Hello, we have ESXi5 and with this command, i get no result. I’m connect to my VCenter Server