= Script: PowerCLI: Get Host Network Information =
**Summary**: A script to collect all network information from an ESX host \\
**Date**: Around 2013 \\
**Refactor**: 22 March 2025: Checked links and formatting. \\
{{tag>powershell vmware}}
This script will grab all network information from a host including:
* vmnic configuration
* vmkernel ports information
* service console information
* all virtual switches
* all port groups
== Script ==
# Basehost must be an exact match to the name in vcenter
$BASEHost = Read-Host "Enter the name of the server as found in vCenter"
$timestamp = Get-Date -format "yyyyMMdd-HH.mm"
$outfile = "D:\sjoerd\$timestamp-$basehost-networkinfo.txt"
$timestamp | Out-File $outfile
# Original command:
# Get-VMHostNetwork $BASEHost | Select HostName,Domain,ConsoleGateWay,DnsAddress
Add-Content $outfile "`nFinding VMkernel and Service Console information on $BASEHost" -Encoding unicode
Get-VMHostNetwork $BASEHost | Format-List | Out-File $outfile -width 500 -append
# Original command:
# Get-VMHostNetworkAdapter $BASEHost | select VMhost, Name, IP, SubnetMask, Mac, PortGroupName, vMotionEnabled, mtu, FullDuplex, BitRatePerSec
# Get-VMHostNetworkAdapter $BASEHost | select VMhost, Name, IP, SubnetMask, Mac, PortGroupName, vMotionEnabled, mtu, FullDuplex, BitRatePerSec | Export-Csv $csvfilenic
Add-Content $outfile "`nListing all NIC information on $BASEHost" -Encoding unicode
Get-VMHostNetworkAdapter $BASEHost | select VMhost, Name, IP, SubnetMask, Mac, PortGroupName, vMotionEnabled, mtu, FullDuplex, DHCPEnabled, BitRatePerSec | Out-File $outfile -width 500 -append
Get-VirtualSwitch $BASEHost |Foreach {
$switch = $_.Name
$numports = $_.NumPorts
$mtu = $_.Mtu
Add-Content $outfile "`nSwitch $switch on $BASEHost has $numports number of ports and has a configured mtu size of $mtu" -Encoding unicode
$_ |Get-VirtualPortGroup |Foreach {
$portgroup = $_.Name
$vlan = $_.VlanID
Add-Content $outfile "`nPortgroup $portgroup has vlanid $vlan" -Encoding unicode
}
}
//This wiki has been made possible by://