Show VM Resources configuration on any cluster

Description :

This is a script PowerCLI script to check all resources on any cluster. 
Information Retrieves are :
VM Name, Resource Pool, VM Resource Configuration (Shares CPU and Memory), Latency Sensitivity

Syntax :

Show-Resources -Cluster String

Examples :

Show-Resources -Cluster MyCluster
Retrieves all resources configuration that reside on the specified cluster.

Show-Resources
Retrieves all resources configuration that reside on all clusters.


Script :

function Show-Resources {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$False,Position=0)]
[array]$Cluster

)#PARAM

if (!$Cluster) {
$AllVM = Get-VM | where {$_.PowerState -eq "PoweredOn"}
}
elseif ($Cluster) {
$AllVM = Get-Cluster -Name $Cluster | Get-VM | where {$_.PowerState -eq "PoweredOn"}
}

foreach ($MyVM in $AllVM) {
$VMName = $MyVM.Name
$ResourcePool = $MyVM.ResourcePool
$VMResourceConfiguration = $MyVM.VMResourceConfiguration

$latencySensitivity = Get-AdvancedSetting -Entity $MyVM | select Name,Value | where {$_.Name -eq "sched.cpu.latencySensitivity"}
$latencySensitivityValue = $latencySensitivity.Value

$Output = New-Object psobject
$Output | Add-Member -MemberType NoteProperty -Name Name -Value $VMName
$Output | Add-Member -MemberType NoteProperty -Name ResourcePoolName -Value $ResourcePool
$Output | Add-Member -MemberType NoteProperty -Name VMResourceConfiguration -Value $VMResourceConfiguration
$Output | Add-Member -MemberType NoteProperty -Name LatencySensitivity -Value $latencySensitivityValue
$Output
}
}