What exactly does the error say? That line with Get-View is not needed. You can get those values also from the original $vm variable.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Ob...
See more...
What exactly does the error say? That line with Get-View is not needed. You can get those values also from the original $vm variable.
$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Where-Object{$_.Name -notmatch '^vcls'} | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
$guestHD = Get-VMGuestDisk -HardDisk $HardDisk
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="Configured OS";E={$vm.ExtensionData.Config.GuestFullName}},
@{N="Running OS";E={$vm.ExtensionData.Guest.GuestFullName}},
@{N="Datacenter";E={$Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={[math]::Round(($vm.extensiondata.layoutex.file|Where-Object{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB)}},
@{N="Drive Size";E={$HardDisk.CapacityGB.foreach{[math]::Round($_)}}},
@{N='GuestDiskPath';E={$guestHD.DiskPath -join "`n"}},
@{N='GuestCapacityGB';E={($guestHD.CapacityGB.foreach{[math]::Round($_)}) -join "`n"}},
@{N='GuestFreeGB';E={($guestHD.FreeSpaceGB.foreach{[math]::Round($_)}) -join "`n"}},
@{N='GuestDiskType';E={$guestHD.FileSystemType -join "`n"}}
}
}
}
}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path ".\VmInfo.csv"