VMware Cloud Community
bernworx
Enthusiast
Enthusiast

VM Allocation and Consumption Report

Hi All

I would like to seek your help as I need a script to get all VM resources allocation and consumption and have a csv & htm report.

The objective is to get all VM inventory per Datacenter\Cluster\Department Folders\ and within this are No. of VMs + Allocated CPU + Allocated Memory + Provisioned Disk.

Here is the sample report >>>

ConsumerNo. of Virtual MachinesAllocated CPUAllocated MemoryDisk Provisioned
Datacenter A\ Cluster 1 \ Corp10xyz
Datacenter A\ Cluster 1 \ Finance6xyz
Datacenter B\ Cluster 1 \ Corp15xyz
Datacenter B\ Cluster 2 \ Production25xyz

By this way I can see the consumption of all departments in our infrastructure.

0 Kudos
3 Replies
RvdNieuwendijk
Leadership
Leadership

I am not sure how you use the folders per cluster. Afaik you can't create a folder in the 'Hosts and Clusters' view below a cluster. The following script will give you the requested information without the folders. If you elaborate on the folders maybe I can add them later.

Get-Datacenter |

Sort-Object -Property Name |

ForEach-Object {

  $Datacenter = $_

  foreach ($Cluster in (Get-Cluster -Location $Datacenter | Sort-Object -Property Name))

  {

    $VMs = Get-VM -Location $Cluster

    New-Object -TypeName PSObject -Property @{

      Datacenter = $Datacenter.Name

      Cluster = $Cluster.Name

      'No. of Virtual Machines' = $VMs | Measure-Object | Select-Object -ExpandProperty Count

      'Allocated CPU' = $VMs | Measure-Object -Property NumCpu -Sum | Select-Object -ExpandProperty Sum

      'Allocated memory (GB)' = $VMs | Measure-Object -Property MemoryGB -Sum | Select-Object -ExpandProperty Sum

      'Disk Provisoned (GB)' = $VMs | Measure-Object -Property ProvisionedSpaceGB -Sum | Select-Object -ExpandProperty Sum

    } | Select-Object -Property Datacenter,Cluster,'No. of Virtual Machines',

          'Allocated CPU','Allocated memory (GB)','Disk Provisoned (GB)'

  }

}


Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
bernworx
Enthusiast
Enthusiast

Hi

The Folders I'm talking into are the ones created in "VMs and Templates" inventory view or Folder objects.

We have arranged our folders per department.

So, basically you get the Datacenter | then Cluster | then Folders | then get the needed information.

Hope this helps. Smiley Happy

0 Kudos
LucD
Leadership
Leadership

Try it like this

New-VIProperty -Name 'FolderPath' -ObjectType 'VirtualMachine' -Value {
 
param($vm)

 
$path = @()
 
$excludeFolders = "Datacenters","vm"
 
$parent = $vm.ExtensionData
 
while($parent.Parent){
   
$parent = Get-View $parent.Parent
   
if($excludeFolders -notcontains $parent.Name){
     
$path += $parent.Name
    }
  }
  [
string]::Join('/',$path[($path.Count -1)..0])
}
-Force -BasedOnExtensionProperty 'Parent' | Out-Null

Get-VM | Group-Object FolderPath | %{
 
New-Object PSObject -Property @{
   
Consumer = $_.Name
   
"No. of Virtual Machines" = $_.Group.Count
   
"Allocated CPU" = $_.Group | Measure-Object -Property NumCPU -Sum | Select -ExpandProperty Sum
   
"Allocated Memory" = $_.Group | Measure-Object -Property MemoryGB -Sum | Select -ExpandProperty Sum
   
"Disk Provisioned" = $_.Group | Measure-Object -Property ProvisionedSpaceGB -Sum | Select -ExpandProperty Sum
  }
}

It uses a VIProperty to get the blue folderpath, and then groups the VM on this property.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos