VMware Cloud Community
john23
Commander
Commander
Jump to solution

Need script for getting folder wise vm used and provisioned space


Hi,

In my client env, we have multiple application type folder. In each folder we have multiple vms, including cluster vms.

We need to get total used space and provisioned space for each folder.

As well requirement is cluster disk must be calculated only one time.  Please help me for this...

-a

Thanks -A Read my blogs: www.openwriteup.com
Reply
0 Kudos
1 Solution

Accepted Solutions
Zsoldier
Expert
Expert
Jump to solution

I'm thinking of a filter to maybe get all VM's that show up as an RDM or shared vmdk and filter those out of the Get-VM collection.

Then add those together separately, combining likeness of the filename maybe?  If you can run this RDM Script, then I can see what the data might look like to adjust.  I don't have any RDM's to play with on my end unfortunately, all NFS these days.

$report = @()

$vms = Get-VM |Sort Name -Descending | Get-View

foreach($vm in $vms)

     {

       foreach($dev in $vm.Config.Hardware.Device)

          {

              if(($dev.gettype()).Name -eq "VirtualDisk")

                    {

                    if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or ($dev.Backing.CompatibilityMode -eq "virtualMode"))

                         {

                         $row = "" | select VMName, HDDeviceName, HDFileName, HDMode, HDSize

                         $row.VMName = $vm.Name

                         $row.HDDeviceName = $dev.Backing.DeviceName

                         $row.HDFileName = $dev.Backing.FileName

                         $row.HDMode = $dev.Backing.CompatibilityMode

                         $row.HDSize = [math]::Round((($dev.CapacityInKB)/1048576),2)

                         $report += $row

                         }

                     }

           }

}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier

View solution in original post

Reply
0 Kudos
10 Replies
Zsoldier
Expert
Expert
Jump to solution

The cluster aspect will be a little more difficult.  Will have to stew on that a bit.:smileyconfused:

Here is a starting point:

$Report = @()

$Folders = Get-Folder

Foreach ($Folder in $Folders)

{

$FolderVMs = $folder | get-vm

If ($FolderVMs)  #Essentially checking if any VM's were returned.

     {

     $TempObject = "" | Select FolderName, ProvisionedSpace, UsedSpace

     $TempObject.FolderName = $folder.name

     $TempObject.ProvisionedSpace = [math]::truncate(($FolderVMs | Measure-Object -Property ProvisionedSpaceGB -Sum).SUM)

     $TempObject.UsedSpace = [math]::truncate(($FolderVMs | Measure-Object -Property UsedSpaceGB -Sum).SUM)   

     $Report += $TempObject

      }

}

$Report

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Zsoldier
Expert
Expert
Jump to solution

Are they RDM's or vmdk's that are shared?

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
john23
Commander
Commander
Jump to solution

Yes these rdm are shared (MSCS clusters).


Thanks -A Read my blogs: www.openwriteup.com
Reply
0 Kudos
john23
Commander
Commander
Jump to solution

Thanks for the script, this is not working Smiley Sad

I am just trying to get the provisioned space and used space parameter,  Not working Smiley Sad

-A

Thanks -A Read my blogs: www.openwriteup.com
Reply
0 Kudos
kunaludapi
Expert
Expert
Jump to solution

Make this correction at 8th line, it will be working.

$TempObject = "" |  Select FolderName, ProvisionedSpace, UsedSpace

--------------------------------------------------------------- Kunal Udapi Sr. System Architect (Virtualization, Networking And Storage) http://vcloud-lab.com http://kunaludapi.blogspot.com VMWare vExpert 2014, 2015, 2016 If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
john23
Commander
Commander
Jump to solution

will try and update ..

Thanks -A Read my blogs: www.openwriteup.com
Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

hehe, oops.  thanks for pointing that out.

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
john23
Commander
Commander
Jump to solution

Thanks Script is working.... Smiley Happy

For MSCS RDM shared disk ,  Script is calculating twice Smiley Sad

Is there any fix for this.

-A

Thanks -A Read my blogs: www.openwriteup.com
Reply
0 Kudos
Zsoldier
Expert
Expert
Jump to solution

I'm thinking of a filter to maybe get all VM's that show up as an RDM or shared vmdk and filter those out of the Get-VM collection.

Then add those together separately, combining likeness of the filename maybe?  If you can run this RDM Script, then I can see what the data might look like to adjust.  I don't have any RDM's to play with on my end unfortunately, all NFS these days.

$report = @()

$vms = Get-VM |Sort Name -Descending | Get-View

foreach($vm in $vms)

     {

       foreach($dev in $vm.Config.Hardware.Device)

          {

              if(($dev.gettype()).Name -eq "VirtualDisk")

                    {

                    if(($dev.Backing.CompatibilityMode -eq "physicalMode") -or ($dev.Backing.CompatibilityMode -eq "virtualMode"))

                         {

                         $row = "" | select VMName, HDDeviceName, HDFileName, HDMode, HDSize

                         $row.VMName = $vm.Name

                         $row.HDDeviceName = $dev.Backing.DeviceName

                         $row.HDFileName = $dev.Backing.FileName

                         $row.HDMode = $dev.Backing.CompatibilityMode

                         $row.HDSize = [math]::Round((($dev.CapacityInKB)/1048576),2)

                         $report += $row

                         }

                     }

           }

}

Chris Nakagaki (中垣浩一)
Blog: https://tech.zsoldier.com
Twitter: @zsoldier
Reply
0 Kudos
john23
Commander
Commander
Jump to solution

I will try to integrate both of them and will post the result ASAP.

-a

Thanks -A Read my blogs: www.openwriteup.com
Reply
0 Kudos