|
| 1 | +function Find-VNVMWithDuplicateMACAddress { |
| 2 | +<# .Description |
| 3 | + Get information about the VM(s) that have a network adapter whose MAC address is a duplicate of another network adapter in the vCenter(s) to which this PowerCLI session is connected |
| 4 | +
|
| 5 | + .Synopsis |
| 6 | + Get information about duplicate MAC addresses |
| 7 | +
|
| 8 | + .Example |
| 9 | + Find-VNVMWithDuplicateMACAddress |
| 10 | + VMName DuplicatedMAC MoRef Count |
| 11 | + ------ ------------- ----- ----- |
| 12 | + {myVM03, oldVM322} 00:50:56:3F:FF:FF {VirtualMachine-vm-16277, VirtualMachine-vm-109} 2 |
| 13 | +
|
| 14 | + Find VMs with network adapters whose MAC address is the same, and return a bit of info about them |
| 15 | +
|
| 16 | + .Example |
| 17 | + Find-VNVMWithDuplicateMACAddress |
| 18 | + VMName DuplicatedMAC MoRef Count |
| 19 | + ------ ------------- ----- ----- |
| 20 | + myVM21 00:50:56:00:00:09 VirtualMachine-vm-16277 2 |
| 21 | +
|
| 22 | + Find VM (just one, apparently, in this vCenter) with network adapters whose MAC address is the same -- in this case, the VM has at least two network adapters, both of which have the same MAC address |
| 23 | +
|
| 24 | + .Link |
| 25 | + http://vNugglets.com |
| 26 | +
|
| 27 | + .Outputs |
| 28 | + System.Management.Automation.PSCustomObject |
| 29 | +#> |
| 30 | + [CmdletBinding()] |
| 31 | + [OutputType([System.Management.Automation.PSCustomObject])] |
| 32 | + Param () ## end param |
| 33 | + |
| 34 | + process { |
| 35 | + ## get VirtualMachine .NET views where the items is not marked as a Template |
| 36 | + $colDevMacAddrInfo = ` |
| 37 | + Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device -Filter @{"Config.Template" = "False"} | Foreach-Object { |
| 38 | + $viewThisVM = $_ |
| 39 | + $_.Config.Hardware.Device | Where-Object {$_ -is [VMware.Vim.VirtualEthernetCard]} | Foreach-Object { |
| 40 | + New-Object -Type PSObject -Property @{VMName = $viewThisVM.Name; MacAddr = $_.MacAddress; MoRef = $viewThisVM.MoRef} |
| 41 | + } ## end foreach-object |
| 42 | + } ## end foreach-object |
| 43 | + |
| 44 | + ## get the non-unique MAC addresses (if any), |
| 45 | + $arrDuplicatedMAC_GroupInfo = $colDevMacAddrInfo | Group-Object MacAddr | Where-Object {$_.count -gt 1} |
| 46 | + |
| 47 | + ## for each duplicated MAC, return an object with the given properties |
| 48 | + if ($null -ne $arrDuplicatedMAC_GroupInfo) { |
| 49 | + $arrDuplicatedMAC_GroupInfo | Foreach-Object { |
| 50 | + New-Object -Type PSObject -Property ([ordered]@{ |
| 51 | + VMName = $_.Group | Foreach-Object {$_.VMName} | Select-Object -Unique |
| 52 | + DuplicatedMAC = $_.Name |
| 53 | + MoRef = $_.Group | Foreach-Object {$_.MoRef} | Select-Object -Unique |
| 54 | + Count = $_.Count |
| 55 | + }) ## end new-object |
| 56 | + } ## end foreach-object |
| 57 | + } ## end if |
| 58 | + else {Write-Verbose "no duplicate MAC addresses found on non-template VMs"} |
| 59 | + } ## end process |
| 60 | +} ## end function |
| 61 | + |
| 62 | + |
| 63 | + |
1 | 64 | function Get-VNNetworkClusterInfo { |
2 | 65 | <# .Description |
3 | 66 | Get information about the VMware HA Cluster(s) in which the given virtual network (virtual portgroup) is defined. May 2015 |
|
0 commit comments