If I wanted to add the Cluster Name for each vm to this report how would I go about doing that? Thanks for any input.
I think I might have figured it out, please tell me if this looks correct?
$report = @()
$allvms = Get-VM
foreach ($vm in $allvms) {
$dstores = $vm | Get-Datastore
foreach($ds in $dstores){
$cluster = $vm | Get-Cluster
foreach ($clus in $cluster){
$row = "" | select VMNAME, DATASTORE, CLUSTER
$row.VMNAME = $vm.name
$row.DATASTORE = $ds.Name
$row.CLUSTER = $clus.name
$report += $row
}
}
}
$report | Export-Csv "C:\vm_ds.csv" -NoTypeInformation