Try something like this
$metrics="disk.numberwrite.summation"
$vms=Get-VM-NameMyVM|where {$_.PowerState-eq"PoweredOn"}
$report=Get-Stat-Entity$vms-Stat$metrics-maxsamples1-IntervalSecs20|
Group-Object-PropertyEntityId|Foreach-Object{
$row=New-ObjectPSObject-Property@{
VM=$_.Group[0].Entity.Name
}
$_.Group|Group-Object-PropertyInstance|%{
$row|Add-Member-Name ($_.Group[0].Instance+"_DiskNumberWrite") -Value$_.Group[0].Value-MemberTypeNoteProperty
}
$row
}
$report|Sort-Object-Property {$_|Get-Member|Measure-Object|select-ExpandPropertyCount} -Descending|
Export-Csv"C:\report1.csv"-NoTypeInformation-UseCulture
It will add a property per instance.
At the end it needs to sort descending on the number of properties in a row.
This to avoid a problem with the Export-Csv cmdlet, that takes the first line to determine how many columns there are in the CSV