Skip navigation
VMware

This Question is Answered

1 "correct" answer available (10 pts)
6,410 Views 9 Replies Last post: Dec 21, 2009 1:18 AM by pkodeer RSS
swspjcd Enthusiast 66 posts since
Nov 14, 2003
Currently Being Moderated

Sep 9, 2008 12:25 PM

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

 

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

          }

        ]

 

 

 

 

 

hugopeeters Hot Shot 156 posts since
Jan 10, 2008
Currently Being Moderated
1. Sep 9, 2008 11:44 PM in response to: swspjcd
Re: storage report listing capacity and freespace for each drive on each vm

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

hugopeeters Hot Shot 156 posts since
Jan 10, 2008
Currently Being Moderated
2. Sep 9, 2008 11:58 PM in response to: swspjcd
Re: storage report listing capacity and freespace for each drive on each vm

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.

fabbio75 Enthusiast 43 posts since
Sep 24, 2008
Currently Being Moderated
4. Nov 18, 2008 1:11 AM in response to: hugopeeters
Re: storage report listing capacity and freespace for each drive on each vm

Ok .. but i've some vm with Linux like SO... and i cannot find freespace disk property ...   .. there's a solution?

johnlennon Enthusiast 43 posts since
Sep 2, 2005
Currently Being Moderated
5. Nov 25, 2008 8:38 AM in response to: fabbio75
Re: storage report listing capacity and freespace for each drive on each vm

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

fabbio75 Enthusiast 43 posts since
Sep 24, 2008
Currently Being Moderated
6. Dec 4, 2008 3:18 AM in response to: hugopeeters
Re: storage report listing capacity and freespace for each drive on each vm

So there's no way to get freedisk space on VM Linux machine ????

joshuatownsend Enthusiast vExpert 86 posts since
Apr 17, 2006
Currently Being Moderated
7. Dec 13, 2008 7:20 AM in response to: fabbio75
Re: storage report listing capacity and freespace for each drive on each vm

 

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

 

 

If you found this or other information useful, please consider awarding points for "Correct" or "Helpful". Please visit http://vmtoday.com for News, Views and Virtualization How-To's Follow me on Twitter - @joshuatownsend
johnlennon Enthusiast 43 posts since
Sep 2, 2005
Currently Being Moderated
8. Jul 9, 2009 10:50 AM in response to: swspjcd
Re: storage report listing capacity and freespace for each drive on each vm

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...

pkodeer Enthusiast 32 posts since
Aug 27, 2007
Currently Being Moderated
9. Dec 21, 2009 1:18 AM in response to: swspjcd
Re: storage report listing capacity and freespace for each drive on each vm

$disks = Get-VMGuest -VM   | select VmName -ExpandProperty Disks 

 

#it works well if a VM has only one vDisk

#If a VM has more than one disk, necessary this:

$report = @()

foreach($vmd in $disks){

$row = "" | select Name, Capacity, FreeSpace           

$row.name = $vmd.VmName          

$row.FreeSpace = $vmd.FreeSpace                     

$row.capacity =  $vmd.Capacity

$report += $row

}

- Enterprise - 68x ESX 3.5.0 build 143128 2x VC 2.5.0 build 147633 more than 300 Guest OS

Bookmarked By (0)

Share This Page

Communities