我有一个脚本来检索我的vCenter群集中所有虚拟机的详细信息。 基本上Get-VM | Get-Harddisk Get-VM | Get-Harddisk 。
我也可以得到Provisioned Space和Used Space值,但是这些值只针对整个虚拟机,而且我想在实际的SAN上得到这个VMDK文件。
我有一些运气($vm.extensiondata.layoutex.file|?{$_.name -contains $harddisk.filename.replace(".","-flat.")}).size/1GB但是这样做不检索所有我的虚拟机的细节,我不能解决为什么?
更新1:所以我发现这个信息可以通过$vm.ExtensionData.Storage.PerDatastoreUsage 。 这将返回每个数据存储的详细数组,并显示使用多less磁盘。 现在的问题是,我不知道如何计算哪个条目涉及哪个磁盘(除了手动检查)。 如果每个磁盘都在不同的数据存储上,但是当它们全都相同且大小相同(也就是说,我们在同一个数据存储中有一个2个100GB的精简磁盘的Windows VM),那么这样做会更有挑战性。
我最终在VMware社区网站上find了这个posthttps://communities.vmware.com/message/1816389#1816389 ,它提供了以下代码作为我可以适应的解决scheme:
Get-View -ViewType VirtualMachine -Property Name, Config.Hardware.Device, LayoutEx | %{ $viewVM = $_; $viewVM.Config.Hardware.Device | ?{$_ -is [VMware.Vim.VirtualDisk]} | %{ ## for each VirtualDisk device, get some info $oThisVirtualDisk = $_ ## get the LayoutEx Disk item that corresponds to this VirtualDisk $oLayoutExDisk = $viewVM.LayoutEx.Disk | ?{$_.Key -eq $oThisVirtualDisk.Key} ## get the FileKeys that correspond to the LayoutEx -> File items for this VirtualDisk $arrLayoutExDiskFileKeys = $oLayoutExDisk.Chain | ?{$_ -is [VMware.Vim.VirtualMachineFileLayoutExDiskUnit]} New-Object -TypeName PSObject -Property @{ ## add the VM name VMName = $viewVM.Name ## the disk label, like "Hard disk 1" DiskLabel = $_.DeviceInfo.Label ## the datastore path for the VirtualDisk file DatastorePath = $_.Backing.FileName ## the provisioned size of the VirtualDisk ProvisionedSizeGB = [Math]::Round($_.CapacityInKB / 1MB, 1) ## get the LayoutEx File items that correspond to the FileKeys for this LayoutEx Disk, and get the size for the items that are "diskExtents" (retrieved as bytes, so converting to GB) SizeOnDatastoreGB = [Math]::Round(($arrLayoutExDiskFileKeys | %{$_.FileKey} | %{$intFileKey = $_; $viewVM.LayoutEx.File | ?{($_.Key -eq $intFileKey) -and ($_.Type -eq "diskExtent")}} | Measure-Object -Sum Size).Sum / 1GB, 1) } ## end new-object } ## end foreach-object } ## end outer foreach-object
我通过社区网站领导到了优秀的博客http://www.lucd.info/2010/03/23/yadr-a-vdisk-reporter/ ,该网站提供了一个包含快照大小的解决scheme