[Guide] vSphere VM - conflicted PortID

VMs with conflicted PortIDs

In certain scenarios it can happend that the PortID (distributed port group) of a VM shows up with the prefix "-c" (eg c-245). vCenter Server creates a conflict port if multiple virtual machine's point to the same port. It does not automatically reconfigure the virtual machine to connect to a regular port if the conflict remains and the virtual machine stays connected to the conflict port.

See: https://knowledge.broadcom.com/external/article/318950/vnetwork-distributed-switch-contains-dvp.html

This issue ussually happens when the distributed vSwitch is out-of sync. I've seen this mostly on Cisco ACI VMM Setups. I strongly do not recommend a Cisco ACI VMM Integration with vSphere.

Anyway, the issue is there, we need to fix it. The fix is quite easy, disconnect the Network Adapter from the VM, save the VM config, then reconnect again. For this manual process I created some scripts:

PowerCLI Script - Find VMs with conflicted PortIDs

Newest Version here

 1# Load the PowerCLI SnapIn and set the configuration
 2Add-PSSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"
 3Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
 4
 5# Get the vCenter Server address, username and password as PSCredential
 6$vCenterServer = Read-Host "Enter vCenter Server host name (DNS with FQDN or IP address)"
 7$vCenterUser = Read-Host "Enter your user name (DOMAIN\User or [email protected])"
 8$vCenterUserPassword = Read-Host "Enter your password (this will be converted to a secure string)" -AsSecureString:$true
 9$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $vCenterUser,$vCenterUserPassword
10
11# Connect to the vCenter Server with collected credentials
12Connect-VIServer -Server $vCenterServer -Credential $Credentials | Out-Null
13Write-Host "Connected to your vCenter server $vCenterServer" -ForegroundColor Green
14
15Add-PSSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"
16Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
17
18
19
20$vms = Get-VM
21
22
23$vmInfo = @()
24
25foreach ($vm in $vms) {
26   
27    $networkAdapters = Get-NetworkAdapter -VM $vm
28    
29    foreach ($adapter in $networkAdapters) {
30        $portID = $adapter.ExtensionData.Backing.Port.PortKey
31        
32        # Only process if the portID starts with "c-"
33        if ($portID -and $portID.StartsWith("c-")) {
34            # Create a custom object with VM and port information
35            $vmData = [PSCustomObject]@{
36                VMName = $vm.Name
37                PowerState = $vm.PowerState
38                NetworkName = $adapter.NetworkName
39                PortID = $portID
40            }
41            
42            # Add the object to the array
43            $vmInfo += $vmData
44        }
45    }
46}
47
48
49$vmInfo | Export-Csv -Path "C:\source\VMPortInfo.csv" -NoTypeInformation

PowerCLI Script - Find VMs with conflicted PortIDs and fix it

This script then detects VMs with "c-" PortID and does the following:

  • list you all VMs
  • will ask, if it should fix the Issue -> disconnects vNIC, waits 5sec, and reconnects the adapter
  • Option to Ping the VMs afterwards (based on the IPs it reads out from VMware Tools)

Newest Version here

 1# Load the PowerCLI SnapIn and set the configuration
 2Add-PSSnapin VMware.VimAutomation.Core -ea "SilentlyContinue"
 3Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Confirm:$false | Out-Null
 4
 5# Get the vCenter Server address, username and password as PSCredential
 6$vCenterServer = Read-Host "Enter vCenter Server host name (DNS with FQDN or IP address)"
 7$vCenterUser = Read-Host "Enter your user name (DOMAIN\User or [email protected])"
 8$vCenterUserPassword = Read-Host "Enter your password (this will be converted to a secure string)" -AsSecureString:$true
 9$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $vCenterUser,$vCenterUserPassword
10
11# Connect to the vCenter Server with collected credentials
12Connect-VIServer -Server $vCenterServer -Credential $Credentials | Out-Null
13Write-Host "Connected to your vCenter server $vCenterServer" -ForegroundColor Green
14
15
16# Get all VMs with portID starting with "c-"
17$problematicVMs = Get-VM | Get-NetworkAdapter | Where-Object { $_.ExtensionData.Backing.Port.PortKey -like "c-*" } | Select-Object -ExpandProperty Parent -Unique
18
19# Print out the VMs with problematic portIDs
20Write-Host "VMs with portID 'c-':"
21$problematicVMs | ForEach-Object { Write-Host $_.Name }
22
23# Ask for confirmation to fix the issues
24$confirmation = Read-Host "Do you want to fix those issues for the following VMs - resulting in 5sec Network Connectivity loss? (yes/no)"
25
26if ($confirmation -eq "yes") {
27    foreach ($vm in $problematicVMs) {
28        Write-Host "Processing $($vm.Name)..."
29        
30        # Disconnect the network adapter
31        Get-NetworkAdapter -VM $vm | Where-Object { $_.ExtensionData.Backing.Port.PortKey -like "c-*" } | Set-NetworkAdapter -Connected $false -Confirm:$false
32        
33        # Wait for 5 seconds
34        Start-Sleep -Seconds 5
35        
36        # Reconnect the network adapter
37        Get-NetworkAdapter -VM $vm | Where-Object { $_.ExtensionData.Backing.Port.PortKey -like "c-*" } | Set-NetworkAdapter -Connected $true -Confirm:$false
38        
39        Write-Host "Fixed network adapter for $($vm.Name)"
40    }
41    
42    # List all affected VMs
43    Write-Host "Affected VMs:"
44    $problematicVMs | ForEach-Object { Write-Host $_.Name }
45    
46    # Option to read out IP and ping VMs
47    $pingOption = Read-Host "Do you want to read out IPs and ping the affected VMs? (yes/no)"
48    
49    if ($pingOption -eq "yes") {
50        foreach ($vm in $problematicVMs) {
51            $ip = $vm.Guest.IPAddress[0]
52            if ($ip) {
53                Write-Host "$($vm.Name) IP: $ip"
54                $pingResult = Test-Connection -ComputerName $ip -Count 1 -Quiet
55                if ($pingResult) {
56                    Write-Host "Ping successful for $($vm.Name)"
57                } else {
58                    Write-Host "Ping failed for $($vm.Name)"
59                }
60            } else {
61                Write-Host "Unable to retrieve IP for $($vm.Name)"
62            }
63        }
64    }
65} else {
66    Write-Host "Operation cancelled. No changes were made."
67}

Hope this helps fixing the Issue.