Skip to content

Commit 2b12097

Browse files
committed
Merge branch 'dev'
2 parents 1de2df0 + 33e5228 commit 2b12097

7 files changed

+93
-17
lines changed

ChangeLog.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
### ChangeLog for vNugglets.Utility PowerShell module
22

3+
#### v1.1, released 20 Dec 2016
4+
5+
- \[new] added function `Find-VNVMWithDuplicateMACAddress` for finding duplicate VM NIC MAC address in vCenter
6+
- \[improvement] updated function `Get-VNVMEVCInfo` to take Cluster object from pipeline, and to take VM object instead of VMId (far better usability)
7+
38
#### v1.0, released 05 Dec 2016
49

510
- created module from many of the juicy snippets/functions that we shared at [vNugglets.com](http://vNugglets.com) over the years

ToDo.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
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)
14+
- ?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`

done.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
\[feat_UpdateCmdlets]:
2+
3+
- added function `Find-VNVMWithDuplicateMACAddress` for finding duplicate VM NIC MAC address in vCenter
4+
- updated function `Get-VNVMEVCInfo` to take Cluster object from pipeline, and to take VM object instead of VMId (far better usability)
5+
6+
17
\[feat_InitialModuleCreation]
8+
29
- function-ize the snippets on vNugglets, improving them as suitable
310
- improved:
411
- `Get-VNVMHostBrokenUplink` -- added more properties to returned object for more easily relating the given vmnic to the VMHost and vSwitch of which it is a part

makeModule.ps1

+1-1
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

+3-3
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

+1-1
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

+74-11
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
@@ -377,9 +440,9 @@ function Get-VNVMByVirtualPortGroup {
377440

378441
function Get-VNVMEVCInfo {
379442
<# .Description
380-
Code to get VMs' EVC mode and that of the cluster in which the VMs reside. May 2014, Matt Boren
443+
Function to get VMs' EVC mode and that of the cluster in which the VMs reside
381444
.Example
382-
Get-VNVMEVCInfo -Cluster myCluster | ?{$_.VMEVCMode -ne $_.ClusterEVCMode}
445+
Get-Cluster myCluster | Get-VNVMEVCInfo | ?{$_.VMEVCMode -ne $_.ClusterEVCMode}
383446
Name PowerState VMEVCMode ClusterEVCMode ClusterName
384447
---- ---------- --------- -------------- -----------
385448
myvm001 poweredOff intel-nehalem myCluster0
@@ -388,20 +451,20 @@ function Get-VNVMEVCInfo {
388451
Get all VMs in given clusters where the VM's EVC mode does not match the Cluster's EVC mode
389452
390453
.Example
391-
Get-VM myVM | Get-VNVMEVCInfo
392-
Get the EVC info for the given VM and the cluster in which it resides
454+
Get-VM myVM0,myVM1 | Get-VNVMEVCInfo
455+
Get the EVC info for the given VMs and the cluster in which they reside
393456
394457
.Outputs
395458
System.Management.Automation.PSCustomObject
396459
#>
397460
[CmdletBinding(DefaultParameterSetName="ByCluster")]
398461
[OutputType([System.Management.Automation.PSCustomObject])]
399462
param(
400-
## Cluster name pattern (regex) to use for getting the clusters whose VMs to get
401-
[parameter(ParameterSetName="ByCluster",Position=0)][string]$Cluster = ".+",
463+
## Cluster whose VMs about which to get EVC information
464+
[parameter(ValueFromPipeline=$true,ParameterSetName="ByCluster",Position=0)][VMware.VimAutomation.Types.Cluster[]]$Cluster,
402465

403-
## Id/MoRef of VM for which to get EVC info
404-
[parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName="ByVMId",Position=0)][Alias("Id","MoRef")][string[]]$VMId
466+
## VM for which to get EVC info
467+
[parameter(ValueFromPipeline=$true,ParameterSetName="ByVM",Position=0)][VMware.VimAutomation.Types.VirtualMachine[]]$VM
405468
) ## end param
406469

407470
begin {
@@ -426,16 +489,16 @@ function Get-VNVMEVCInfo {
426489

427490
Switch ($PSCmdlet.ParameterSetName) {
428491
"ByCluster" {
429-
Get-View -ViewType ClusterComputeResource -Property Name,Summary -Filter @{"Name" = $Cluster} | Foreach-Object {
492+
Get-View -Property Name,Summary -Id $Cluster.Id | Foreach-Object {
430493
$viewThisCluster = $_
431494
Get-View -ViewType VirtualMachine @hshParamForGetVMView -SearchRoot $viewThisCluster.MoRef | Foreach-Object {
432495
_New-InfoObj -VMView $_ -ClusterEVCModeKey $viewThisCluster.Summary.CurrentEVCModeKey -ClusterName $viewThisCluster.Name
433496
} ## end foreach-object
434497
} ## end foreach-object
435498
break
436499
} ## end case
437-
"ByVMId" {
438-
Get-View @hshParamForGetVMView -Id $VMId | Foreach-Object {
500+
"ByVM" {
501+
Get-View @hshParamForGetVMView -Id $VM.Id | Foreach-Object {
439502
## update the View data to get the cluster name and the cluster summary (which has the cluster's EVCMode)
440503
$_.UpdateViewData("Runtime.Host.Parent.Name")
441504
$_.Runtime.LinkedView.Host.LinkedView.Parent.UpdateViewData("Summary")

0 commit comments

Comments
 (0)