VMware

This Question is Answered

1 "correct" answer available (10 pts)
8 Replies Last post: Jul 9, 2009 10:50 AM by johnlennon  

storage report listing capacity and freespace for each drive on each vm posted: Sep 9, 2008 12:25 PM

Click to view swspjcd's profile Enthusiast 60 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
}
]


Click to view hugopeeters's profile Hot Shot 155 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
Click to view hugopeeters's profile Hot Shot 155 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.
Click to view fabbio75's profile Enthusiast 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?
Click to view johnlennon's profile Enthusiast 38 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
Click to view fabbio75's profile Enthusiast 43 posts since
Sep 24, 2008
So there's no way to get freedisk space on VM Linux machine ????
Click to view joshuatownsend's profile Novice 19 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

Click to view johnlennon's profile Enthusiast 38 posts since
Sep 2, 2005
I'm looking for an update from VMware: is there a way to get a reliable free space via this toolkit for Linux VMs? For Windows this works, for Linux nos so much...

VMware Developer

SDKs, APIs, Videos, Learn and much more in the Developer community.

Learn More

Developer Sample Code

Increase your developer productivity with VMware API sample code.

Learn More

VMworld Sessions & Labs

Online access to the latest VMworld Sessions & Labs and online services.

Learn more

Purchase PSO Credits Online

Purchase credits to redeem training and consulting services online.

Buy Now

Community Hardware Software

View reported configurations or report your own.

Learn More

VMware vSphere

Come witness the next giant leap in virtualization.

Register Today

Communities