Report your CDP Neighbours
Let’s build a HTML-Report about the CDP Neighbours of your ESXi Hosts.
It looks like this:
You can see your VMhost, VMNic, etc. in a HTML Output
# Creator Christoph Hochsticher 04.09.2015 # 13.05.2016 Changed to function ############################################################ # Creates a HTML Output with CDP informations of your hosts# ############################################################ # Load VMware Snapin Add-PSSnapin VMware.VimAutomation.Core #Connect vCenter Server Connect-VIServer -server yourvcenter -User [email protected] -password yourpassword #Define Var $path = 'L:HTML-ReportsCDP-InfoCSVCDP-Info-' + (Get-Date -Format yyyy-MM-dd) + '.csv' $htmlfile = 'L:HTML-ReportsCDP-Infoolder-reportsCDP-Info-' + (Get-Date -Format yyyy-MM-dd) + '.html' $htmlfile2 = 'L:HTML-ReportsCDP-InfoCDP-Info-latest' + '.html' $date = Get-Date $logo = '<img src="http://your-logo.svg" alt="" align="right">' #html custom $custom = '<style> BODY{background-color:#A4D7D2;} TABLE{border-width:1px; border-style:solid; border-color:black; border-collapse:collapse;} TH{border-width:1px; padding:0px; border-style:solid; border-color:black;} TD{border-width:1px; padding:0px; border-style:solid; border-color:black;} </style>' #function get-cdp info function Get-Cdpinfo { <# .SYNOPSIS Short Description .DESCRIPTION Detailed Description .EXAMPLE Get-cdpinfo esxhost Get-cdpinfo * explains how to use the command can be multiple lines .EXAMPLE Get-cdpinfo another example can have as many examples as you like #> param ( [Parameter(Mandatory=$true)] $VMHost ) $vmh = Get-VMHost $VMHost Get-View $vmh.ID | ` % { $esxname = $_.Name; Get-View $_.ConfigManager.NetworkSystem} | ` % { foreach ($physnic in $_.NetworkInfo.Pnic) { $pnicInfo = $_.QueryNetworkHint($physnic.Device) foreach( $hint in $pnicInfo ){ # Write-Host $esxname $physnic.Device if ( $hint.ConnectedSwitchPort ) { $hint.ConnectedSwitchPort | Select-Object @{n='VMHost';e={$esxname}},@{n='VMNic';e={$physnic.Device}},DevId,Address,PortId,HardwarePlatform,Location,MgmtAddr,SoftwareVersion,SystemName } else { } } } } } $tmp = (Get-Cdpinfo -vmhost *) #Export to CSV & HTML $tmp | export-csv $path $tmp | sort-object 'VMHost' | ConvertTo-Html -Title 'CDP-Info' -Body "<H2> CDP-Info $logo </H2> <br> <H3>Reporting Date :$date </H3> $custom " |Out-File $htmlfile #Copy for Archive Copy-Item $htmlfile $htmlfile2 Disconnect-VIServer * -Confirm:$false