I adapted it to suit my needs:
$Hosts = Get-VMHost | sort -property Name
foreach ($vhost in $Hosts){
$vmh = Get-VMHost -Name $vhost
If ($vmh.State -ne "Connected") {
Write-Output "Host $($vmh) state is not connected, skipping."
}
Else {
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 @{n="VMHost";e={$esxname}},@{n="VMNic";e={$physnic.Device}},DevId,PortId
}
}
}
}
}
}
.\VMHostCDPInfo.ps1 | Format-Table -AutoSize |Out-File cdpinfo.txt
It ignores all nics where it cannot retrieve any CDP info from, but other than that, you get a nice list, which you can put with your documentation which looks like:
VMHost VMNic DevId PortId ------ ----- ----- ------ server01 vmnic0 switch01 GigabitEthernet1/25 server01 vmnic10 switch02 GigabitEthernet2/0/31
Thank you for your valuable content , Easy to understand and follow. As said, the migration to cloud is very essential for the protection of the database.
ReplyDeleteCloud Migration services
Aws Cloud Migration services
Azure Cloud Migration services
Vmware Cloud Migration services
Database Migration services
Cloud Migration Tool
Best Cloud Migration Tool
Lia Infraservices