Hello,
I'm collecting various statistics from my ESXi Hosts / VMs and output them to .csv. Those files are getting then indexed, so that different live/saved reports can be generated.
All the scripts I found/modified so far are working providing a pretty standard output.
Only those VM Disk Stats are giving me headaches.
To make the example easy, I'll run the script on 1 VM with 1 metric.
This code is working (from LucD)...
$metrics = "disk.numberwrite.summation"
$vms = get-vm -Name MyVM | where {$_.PowerState -eq "PoweredOn"}
Get-Stat -Entity $vms -Stat $metrics -maxsamples 1 -IntervalSecs 20 |
Group-Object -Property EntityId | Foreach-Object{
New-Object PSObject -Property @{
VM = $_.Group[0].Entity.Name
Instance = $_.Group[0].Instance
MetricId = $_.Group[0].MetricId
Value = $_.Group[0].Value
}
} | Select VM,Instance,MetricId,Value |
Export-Csv "C:\report.csv" -NoTypeInformation
... but with an output of instances and values per columns (which is an obstacle, when trying to index the resulted .csv)
Entity Instance MetricId Value
MyVM xyz.12345e8069872a000000963d00008015 disk.numberwrite.summation 7
MyVM xyz.12345e8069872a000000963d00008012 disk.numberwrite.summation 0
Now, I modify the script as followed and....
$metrics = "disk.numberwrite.summation"
$vms = get-vm -Name MyVM| where {$_.PowerState -eq "PoweredOn"}
Get-Stat -Entity $vms -Stat $metrics -maxsamples 1 -IntervalSecs 20 |
Group-Object -Property EntityId | Foreach-Object{
New-Object PSObject -Property @{
VM = $_.Group[0].Entity.Name
Instance1 = $_.Group[0].Instance
Instance2 = $_.Group[1].Instance
DiskNumberWrite1 = $_.Group[0].Value
DiskNumberWrite2 = $_.Group[1].Value
}
} | Select VM,Instance1,Instance2,DiskNumberWrite1,DiskNumberWrite2 |
Export-Csv "C:\report1.csv" -NoTypeInformation
.. I can get the desired output, with instances and values per line with the VM Name as "primary key" so to say:
Entity Instance1 Instance2 DiskNumberWrite1 DiskNumberWrite2
MyVM xyz.12345e8069872a000000963d00008015 xyz.12345e8069872a000000963d00008012 7 0
My question:
The example is fine but in real life, we have VMs with 2 to 10 instances, how can we get and output the Instance[x], Value[x] as variables ?
With twice the word Power in PowerShell und PowerCli, I'm sure it's possible... Any hint would be greatly appreciated.