Hi Vincent,
the script is working fine in my environment, except that I saw that the datastore names were not sorted. I made a new version to correct that.
I have an idea what is going wrong with the Format-Table cmdlet. You get this error if you want to mix two kind of records and pipe them to Format-Table. If you run the script without the Format-Table cmdlet do you see records that have a different format than the others? That might be the problem. If you see them can you give me an example of the different records?
Here is the new version of the script with the datastore names sorted:
Get-Cluster | `
Sort-Object -Property Name | `
ForEach-Object {
$Cluster = $_
$Cluster | `
Get-VMHost | `
Sort-Object -Property Name | `
ForEach-Object {
$VMHost = $_
$Report = "" | `
Select-Object -Property Cluster,VMHost,CPUTotalMHz,MemoryTotalMB,Datastore,CapacityMB
$Report.Cluster = $Cluster.Name
$Report.VMHost = $VMHost.Name
$Report.CPUTotalMHz = $VMHost.CPUTotalMHz
$Report.MemoryTotalMB = $VMHost.MemoryTotalMB
$Report
$VMHost | `
Get-Datastore | `
Sort-Object -Property Name | `
ForEach-Object {
$Datastore = $_
$Report = "" | `
Select-Object -Property Cluster,VMHost,CPUTotalMHz,MemoryTotalMB,Datastore,CapacityMB
$Report.Cluster = $Cluster.Name
$Report.VMHost = $VMHost.Name
$Report.Datastore = $Datastore.Name
$Report.CapacityMB = $Datastore.CapacityMB
$Report
}
}
} | Format-Table -AutoSize
Regards, Robert