Automation

 View Only
Expand all | Collapse all

Observed IP Ranges collected with Powershell and VIToolKit?

  • 1.  Observed IP Ranges collected with Powershell and VIToolKit?

    Posted Mar 16, 2009 08:28 PM

    In Virtual Center when looking at any esx host

    configuration -> network adapters

    There is a field that displays the vlans that each physical nic is aware of, Observed IP Ranges.

    I want to grab this information for each host in a data center with a powershell script.

    im not sure how to return that field or if its even possible with the comlets in vitoolkit

    i tried get-vmhost | get-view | select network

    this does not display helpful info

    is there some other cmdlet other than get-vmhost that might work?



  • 2.  RE: Observed IP Ranges collected with Powershell and VIToolKit?
    Best Answer

    Posted Mar 16, 2009 08:37 PM

    Have a look at .



  • 3.  RE: Observed IP Ranges collected with Powershell and VIToolKit?

    Posted Mar 17, 2009 11:47 AM

    Similiar to LucD

    $vmhosts = Get-VMHost | Sort Name | Where-Object {$_.State -eq "Connected"} | Get-View
    $MyCol = @()
    foreach ($vmhost in $vmhosts){
     $ESXHost = $vmhost.Name
     Write "Collating information for $ESXHost"
     $networkSystem = Get-view $vmhost.ConfigManager.NetworkSystem
     foreach($pnic in $networkSystem.NetworkConfig.Pnic){
         $pnicInfo = $networkSystem.QueryNetworkHint($pnic.Device)
         foreach($Hint in $pnicInfo){
             $NetworkInfo = "" | select-Object Host, PNic, Speed, MAC, DeviceID, PortID, Observed, VLAN
             $NetworkInfo.Host = $vmhost.Name
             $NetworkInfo.PNic = $Hint.Device
             $NetworkInfo.DeviceID = $Hint.connectedSwitchPort.DevId
             $NetworkInfo.PortID = $Hint.connectedSwitchPort.PortId
             $record = 0
             Do{
                 If ($Hint.Device -eq $vmhost.Config.Network.Pnic[$record].Device){
                     $NetworkInfo.Speed = $vmhost.Config.Network.Pnic[$record].LinkSpeed.SpeedMb
                     $NetworkInfo.MAC = $vmhost.Config.Network.Pnic[$record].Mac
                 }
                 $record ++
             }
             Until ($record -eq ($vmhost.Config.Network.Pnic.Length))
             foreach ($obs in $Hint.Subnet){
                 $NetworkInfo.Observed += $obs.IpSubnet + " "
                 Foreach ($VLAN in $obs.VlanId){
                     If ($VLAN -eq $null){
                     }
                     Else{
                         $strVLAN = $VLAN.ToString()
                         $NetworkInfo.VLAN += $strVLAN + " "
                     }
                 }
             }
             $MyCol += $NetworkInfo
         }
     }
    }
    $Mycol | Sort Host, PNic
    

    http://www.vmwarescripting.com



  • 4.  RE: Observed IP Ranges collected with Powershell and VIToolKit?

    Posted Mar 17, 2009 05:24 PM

    thank you this is exactly what i was looking for



  • 5.  RE: Observed IP Ranges collected with Powershell and VIToolKit?

    Posted Mar 17, 2009 06:50 PM