Hi All,
My Setup is like Management & vMotion are in Distributed Switch , only iSCSI(Storage) is in Standard Switch.
Can someone help me in getting the IP Address, SubnetMask & Gateway of Standard Switch & Distributed Switch in CSV file.
vCenter IP | ESXi Hostname | Make | Model | Service Tag | ESXi IP | ESXi Subnet Mask | ESXi Gateway | iSCSI IP | ISCSI Subnet Mask | iSCSI Gateway |
I suspect this one might give you most of what you are looking for
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
To be more specific I am looking on Network Label, IP address, subnetmask & gateway of switches configured for ESXi Server.
iSCSI1 IP Address SubnetMask Gateway iSCSI2 IP Address SubnetMask Gateway.
I would need a report as per the configuration. Is there any way that we can get all the details.
So you want to see for each VMKernel that has iSCSI port binding, the IP, subnet and gateway?
Is that correct?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes Lucd, Including ESXi Mangement & vMotion details along with iSCSI
Still confused.
Are you looking for VMKernel adapters that are have a binding with the iSCSI HBA?
Or just VMKernel adapters on your VSS that have a name that starts with iSCSI?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi, Siva,
Please try the below script if it is suitable to your needs:
$MyOutput = @()
foreach($VMHost in (Get-View -ViewType HostSystem)){
$netSys = Get-View $VMHost.ConfigManager.NetworkSystem
$vswTab = @{}
foreach($vsw in $netSys.NetworkInfo.vSwitch){
foreach($pnic in $vsw.Pnic){
$vswTab.Add(($netSys.NetworkInfo.Pnic | where {$_.Key -eq $Pnic}).Device,$vsw.Name)
}
}
foreach ($physnic in $netSys.NetworkInfo.Pnic) {
$pnicInfo = $netSys.QueryNetworkHint($physnic.Device)
foreach($hint in $pnicInfo){
$Report = "" | Select VMHost,vSwitch,vmnic,Status,MAC,Speed,Vlan,PortId,DeviceId,Observed
$Report.VMHost = $VMHost.Name
$Report.vmnic = $physnic.Device
$Report.vSwitch = $vswTab[$physnic.Device]
$Report.DeviceId = $hint.connectedSwitchPort.DevId
$Report.PortId = $hint.connectedSwitchPort.PortId
$Report.Vlan = $hint.connectedSwitchPort.Vlan
$record = 0
Do{
If ($Hint.Device -eq $vmhost.Config.Network.Pnic[$record].Device){
$Report.Speed = $vmhost.Config.Network.Pnic[$record].LinkSpeed.SpeedMb
$Report.MAC = $vmhost.Config.Network.Pnic[$record].Mac
}
$record ++
}
Until ($record -eq ($vmhost.Config.Network.Pnic.Length))
foreach ($obs in $Hint.Subnet){
$Report.Observed += $obs.IpSubnet + " "
}
If (($Report.Speed -ge 1000) -and ($Hint.ConnectedSwitchPort.FullDuplex -eq $true)){
$Report.Status = "OK"
}Else{If (($Report.Speed -gt 0) -and ($Hint.ConnectedSwitchPort.FullDuplex -eq "")){
$Report.Status = "CDP not working"
}ElseIf (($Report.Speed -gt 0) -and ($Hint.ConnectedSwitchPort.FullDuplex -eq $false)){
if ($Status -ne ""){$Status += " / "}
$Report.Status = "Duplex config error"
}ElseIf (($Report.Speed -gt 0) -and ($Report.Speed -lt 1000)){
if ($Report.Status -ne ""){$Report.Status += " / "}
$Report.Status = "Speed config error"
}Else{
$Report.Status = "Link Down"
}
}
$MyOutput += $Report
}
}
$MyOutput | Sort VMHost,vSwitch,vmnic | Export-Csv -Path C:\NetworkAudit.csv -NoTypeInformation
}
Let us know how it goes.
Hi Albert,
Thanks for your script. As per port binding of Management, vMotion & iSCSI, I need a report like below.
ESXi IP | Subnet | Gateway | vMotion IP | Subnet | Gateway | iSCSI1 IP | Subnet | Gateway | iSCSI2 IP | Subnet | Gateway |
192.168.1.20 | 255.255.255.0 | 192.168.1.1 | 192.168.1.21 | 255.255.255.0 | 192.168.1.1 | 192.168.5.10 | 255.255.255.0 | 192.168.5.1 | 192.168.5.11 | 255.255.255.0 | 192.168.5.1 |
You can try the below script which is very specific to your described configuration.The
$report = @()
$hosts = Get-VMHost
foreach ($host_name in $hosts)
{
$gateway = (Get-VMHostNetwork -VMHost $host_name).VMKernelGateway
$hardware = Get-VMHostHardware -VMHost $host_name
$adaps = Get-VMHostNetworkAdapter -VMHost $host_name -VirtualSwitch (Get-VDSwitch) -VMKernel
$iscsiadap = Get-VMHostNetworkAdapter -VMHost $host_name -VirtualSwitch (Get-virtualswitch -Standard) -VMKernel
$row = "" | Select "ESXi Hostname", Make, Model, "Service Tag", "ESXi IP", "vMotion IP", "ISCSI IP", Subnet, Gateway
$row."ESXi Hostname" = $host_name.Name
$row.Make = $hardware.Manufacturer
$row.Model = $hardware.Model
$row."Service Tag" = $hardware.AssetTag
$row."ESXi IP" = $adaps[0].IP
$row."vMotion IP" = $adaps[1].IP
$row."ISCSI IP" = $iscsiadap.IP
$row.Subnet = $adaps[0].SubnetMask
$row.Gateway = $gateway
$report += $row
}
$report | Export-Csv "C:\report.csv"
Hi, thanks for the follow up in this thread, however, it does not work, see the below result:
and some of the error message:
Get-VMHostNetworkAdapter : Cannot validate argument on parameter 'VirtualSwitch'. The argument is null. Provide a valid value for the argument, and then try running the command again.
+ ... tworkAdapter -VMHost $host_name -VirtualSwitch (Get-VDSwitch) -VMKern ...
Is this because I do not have dvSwitch ?
As I have mentioned earlier the script very specific to the environment provided in the question.
Since there is no dvSwitch in your configuration, the script threw an error.
However as you can see in the csv file, all the available network configurations in your en