Skip to content

Commit d02a000

Browse files
committed
added fn Find-VNVMWithDuplicateMACAddress
1 parent 4aa28d8 commit d02a000

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

ToDo.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@
1010
- support searching by guest DNS name (also using `VMware.Vim.SearchIndex`, via the `FindAllByDnsName` method)
1111
- update function `Get-VNVMByVirtualPortGroup` to take a standard- or distributed virtual portgroup as a parameter (and, from pipeline)
1212
- update function `Copy-VNVIRole` to take SourceVIRole as VIRole object, and to accept it from pipeline
13-
- update function `Get-VNVMEVCInfo` to take Cluster object from pipeline
1413
- update function `Get-VNUplinkNicForVM` to give more meaningful VDSwitch identification (currently returns something to the effect of `DvsPortset-1` for the VDSwitch name)
15-
- add function for finding duplicate VM NIC MAC address in vCenter
1614
- ?add function for changing VM boot order
15+
- investigate using a PropertyCollector to more quickly retrieve VM network adapter MAC addresses for function `Find-VNVMWithDuplicateMACAddress`
16+
17+
### Doing
18+
19+
\[feat_UpdateCmdlets]:
20+
- update function `Get-VNVMEVCInfo` to take Cluster object from pipeline
21+
22+
done:
23+
- added function `Find-VNVMWithDuplicateMACAddress` for finding duplicate VM NIC MAC address in vCenter

makeModule.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ $hshModManifestParams = @{
1010
#DefaultCommandPrefix = ""
1111
#FormatsToProcess = "SomeModule.format.ps1xml"
1212
ModuleToProcess = "vNuggletsUtilityMod.psm1"
13-
ModuleVersion = "1.0.0"
13+
ModuleVersion = "1.1.0"
1414
## scripts (.ps1) that are listed in the NestedModules key are run in the module's session state, not in the caller's session state. To run a script in the caller's session state, list the script file name in the value of the ScriptsToProcess key in the manifest
1515
NestedModules = @("vNuggletsUtilityMod_functions.ps1", "vNugglets_SupportingFunctions.ps1")
1616
PowerShellVersion = [System.Version]"4.0"

vNugglets.Utility/vNugglets.Utility.psd1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
# Generated by: Matt Boren
55
#
6-
# Generated on: 12/2/2016
6+
# Generated on: 12/6/2016
77
#
88

99
@{
@@ -12,10 +12,10 @@
1212
RootModule = 'vNuggletsUtilityMod.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.0'
15+
ModuleVersion = '1.1.0'
1616

1717
# ID used to uniquely identify this module
18-
GUID = 'c07f8992-e2c1-42d5-a7a3-49dbd2cdfd20'
18+
GUID = 'a22ca8fe-3739-463f-b8dd-4d5d2c9ffec4'
1919

2020
# Author of this module
2121
Author = 'Matt Boren'

vNugglets.Utility/vNuggletsUtilityMod.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $arrAliasNamesToExport = $hshNewAliasInfo.GetEnumerator() | Foreach-Object {
1515

1616
## export these items for use by consumer
1717
$hshModuleMemberParams = @{
18-
Function = Write-Output Connect-VNVIServer, Copy-VNVIRole, Disconnect-VNVIServer,
18+
Function = Write-Output Connect-VNVIServer, Copy-VNVIRole, Disconnect-VNVIServer, Find-VNVMWithDuplicateMACAddress,
1919
Get-VNNetworkClusterInfo, Get-VNUplinkNicForVM, Get-VNVMByAddress, Get-VNVMByRDM, Get-VNVMByVirtualPortGroup, Get-VNVMDiskAndRDM, Get-VNVMEVCInfo,
2020
Get-VNVMHostBrokenUplink, Get-VNVMHostFirmwareInfo, Get-VNVMHostHBAWWN, Get-VNVMHostLogicalVolumeInfo, Get-VNVMHostNICFirmwareAndDriverInfo,
2121
Invoke-VNEvacuateDatastore, Move-VNTemplateFromVMHost, Update-VNTitleBarForPowerCLI

vNugglets.Utility/vNuggletsUtilityMod_functions.ps1

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,66 @@
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+
164
function Get-VNNetworkClusterInfo {
265
<# .Description
366
Get information about the VMware HA Cluster(s) in which the given virtual network (virtual portgroup) is defined. May 2015

0 commit comments

Comments
 (0)