New-VIProperty and Get-Stat with Clusters

I have a function that I used to collect the Min, Max, Avg for CPU and memory.  The service collects data from last month and returns a single value for each item.  After reading the New VIProperty, I thought I would try to adapt the function in the properties of the Cluster. I got the property works except that it returns an array of values instead of a single value.  I would like help to refine the 1st property and then I can create others.  I'll fix the work function and non-functional property.


Work function


Function Min_Max_Avg ($E, $C, $S) {
Get-Stat -Entity $E -Stat $C -Start $S |
Group-object -Property {$_. @entity.name} | %{
$stats = $_. Group | Measure-object -property Value -way -up -Minimum
}
$Avg = [math]::round(($stats. (On average), 0)
$Min = [math]::round(($stats. (Minimum), 0)
$Max = [math]::round(($stats. (Maximum) 0)

Return $Avg,$Min,$Max }





Work not property


# MemoryMinUsageMonth - MB
New-VIProperty -Name MemoryMinUsageMonth -ObjectType Cluster - value}
param ($cluster)
$start = (Get-Date). AddMonths (-1)
Get-Stat -Entity $cluster -Stat mem.usage.average -Start $start
Group-object -Property {$cluster.} @entity.name} | %{
$stats = $cluster. Group | Measure-object -property Value -Minimum
}
$Min = [math]::round(($stats. (Minimum), 0)
$Min
}



As far as I know, the New VIProperty you set is called individually for each cluster.

There is no need to use the group object.

Can maybe try you it like that

#MemoryMinUsageMonth - MB
New-VIProperty-name MemoryMinUsageMonth - ObjectType Cluster - value {}
Param ($cluster)
Get-Stat - entity $cluster - Stat mem.usage.average - Start (Get-Date). AddMonths(-1) |
Measure-object-property - Minimum value.

Select - ExpandProperty Minimum
}

Tags: VMware

Similar Questions

Maybe you are looking for