VMware Communities > Developer Community > VI Toolkit (for Windows) > Discussions

This Question is Answered

1 "correct" answer available (10 pts)
7 Replies Last post: Dec 13, 2008 7:20 AM by joshuatownsend
Reply

storage report listing capacity and freespace for each drive on each vm

Sep 9, 2008 12:25 PM

Click to view swspjcd's profile Novice swspjcd 54 posts since
Nov 14, 2003

I am just starting to learn powershell so be patient! I'm looking for a way to connect to our VC or one of the hosts and list all of the virtual servers and their individual drive capacities and also the freespace for each drive. I just started playing around with powershell yesterday and found that if I do "get-vm|fc" it will list out alot of detail about each virtual machine including some lines like below. As far as getting the drive listings for each vm with capacity and freespaceinto a nice formatted report, I'm at a loss. Anyone wanna help? I'm looking through some other scripts to get examples but thought I'd through this out there and see if anyone else (who has better powershell skills!) could help out some.

class VirtualMachineImpl
{
PowerState = PoweredOn
Description =
Guest =
class VMGuestImpl
{
OSFullName = Microsoft Windows Server 2003, Standard Edition (32-bit
IPAddress =
[
REMOVED

]

State = Running
Disks =
[
class DiskInfoImpl
{
Path = C:\
Capacity = 8578932736
FreeSpace = 1092395008
}
class DiskInfoImpl
{
Path = D:\
Capacity = 10733219840
FreeSpace = 10666061824
}
]


Reply Re: storage report listing capacity and freespace for each drive on each vm Sep 9, 2008 11:44 PM
Click to view hugopeeters's profile Hot Shot hugopeeters 137 posts since
Jan 10, 2008
After connecting to Virtual Center or an ESX server (Connect-VIServer SERVERNAME), you can use the following one-liner:
Get-VM | Get-VMGuest | Select VmName -ExpandProperty Disks


If you want to have it as a csv file (to import in Excel), pipe it to Export-Csv D:\scripts\vmdisks.csv
If you'd rather have it saved in html, pipe it to ConvertTo-Html | Out-File D:\scripts\vmdisks.html

You might want to set $errorActionPreference = SilentlyContinue first, because powered off vm's will cause an error. Or use:
Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VmName -ExpandProperty Disks


Hope that helps.

Hugo Peeters
www.peetersonline.nl
Reply Re: storage report listing capacity and freespace for each drive on each vm Sep 9, 2008 11:58 PM
Click to view hugopeeters's profile Hot Shot hugopeeters 137 posts since
Jan 10, 2008
Or, if you want to get really fancy, try this one-liner:
Get-VM | Where { $_.PowerState -eq "PoweredOn" } | Get-VMGuest | Select VmName -ExpandProperty Disks | Select VmName, Path, @{ N="PercFree"; E={ [math]::Round( ( 100 * ( $_.FreeSpace / $_.Capacity ) ),0 ) } } | Sort PercFree

You'll get an overview sorted by Percentage of free space.
Reply Re: storage report listing capacity and freespace for each drive on each vm Sep 10, 2008 5:40 AM
in response to: hugopeeters
Click to view swspjcd's profile Novice swspjcd 54 posts since
Nov 14, 2003
Excellent! Thanks to all of you. This definitely gives me a place to start and will certainly help in my quest for more powershell scripting abilities.
Reply Re: storage report listing capacity and freespace for each drive on each vm Nov 18, 2008 1:11 AM
in response to: hugopeeters
Click to view fabbio75's profile Enthusiast fabbio75 43 posts since
Sep 24, 2008
Ok .. but i've some vm with Linux like SO... and i cannot find freespace disk property ... :( .. there's a solution?
Reply Re: storage report listing capacity and freespace for each drive on each vm Nov 25, 2008 8:38 AM
in response to: fabbio75
Click to view johnlennon's profile Enthusiast johnlennon 27 posts since
Sep 2, 2005
Same here, for Linux RHEL5 with LVM, the command reports only the /boot partition infomation which is useless, instead of the / which is the one that we need.

What is reported by Select VmName -ExpandProperty Disks


Path Capacity FreeSpace

/boot 103512064 79201280

What df reports (in bold what is missing from the powershell output):

$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00

  • 28G 13G 14G 48% /*
/dev/sda1 99M 24M 71M 25% /boot
Reply Re: storage report listing capacity and freespace for each drive on each vm Dec 4, 2008 3:18 AM
in response to: hugopeeters
Click to view fabbio75's profile Enthusiast fabbio75 43 posts since
Sep 24, 2008
So there's no way to get freedisk space on VM Linux machine ????
Reply Re: storage report listing capacity and freespace for each drive on each vm Dec 13, 2008 7:20 AM
in response to: fabbio75
Click to view joshuatownsend's profile Novice joshuatownsend 5 posts since
Apr 17, 2006

There is a way to get free space on Linux guests (or any guest in any power-state for that matter). I outline the method in a post on my blog at VMtoday. My method is not a VI Toolkit for Windows solution, although it does use PowerShell to run a SQL Query against the VirtualCenter database. Check out the post for more info....

Josh

Actions