Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all articles
Browse latest Browse all 9071

Report VMHost, VMNIC, DVS and CDP info

$
0
0

Hello,

 

I tried to create a Report wir these Information:

Clustername, Hostname, VMNIC, PCI, DVS, CDP_Port, CDP_Device, CDP_Address  

 

Thats the actual script with a modified version of LucD `s Get-CDP Function:   $obj.

 

function Get-CDPDetails {<#    .DESCRIPTION    .Example    .PARAMETER




#Requires PS -Version 4.0
#Requires -Modules VMware.VimAutomation.Core, @{ModuleName="VMware.VimAutomation.Core";ModuleVersion="6.3.0.0"}
#>


[CmdletBinding()]
param(
    [Parameter(Mandatory=$True, ValueFromPipeline=$False, Position=0)]        [String] $Clustername
)


Begin {
    $Validate = $True    if (($myCluster = Get-Cluster -Name $Clustername).count -lt 1) {       $Validate = $False       thow "No Cluster '$myCluster' found"    }    function Get-CDP ($VMhost, $VMhostDVS, $VMhostDC){        $objReport = @()        $VMhost| %{Get-View $_.ID} |        %{$esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} |        %{ foreach($physnic in $_.NetworkInfo.Pnic){                $obj = "" | Select-Object Clustername,Hostname,VMNIC,PCI,DVS,CDP_Port,CDP_Device,CDP_Address                  $pnicInfo = $_.QueryNetworkHint($physnic.Device)            foreach($hint in $pnicInfo){              $obj.Clustername = $VMhost.parent.name              $obj.Hostname = $esxname              $obj.VMNIC = $physnic.Device              $obj.PCI = $physnic.PCI              $obj.DVS = ($VMhostDVS | where {$_.ExtensionData.Config.Host.Config.Host -eq $VMhost.ExtensionData.MoRef -and $_.Datacenter.name -eq $VMhostDC.name -and $_.ExtensionData.Config.Host.Config.Backing.PnicSpec.PnicDevice -eq $physnic.Device}).name              if( $hint.ConnectedSwitchPort ) {                $obj.CDP_Port = $hint.ConnectedSwitchPort.PortId              } else {                $obj.CDP_Port = "No CDP information available."              }              $obj.CDP_Device = $hint.ConnectedSwitchPort.DevId              $obj.CDP_Address = $hint.ConnectedSwitchPort.Address             }            $objReport += $obj          }        }        $objReport    } 
}


Process {


    $MyView = @()    if ($Validate -eq $True) {         foreach ($myHost in ($myCluster | Get-VMHost)) {        $mydvs = $myhost | Get-VirtualSwitch -Distributed        $mydc = $myhost | Get-Datacenter        $CDP = Get-CDP $myHost $mydvs $mydc        $MyView += $CDP         }               $MyView | Sort Clustername, Hostname, VMNIC    }    }
}

 

The Report itself works except one limitation: If you have a large Environment with duplicate ESXi Host MoRef IDs the DVS Field has multiple values.

get-cdpdetails.png

The Issue is by Design because I filter on the MoRef in the DVS Object...

 

Any suggestions how to filter more efficient or maybe start completely different?

 

Kind Regards,

Markus


Viewing all articles
Browse latest Browse all 9071

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>