From 4aa28d8ac178bc65d4f044ccad42f3cb5fff8710 Mon Sep 17 00:00:00 2001 From: MTBoren Date: Mon, 5 Dec 2016 21:52:15 -0500 Subject: [PATCH 1/4] added items to ToDo --- ToDo.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ToDo.md b/ToDo.md index f0a649d..a8e4f2e 100644 --- a/ToDo.md +++ b/ToDo.md @@ -12,3 +12,5 @@ - update function `Copy-VNVIRole` to take SourceVIRole as VIRole object, and to accept it from pipeline - update function `Get-VNVMEVCInfo` to take Cluster object from pipeline - update function `Get-VNUplinkNicForVM` to give more meaningful VDSwitch identification (currently returns something to the effect of `DvsPortset-1` for the VDSwitch name) +- add function for finding duplicate VM NIC MAC address in vCenter +- ?add function for changing VM boot order From d02a000c6a9bb7c6222060215bc0cd4d0e79e659 Mon Sep 17 00:00:00 2001 From: MTBoren Date: Tue, 6 Dec 2016 18:59:59 -0500 Subject: [PATCH 2/4] added fn Find-VNVMWithDuplicateMACAddress --- ToDo.md | 11 +++- makeModule.ps1 | 2 +- vNugglets.Utility/vNugglets.Utility.psd1 | 6 +- vNugglets.Utility/vNuggletsUtilityMod.psm1 | 2 +- .../vNuggletsUtilityMod_functions.ps1 | 63 +++++++++++++++++++ 5 files changed, 77 insertions(+), 7 deletions(-) diff --git a/ToDo.md b/ToDo.md index a8e4f2e..1288599 100644 --- a/ToDo.md +++ b/ToDo.md @@ -10,7 +10,14 @@ - support searching by guest DNS name (also using `VMware.Vim.SearchIndex`, via the `FindAllByDnsName` method) - update function `Get-VNVMByVirtualPortGroup` to take a standard- or distributed virtual portgroup as a parameter (and, from pipeline) - update function `Copy-VNVIRole` to take SourceVIRole as VIRole object, and to accept it from pipeline -- update function `Get-VNVMEVCInfo` to take Cluster object from pipeline - update function `Get-VNUplinkNicForVM` to give more meaningful VDSwitch identification (currently returns something to the effect of `DvsPortset-1` for the VDSwitch name) -- add function for finding duplicate VM NIC MAC address in vCenter - ?add function for changing VM boot order +- investigate using a PropertyCollector to more quickly retrieve VM network adapter MAC addresses for function `Find-VNVMWithDuplicateMACAddress` + +### Doing + +\[feat_UpdateCmdlets]: +- update function `Get-VNVMEVCInfo` to take Cluster object from pipeline + +done: +- added function `Find-VNVMWithDuplicateMACAddress` for finding duplicate VM NIC MAC address in vCenter diff --git a/makeModule.ps1 b/makeModule.ps1 index 2d3eee1..6eba647 100644 --- a/makeModule.ps1 +++ b/makeModule.ps1 @@ -10,7 +10,7 @@ $hshModManifestParams = @{ #DefaultCommandPrefix = "" #FormatsToProcess = "SomeModule.format.ps1xml" ModuleToProcess = "vNuggletsUtilityMod.psm1" - ModuleVersion = "1.0.0" + ModuleVersion = "1.1.0" ## 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 NestedModules = @("vNuggletsUtilityMod_functions.ps1", "vNugglets_SupportingFunctions.ps1") PowerShellVersion = [System.Version]"4.0" diff --git a/vNugglets.Utility/vNugglets.Utility.psd1 b/vNugglets.Utility/vNugglets.Utility.psd1 index be718e1..e2f25ce 100644 --- a/vNugglets.Utility/vNugglets.Utility.psd1 +++ b/vNugglets.Utility/vNugglets.Utility.psd1 @@ -3,7 +3,7 @@ # # Generated by: Matt Boren # -# Generated on: 12/2/2016 +# Generated on: 12/6/2016 # @{ @@ -12,10 +12,10 @@ RootModule = 'vNuggletsUtilityMod.psm1' # Version number of this module. -ModuleVersion = '1.0.0' +ModuleVersion = '1.1.0' # ID used to uniquely identify this module -GUID = 'c07f8992-e2c1-42d5-a7a3-49dbd2cdfd20' +GUID = 'a22ca8fe-3739-463f-b8dd-4d5d2c9ffec4' # Author of this module Author = 'Matt Boren' diff --git a/vNugglets.Utility/vNuggletsUtilityMod.psm1 b/vNugglets.Utility/vNuggletsUtilityMod.psm1 index 05c1592..3bd7b7d 100644 --- a/vNugglets.Utility/vNuggletsUtilityMod.psm1 +++ b/vNugglets.Utility/vNuggletsUtilityMod.psm1 @@ -15,7 +15,7 @@ $arrAliasNamesToExport = $hshNewAliasInfo.GetEnumerator() | Foreach-Object { ## export these items for use by consumer $hshModuleMemberParams = @{ - Function = Write-Output Connect-VNVIServer, Copy-VNVIRole, Disconnect-VNVIServer, + Function = Write-Output Connect-VNVIServer, Copy-VNVIRole, Disconnect-VNVIServer, Find-VNVMWithDuplicateMACAddress, Get-VNNetworkClusterInfo, Get-VNUplinkNicForVM, Get-VNVMByAddress, Get-VNVMByRDM, Get-VNVMByVirtualPortGroup, Get-VNVMDiskAndRDM, Get-VNVMEVCInfo, Get-VNVMHostBrokenUplink, Get-VNVMHostFirmwareInfo, Get-VNVMHostHBAWWN, Get-VNVMHostLogicalVolumeInfo, Get-VNVMHostNICFirmwareAndDriverInfo, Invoke-VNEvacuateDatastore, Move-VNTemplateFromVMHost, Update-VNTitleBarForPowerCLI diff --git a/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 b/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 index 99601f6..fce02e6 100644 --- a/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 +++ b/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 @@ -1,3 +1,66 @@ +function Find-VNVMWithDuplicateMACAddress { +<# .Description + 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 + + .Synopsis + Get information about duplicate MAC addresses + + .Example + Find-VNVMWithDuplicateMACAddress + VMName DuplicatedMAC MoRef Count + ------ ------------- ----- ----- + {myVM03, oldVM322} 00:50:56:3F:FF:FF {VirtualMachine-vm-16277, VirtualMachine-vm-109} 2 + + Find VMs with network adapters whose MAC address is the same, and return a bit of info about them + + .Example + Find-VNVMWithDuplicateMACAddress + VMName DuplicatedMAC MoRef Count + ------ ------------- ----- ----- + myVM21 00:50:56:00:00:09 VirtualMachine-vm-16277 2 + + 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 + + .Link + http://vNugglets.com + + .Outputs + System.Management.Automation.PSCustomObject +#> + [CmdletBinding()] + [OutputType([System.Management.Automation.PSCustomObject])] + Param () ## end param + + process { + ## get VirtualMachine .NET views where the items is not marked as a Template + $colDevMacAddrInfo = ` + Get-View -ViewType VirtualMachine -Property Name,Config.Hardware.Device -Filter @{"Config.Template" = "False"} | Foreach-Object { + $viewThisVM = $_ + $_.Config.Hardware.Device | Where-Object {$_ -is [VMware.Vim.VirtualEthernetCard]} | Foreach-Object { + New-Object -Type PSObject -Property @{VMName = $viewThisVM.Name; MacAddr = $_.MacAddress; MoRef = $viewThisVM.MoRef} + } ## end foreach-object + } ## end foreach-object + + ## get the non-unique MAC addresses (if any), + $arrDuplicatedMAC_GroupInfo = $colDevMacAddrInfo | Group-Object MacAddr | Where-Object {$_.count -gt 1} + + ## for each duplicated MAC, return an object with the given properties + if ($null -ne $arrDuplicatedMAC_GroupInfo) { + $arrDuplicatedMAC_GroupInfo | Foreach-Object { + New-Object -Type PSObject -Property ([ordered]@{ + VMName = $_.Group | Foreach-Object {$_.VMName} | Select-Object -Unique + DuplicatedMAC = $_.Name + MoRef = $_.Group | Foreach-Object {$_.MoRef} | Select-Object -Unique + Count = $_.Count + }) ## end new-object + } ## end foreach-object + } ## end if + else {Write-Verbose "no duplicate MAC addresses found on non-template VMs"} + } ## end process +} ## end function + + + function Get-VNNetworkClusterInfo { <# .Description Get information about the VMware HA Cluster(s) in which the given virtual network (virtual portgroup) is defined. May 2015 From 6d7bbf1f26e576f157cab7006e7e355678104306 Mon Sep 17 00:00:00 2001 From: MTBoren Date: Tue, 20 Dec 2016 18:08:14 -0500 Subject: [PATCH 3/4] updated Get-VNVMEVCInfo to take proper vSphere objects as param values --- ToDo.md | 5 +++-- .../vNuggletsUtilityMod_functions.ps1 | 22 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ToDo.md b/ToDo.md index 1288599..953e383 100644 --- a/ToDo.md +++ b/ToDo.md @@ -16,8 +16,9 @@ ### Doing +done: + \[feat_UpdateCmdlets]: -- update function `Get-VNVMEVCInfo` to take Cluster object from pipeline -done: - added function `Find-VNVMWithDuplicateMACAddress` for finding duplicate VM NIC MAC address in vCenter +- updated function `Get-VNVMEVCInfo` to take Cluster object from pipeline, and to take VM object instead of VMId (far better usability) diff --git a/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 b/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 index fce02e6..97e163b 100644 --- a/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 +++ b/vNugglets.Utility/vNuggletsUtilityMod_functions.ps1 @@ -440,9 +440,9 @@ function Get-VNVMByVirtualPortGroup { function Get-VNVMEVCInfo { <# .Description - Code to get VMs' EVC mode and that of the cluster in which the VMs reside. May 2014, Matt Boren + Function to get VMs' EVC mode and that of the cluster in which the VMs reside .Example - Get-VNVMEVCInfo -Cluster myCluster | ?{$_.VMEVCMode -ne $_.ClusterEVCMode} + Get-Cluster myCluster | Get-VNVMEVCInfo | ?{$_.VMEVCMode -ne $_.ClusterEVCMode} Name PowerState VMEVCMode ClusterEVCMode ClusterName ---- ---------- --------- -------------- ----------- myvm001 poweredOff intel-nehalem myCluster0 @@ -451,8 +451,8 @@ function Get-VNVMEVCInfo { Get all VMs in given clusters where the VM's EVC mode does not match the Cluster's EVC mode .Example - Get-VM myVM | Get-VNVMEVCInfo - Get the EVC info for the given VM and the cluster in which it resides + Get-VM myVM0,myVM1 | Get-VNVMEVCInfo + Get the EVC info for the given VMs and the cluster in which they reside .Outputs System.Management.Automation.PSCustomObject @@ -460,11 +460,11 @@ function Get-VNVMEVCInfo { [CmdletBinding(DefaultParameterSetName="ByCluster")] [OutputType([System.Management.Automation.PSCustomObject])] param( - ## Cluster name pattern (regex) to use for getting the clusters whose VMs to get - [parameter(ParameterSetName="ByCluster",Position=0)][string]$Cluster = ".+", + ## Cluster whose VMs about which to get EVC information + [parameter(ValueFromPipeline=$true,ParameterSetName="ByCluster",Position=0)][VMware.VimAutomation.Types.Cluster[]]$Cluster, - ## Id/MoRef of VM for which to get EVC info - [parameter(ValueFromPipelineByPropertyName=$true,ParameterSetName="ByVMId",Position=0)][Alias("Id","MoRef")][string[]]$VMId + ## VM for which to get EVC info + [parameter(ValueFromPipeline=$true,ParameterSetName="ByVM",Position=0)][VMware.VimAutomation.Types.VirtualMachine[]]$VM ) ## end param begin { @@ -489,7 +489,7 @@ function Get-VNVMEVCInfo { Switch ($PSCmdlet.ParameterSetName) { "ByCluster" { - Get-View -ViewType ClusterComputeResource -Property Name,Summary -Filter @{"Name" = $Cluster} | Foreach-Object { + Get-View -Property Name,Summary -Id $Cluster.Id | Foreach-Object { $viewThisCluster = $_ Get-View -ViewType VirtualMachine @hshParamForGetVMView -SearchRoot $viewThisCluster.MoRef | Foreach-Object { _New-InfoObj -VMView $_ -ClusterEVCModeKey $viewThisCluster.Summary.CurrentEVCModeKey -ClusterName $viewThisCluster.Name @@ -497,8 +497,8 @@ function Get-VNVMEVCInfo { } ## end foreach-object break } ## end case - "ByVMId" { - Get-View @hshParamForGetVMView -Id $VMId | Foreach-Object { + "ByVM" { + Get-View @hshParamForGetVMView -Id $VM.Id | Foreach-Object { ## update the View data to get the cluster name and the cluster summary (which has the cluster's EVCMode) $_.UpdateViewData("Runtime.Host.Parent.Name") $_.Runtime.LinkedView.Host.LinkedView.Parent.UpdateViewData("Summary") From d96bbed3b8e25223123f6af6c5f4650dcfdd4b03 Mon Sep 17 00:00:00 2001 From: MTBoren Date: Tue, 20 Dec 2016 18:13:39 -0500 Subject: [PATCH 4/4] update docs, prep for release --- ChangeLog.md | 5 +++++ ToDo.md | 1 + done.md | 7 +++++++ 3 files changed, 13 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 6dcfd8b..d47453f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,10 @@ ### ChangeLog for vNugglets.Utility PowerShell module +#### v1.1, released 20 Dec 2016 + +- \[new] added function `Find-VNVMWithDuplicateMACAddress` for finding duplicate VM NIC MAC address in vCenter +- \[improvement] updated function `Get-VNVMEVCInfo` to take Cluster object from pipeline, and to take VM object instead of VMId (far better usability) + #### v1.0, released 05 Dec 2016 - created module from many of the juicy snippets/functions that we shared at [vNugglets.com](http://vNugglets.com) over the years diff --git a/ToDo.md b/ToDo.md index a8e4f2e..b66e43c 100644 --- a/ToDo.md +++ b/ToDo.md @@ -14,3 +14,4 @@ - update function `Get-VNUplinkNicForVM` to give more meaningful VDSwitch identification (currently returns something to the effect of `DvsPortset-1` for the VDSwitch name) - add function for finding duplicate VM NIC MAC address in vCenter - ?add function for changing VM boot order +- investigate using a PropertyCollector to more quickly retrieve VM network adapter MAC addresses for function `Find-VNVMWithDuplicateMACAddress` diff --git a/done.md b/done.md index b8d58a9..92be089 100644 --- a/done.md +++ b/done.md @@ -1,4 +1,11 @@ +\[feat_UpdateCmdlets]: + +- added function `Find-VNVMWithDuplicateMACAddress` for finding duplicate VM NIC MAC address in vCenter +- updated function `Get-VNVMEVCInfo` to take Cluster object from pipeline, and to take VM object instead of VMId (far better usability) + + \[feat_InitialModuleCreation] + - function-ize the snippets on vNugglets, improving them as suitable - improved: - `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