简体   繁体   English

VMWare PowerCLI获取已关闭电源的VM的DiskUsage

[英]VMWare PowerCLI Get DiskUsage of powered off vm's

I'm creating a script that gets all vm's and shows the DiskSpace. 我正在创建一个获取所有虚拟机并显示DiskSpace的脚本。 THe Problem is, that if a vm is powered off, it won't show the uesed Space of a disk. 问题是,如果虚拟机关闭电源,它将不会显示磁盘的已用空间。

Here are two examples: First one with an VM that is powered on: 以下是两个示例:第一个示例是打开了VM的电源:

PowerCLI C:\> Get-VM sluwv0039

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
sluwv0039            PoweredOn  2        4.000

PowerCLI C:\> $VM = Get-VM sluwv0039
PowerCLI C:\> $VM.guest.disks

CapacityGB      FreeSpaceGB     Path
----------      -----------     ----
49.997          5.417           C:\

Example two where the VM is powered off: 虚拟机关闭的示例二:

PowerCLI C:\> Get-VM sluwv0012

Name                 PowerState Num CPUs MemoryGB
----                 ---------- -------- --------
sluwv0012            PoweredOff 4        8.000


PowerCLI C:\> $VM = Get-VM sluwv0012
PowerCLI C:\> $VM.guest.disks
PowerCLI C:\>

Note: The Last line is the output. 注意:最后一行是输出。 There is no "CapacityGB" etc. 没有“ CapacityGB”等。

Correct, that property is reading from the guest file system to see how much space is left on the partition. 正确,该属性正在从来宾文件系统读取,以查看分区上剩余了多少空间。 In your case, the C:\\ drive. 您的情况是C:\\驱动器。 If the VM is off, there's no way for PowerCLI to find that property. 如果VM关闭,则PowerCLI无法找到该属性。

Alternatively, you could look at the $vm.ExtensionData.Summary.Storage properties and do some rough conversions. 另外,您可以查看$vm.ExtensionData.Summary.Storage属性并进行一些粗略的转换。 Note: the output of those are in byte, so you'll want to convert them to GB. 注意:这些文件的输出以字节为单位,因此您需要将它们转换为GB。 Example: $tempVM.ExtensionData.Summary.Storage.Committed / 1GB 示例: $tempVM.ExtensionData.Summary.Storage.Committed / 1GB

It won't be exact, but it will be better than no output at all. 这不是精确的,但总比没有输出要好。

here is example of script to show vm specification: 这是显示vm规范的脚本示例:

Get-Vm | Get-Vm | Select-Object Name,PowerState,VMHost,NumCPU,MemoryGB,ProvisionedSpaceGB,@{N="HostName";E={@($ .guest.HostName)}},@{N="Gateway";E={@($ .ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress[0])}},@{N="DNS";E={$ .ExtensionData.Guest.IpStack.DnsConfig.IpAddress}},@{N="IPAddress";E={@($ .guest.IPAddress -like "192.168.*")}},@{N="Nics";E={@($ .guest.Nics)}},@{N="Datastore";E={@($ | Get-DataStore)}},@{N="Disks";E={@($ .guest.Disks)}},Version,@{N="State";E={@($ .guest.State)}},@{N="OS";E={@($_.guest.OSFullName)}} 选择对象名称,PowerState,VMHost,NumCPU,MemoryGB,ProvisionedSpaceGB,@ {N =“ HostName”; E = {@($ .guest.HostName)}},@ {N =“ Gateway”; E = {@( $ .ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IpAddress [0])}},@ {N =“ DNS”; E = {$ .ExtensionData.Guest.IpStack.DnsConfig.IpAddress}},@ {N =“ IPAddress”; E = {@($ .guest.IPAddress -like“ 192.168。*”)}},@ {N =“ Nics”; E = {@($ .guest.Nics)}},@ { N =“ Datastore”; E = {@($ | Get-DataStore)}},@ {N =“ Disks”; E = {@($ .guest.Disks)}},版本,@ {N =“ State “; E = {@($ .guest.State)}},@ {N =” OS“; E = {@($ _。guest.OSFullName)}}

the sample output is like this: 示例输出如下:

Name State VMHost NumCpu MemoryGB PowerState ProvisionedSpaceGB Version IPAddress HostName OS Nics Disks VMwareTools Gateway DNS test Running 192.168.32.100 2 1 PoweredOn 43.1085147 v8 192.168.122.1 Elenoon Ubuntu Linux (64-bit) Network adapter 1:VM Network Network adapter 2:local : : Capacity:17167286272, FreeSpace:14212493312, Path:/ Capacity:15188623360, FreeSpace:15154872320, Path:/media/files Capacity:10724835328, FreeSpace:10672824320, Path:/var/log Capacity:973770752, FreeSpace:690139136, Path:/boot guestToolsRunning 127.0.0.1 名称状态VMHost NumCpu MemoryGB PowerState ProvisionedSpaceGB版本IPAddress HostName OS Nics磁盘VMwareTools Gateway DNS test Running 192.168.32.100 2 1 PoweredOn 43.1085147 v8 192.168.122.1 Elenoon Ubuntu Linux(64-bit)Network adapter 1:VM Network Network adapter 2:local::容量:17167286272,FreeSpace:14212493312,路径:/容量:15188623360,FreeSpace:15154872320,路径:/ media / files容量:10724835328,FreeSpace:10672824320,路径:/ var / log容量:973770752,FreeSpace:690139136,路径:/启动guestTools运行127.0.0.1

hope to be useful ;) 希望有用;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM