VMware Cloud Community
vmhyperv
Contributor
Contributor
Jump to solution

No of vCPU and Memory reservation in VC

Hello,

  I am looking for a Power Cli script for finding out the no of vCPU reserved and Memory(GB) reserved of a VM in VC. The output in csv format with VM Name having no  of  vCPU and memory reserved.

  And also is it possible to findout the reservation at per Cluster level.

Thanks

Kumar

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
dmilov
VMware Employee
VMware Employee
Jump to solution

Sure, You should remove Get-Cluster call and pass the VC connection to the Server parameter of Get-VM cmdlet, see below:

$myVC = Connect-VIServer <VC server IP/Name>

$vmsInfo = Get-VM -Server $myVC | % {

$vmInfo = New-Object PSObject -Property @{Name = ''; MemoryReservationGB = 0; CPUReservationMHz = 0;};

$vmInfo.Name = $_.Name;

$vmInfo.CPUReservationMHz = $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation

$vmInfo.MemoryReservationGB = $_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation / 1024;

return $vmInfo;

}

$vmsInfo | Export-Csv -Path "c:\tmp.csv"

View solution in original post

0 Kudos
8 Replies
dmilov
VMware Employee
VMware Employee
Jump to solution

Hello Kumar,

See below 2 script, not sure what you mean number of vCPU reserved, but the scripts extract the VM number of CPUs and memory reservation in GB:

For VMs in a Cluster:

$vmsInfo = Get-Cluster -Name 'MyCluster' | Get-VM | % {

   $vmInfo = New-Object PSObject -Property @{Name = ''; MemoryReservationGB = 0; NumCPU = 0;};

   $vmInfo.Name = $_.Name;

   $vmInfo.MemoryReservationGB = $_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation / 1024;

   return $vmInfo;

}

$vmsInfo | Export-Csv -Path "c:\tmp.csv"

For single VM:

$vm

= Get-VM -Name 'MyVM'

$vmInfo

= New-Object PSObject -Property @{Name = ''; MemoryReservationGB = 0; NumCPU = 0;};

$vmInfo

.Name = $vm.Name;

$vmInfo

.MemoryReservationGB = $vm.ExtensionData.ResourceConfig.MemoryAllocation.Reservation / 1024;

$vmInfo

| Export-Csv -Path "c:\tmp.csv"

Is this what you are looking for?

Regards,

Dimitar Milov

PowerCLI Team

vmhyperv
Contributor
Contributor
Jump to solution

Hello dmilov,

         Thanks once again for your help.Actually i got one project  for preparing Capacity planing Report where i need to findout first How (many) VMs having no  of CPU and Memory (GB) reserved so that we can calculate after excluding this.PFA  If still not clear then let me know  so that i can explain in details.

Thanks

Kumar

0 Kudos
dmilov
VMware Employee
VMware Employee
Jump to solution

OK, I see,

The CPU reservation is in MHz, so the script could be changed as follows

$vmsInfo = Get-Cluster -Name 'MyCluster' | Get-VM | % {

$vmInfo = New-Object PSObject -Property @{Name = ''; MemoryReservationGB = 0; CPUReservationMHz = 0;};

$vmInfo.Name = $_.Name;

$vmInfo.CPUReservationMHz = $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation

$vmInfo.MemoryReservationGB = $_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation / 1024;

return $vmInfo;

}

$vmsInfo | Export-Csv -Path "c:\tmp.csv"

As addition You can take a look at $vm.ExtensionData.ResourceConfig to extract what you need, where $vm is a VM instance returned from get-VM cmdlet.

vmhyperv
Contributor
Contributor
Jump to solution

Thanks I will let you know how its works  once i will  execute the scripts in office environment.(Coming Monday) i got the perfect script.

Thanks

kumar

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

Hello demilov,

         These details i have missed out so please find the attachment.Capacity planning Report generated from RV tools and rest finding through powerCli script. We have 5000 VMs

Powered On VMs      (got the answer)
Powered Off VMs      (got the answer)
Reserved vCPU         (got the answer)
Reserved Memory GB  (got the answer)

Any valuable suggestions/Improvement will be much appreaciated.

Thanks

Kumar

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

Hello Dmilov,

        Is Possible  to modify the script to find the  CPU and Memory  reservation in IN VCenter  level instead of Cluster level

like which  VM name  having  CPU and Memory reservation  with cluster name,ESX host name(optional).Right now the script is working but lot of cluster having in vc so every time need to change the cluster name to findout the reservation.  Looking  for prompt response.

Thanks

Kumar

0 Kudos
dmilov
VMware Employee
VMware Employee
Jump to solution

Sure, You should remove Get-Cluster call and pass the VC connection to the Server parameter of Get-VM cmdlet, see below:

$myVC = Connect-VIServer <VC server IP/Name>

$vmsInfo = Get-VM -Server $myVC | % {

$vmInfo = New-Object PSObject -Property @{Name = ''; MemoryReservationGB = 0; CPUReservationMHz = 0;};

$vmInfo.Name = $_.Name;

$vmInfo.CPUReservationMHz = $_.ExtensionData.ResourceConfig.CpuAllocation.Reservation

$vmInfo.MemoryReservationGB = $_.ExtensionData.ResourceConfig.MemoryAllocation.Reservation / 1024;

return $vmInfo;

}

$vmsInfo | Export-Csv -Path "c:\tmp.csv"

0 Kudos
vmhyperv
Contributor
Contributor
Jump to solution

Dmilov,

      Thanks for help once again.I will let you know after executing the script.

Thanks

kumar

0 Kudos