diff --git a/ToDo.md b/ToDo.md index b66e43c..95e0626 100644 --- a/ToDo.md +++ b/ToDo.md @@ -10,8 +10,6 @@ - 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` 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..97e163b 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 @@ -377,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 @@ -388,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 @@ -397,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 { @@ -426,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 @@ -434,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")