Skip to content

Commit

Permalink
updated Get-VNVMEVCInfo to take proper vSphere objects as param values
Browse files Browse the repository at this point in the history
  • Loading branch information
mtboren committed Dec 20, 2016
1 parent d02a000 commit 6d7bbf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
22 changes: 11 additions & 11 deletions vNugglets.Utility/vNuggletsUtilityMod_functions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -451,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 @@ -489,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 6d7bbf1

Please sign in to comment.