In below code :-
If i need to add memory & then consolidate both cpu & memory into xls how can i modify this script ?
$start = (Get-Date).Adddays(-1)
$clusters = Get-Cluster |Select -Last 1
Get-Stat -Entity $clusters -Start $start -Stat cpu.usage.average |
Group-Object -Property {$_.Entity.Name} | %{
$calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum
New-Object PSObject -Property @{
Name = $_.Name
Start = $start
CpuAvg = $calc.Average
CpuMin = $calc.Minimum
CpuMax = $calc.Maximum
}
}
That should have said $clusters (I corrected the code above)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I got this working when i select single cluster
$start = (Get-Date).Adddays(-1)
#$clusters = Get-Cluster -location xx
$clusters = Get-Cluster cluster1
foreach ($cluster in $clusters)
{
Get-Stat -Entity $cluster -Start $start -Stat Mem.Usage.Average |`
Group-Object -Property {$_.Entity.Name} | %{
$calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum
New-Object PSObject -Property @{
Name = $_.Name
StatsForLast7DaysFrom = $start
MemoryAvg = $calc.Average
MemoryMin = $calc.Minimum
MemoryMax = $calc.Maximum
}
} |export-csv c:\clutser1.csv
}
But when i do
$start = (Get-Date).Adddays(-1)
$clusters = Get-Cluster -location xx
#$clusters = Get-Cluster cluster1
foreach ($cluster in $clusters)
{
Get-Stat -Entity $cluster -Start $start -Stat Mem.Usage.Average |`
Group-Object -Property {$_.Entity.Name} | %{
$calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum
New-Object PSObject -Property @{
Name = $_.Name
StatsForLast7DaysFrom = $start
MemoryAvg = $calc.Average
MemoryMin = $calc.Minimum
MemoryMax = $calc.Maximum
}
} |export-csv c:\clutserX.csv
}
The xls is empty ..
can someone Please take a look
Also the values return in above code are % of memory use looks, correct.
You are overwriting the same CSV file for each cluster.
But there is no need to have a loop over all the clusters, try like this
$start = (Get-Date).Adddays(-1)
$clusters = Get-Cluster -location xx
Get-Stat -Entity $clusters -Start $start -Stat Mem.Usage.Average |
Group-Object -Property {$_.Entity.Name} | %{
$calc = $_.Group | Measure-Object -Property Value -Average -Minimum -Maximum
New-Object PSObject -Property @{
Name = $_.Name
StatsForLast7DaysFrom = $start
MemoryAvg = $calc.Average
MemoryMin = $calc.Minimum
MemoryMax = $calc.Maximum
}
} |export-csv c:\clutserX.csv
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i got error for this
Get-Stat : 12/1/2014 10:50:21 AM Get-Stat Value cannot be found for the mandatory parameter Entity
At line:1 char:9
+ Get-Stat <<<< -Entity $cluster -Start $start -Stat Mem.Usage.Average |
+ CategoryInfo : NotSpecified: (:) [Get-Stat], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetViStats
I think -Finish is missing
That should have said $clusters (I corrected the code above)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference