It is pretty straightforward, but is handy for identifying those VMs that are, say, at a different EVC mode than is configured on the cluster. So, the code:
function Get-VMEVCMode { <# .Description Code to get VMs' EVC mode and that of the cluster in which the VMs reside. May 2014, vNugglets.com .Example Get-VMEVCMode -Cluster myCluster | ?{$_.VMEVCMode -ne $_.ClusterEVCMode} Get all VMs in given clusters and return, for each, an object with the VM's- and its cluster's EVC mode, if any .Outputs PSCustomObject #> param( ## Cluster name pattern (regex) to use for getting the clusters whose VMs to get [string]$Cluster_str = ".+" ) process { ## get the matching cluster View objects Get-View -ViewType ClusterComputeResource -Property Name,Summary -Filter @{"Name" = $Cluster_str} | Foreach-Object { $viewThisCluster = $_ ## get the VMs Views in this cluster Get-View -ViewType VirtualMachine -Property Name,Runtime.PowerState,Summary.Runtime.MinRequiredEVCModeKey -SearchRoot $viewThisCluster.MoRef | Foreach-Object { ## create new PSObject with some nice info New-Object -Type PSObject -Property ([ordered]@{ Name = $_.Name PowerState = $_.Runtime.PowerState VMEVCMode = $_.Summary.Runtime.MinRequiredEVCModeKey ClusterEVCMode = $viewThisCluster.Summary.CurrentEVCModeKey ClusterName = $viewThisCluster.Name }) } ## end foreach-object } ## end foreach-object } ## end process } ## end function
And, some examples: Get EVC mode info for all of the VMs in this cluster:
PS vN:\> Get-VMEVCMode -Cluster myCluster Name PowerState VMEVCMode ClusterEVCMode ClusterName ---- ---------- --------- -------------- ----------- somesvr01.dom.com poweredOn intel-westmere intel-westmere OurCluster somesvrlm1.dom.com poweredOn intel-penryn intel-westmere OurCluster somesvrbs03.dom.com poweredOff intel-westmere OurCluster somesvrxp.dom.com poweredOn intel-penryn intel-westmere OurCluster ...
For all of the VMs in this cluster where their EVC mode does not match the config'd cluster EVC mode, return their info:
PS vN:\> Get-VMEVCMode -Cluster myCluster | ?{($_.VMEVCMode -ne $_.ClusterEVCMode) -and ($_.PowerState -eq "poweredOn")} Name PowerState VMEVCMode ClusterEVCMode ClusterName ---- ---------- --------- -------------- ----------- somesvrlm1.dom.com poweredOn intel-penryn intel-westmere OurCluster somesvrp83.dom.com poweredOn intel-penryn intel-westmere OurCluster somesvra.dom.com poweredOn intel-merom intel-westmere OurCluster ...
Note: The function does expect that you are using at least PowerShell v3, which surely everyone is well beyond by now, anyway. But, if not, the "[ordered]" cast should be the only thing one would need to take out in order to use in older PowerShell versions.
Straightforward, and uses everyone's favorite PowerCLI cmdlet, Get-View, so you know that it is FaF! Enjoy.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.