Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mtboren committed Dec 20, 2016
2 parents 1de2df0 + 33e5228 commit 2b12097
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 17 deletions.
5 changes: 5 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +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 changing VM boot order
- investigate using a PropertyCollector to more quickly retrieve VM network adapter MAC addresses for function `Find-VNVMWithDuplicateMACAddress`
7 changes: 7 additions & 0 deletions done.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion makeModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions vNugglets.Utility/vNugglets.Utility.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Matt Boren
#
# Generated on: 12/2/2016
# Generated on: 12/6/2016
#

@{
Expand All @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion vNugglets.Utility/vNuggletsUtilityMod.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 74 additions & 11 deletions vNugglets.Utility/vNuggletsUtilityMod_functions.ps1
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -388,20 +451,20 @@ 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
#>
[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 {
Expand All @@ -426,16 +489,16 @@ 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
} ## end foreach-object
} ## 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")
Expand Down

0 comments on commit 2b12097

Please sign in to comment.