Paasi
Paasi

Reputation: 35

VMWare PowerCLI Get DiskUsage of powered off vm's

I'm creating a script that gets all vm's and shows the 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:

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.

Upvotes: 0

Views: 2159

Answers (2)

mehrdad rafiee
mehrdad rafiee

Reputation: 14

here is example of script to show vm specification:

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)}}

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

hope to be useful ;)

Upvotes: 0

Kyle Ruddy
Kyle Ruddy

Reputation: 2121

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. If the VM is off, there's no way for PowerCLI to find that property.

Alternatively, you could look at the $vm.ExtensionData.Summary.Storage properties and do some rough conversions. Note: the output of those are in byte, so you'll want to convert them to GB. Example: $tempVM.ExtensionData.Summary.Storage.Committed / 1GB

It won't be exact, but it will be better than no output at all.

Upvotes: 2

Related Questions