Skip to content

Instantly share code, notes, and snippets.

@kapb14
Created December 18, 2021 20:31
Show Gist options
  • Save kapb14/73a48cf751517c3602e096e40a7a3877 to your computer and use it in GitHub Desktop.
Save kapb14/73a48cf751517c3602e096e40a7a3877 to your computer and use it in GitHub Desktop.
Get information about vSphere host physical ports CDP
$cdpVar = ForEach ($dstHost in $(Get-VMHost))
{
$NetSystem = Get-View $dstHost.ExtensionData.ConfigManager.NetworkSystem
foreach ($Pnic in $dstHost.ExtensionData.Config.Network.Pnic)
{
if ($Pnic.Device -notlike "vusb*")
{
$PnicInfo = $NetSystem.QueryNetworkHint($Pnic.Device)
$cdp = $PnicInfo.ConnectedSwitchPort
[pscustomobject]@{
server = $dstHost.Name
serverPort = $Pnic.Device
cdpDevice = $cdp.DevId
cdpDevicePort = $cdp.PortId
}
}
}
}
# $cdpVar
$cdpVar | Export-Excel -Path C:\temp\vs5vmvlans.xlsx `
-Title "какой сервер каким портом в какую циску воткнут" `
-TableName "CiscoPorts" `
-WorksheetName "CiscoPorts" `
-AutoSize `
-Show `
-Append
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment