VMware Cloud Community
ranjithbabhu
Enthusiast
Enthusiast
Jump to solution

To get the report only the VMs is set for memory and CPU reservation.

if Memory and CPU reservation is set "0" then no problem. Want to find only the VMs with settings Memory and CPU reservation more than 0. Tried something like below but its giving for all VMs output.

foreach ($vCenter in $vCenters)

{

        Connect-VIServer $vCenter -Username $vcUser -Password $vcPassword

}

$report = foreach($rp in Get-ResourcePool){

    $rpCpu = Get-View -Id  $rp.ExtensionData.Vm -Property Config.Hardware.NumCpu |

        %{$_.Config.Hardware.NumCpu} | Measure-Object -Sum | select -ExpandProperty Sum

    Get-VM -Location $rp |

    Select @{N='Resourcepool';E={$rp.Name}},

  

        @{N='CPU Reservation MHz';E={$rp.CpuReservationMHz}},

        @{N='Mem Reservation GB';E={$rp.MemReservationGB}},

        Name

}

$report | Export-Csv resoures.csv -NoTypeInformation -UseCulture

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, if I understand it correctly, you want something like this.

foreach ($vCenter in $vCenters)

{

        Connect-VIServer $vCenter -Username $vcUser -Password $vcPassword

}


$report = foreach($rp in Get-ResourcePool){

    $rpCpu = Get-View -Id  $rp.ExtensionData.Vm -Property Config.Hardware.NumCpu |

        %{$_.Config.Hardware.NumCpu} | Measure-Object -Sum | select -ExpandProperty Sum

    Get-VM -Location $rp |

    where{$_.ExtensionData.Config.CpuAllocation.Reservation -gt 0 -or $_.ExtensionData.Config.MemoryAllocation.Reservation -gt 0} |

    Select @{N='Resourcepool';E={$rp.Name}},

        @{N='CPU Reservation MHz';E={$_.ExtensionData.Config.CpuAllocation.Reservation}},

        @{N='Mem Reservation GB';E={$_.ExtensionData.Config.MemoryAllocation.Reservation}},

        Name

}


$report | Export-Csv resoures.csv -NoTypeInformation -UseCulture


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

View solution in original post

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership
Jump to solution

Try adding this Where-clause

foreach ($vCenter in $vCenters)

{

        Connect-VIServer $vCenter -Username $vcUser -Password $vcPassword

}

$report = foreach($rp in Get-ResourcePool){

    $rpCpu = Get-View -Id  $rp.ExtensionData.Vm -Property Config.Hardware.NumCpu |

        %{$_.Config.Hardware.NumCpu} | Measure-Object -Sum | select -ExpandProperty Sum

    Get-VM -Location $rp |

    where{$_.ExtensionData.Config.CpuAllocation.Reservation -gt 0 -or $_.ExtensionData.Config.MemoryAllocation.Reservation -gt 0} |

    Select @{N='Resourcepool';E={$rp.Name}},

        @{N='CPU Reservation MHz';E={$rp.CpuReservationMHz}},

        @{N='Mem Reservation GB';E={$rp.MemReservationGB}},

        Name

}

$report | Export-Csv resoures.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
ranjithbabhu
Enthusiast
Enthusiast
Jump to solution

The Where-clause is works fine. But  the CPU and Memory limit value is showing wrong. is it something i missing here

The out put shows like below  but the actual value reservation for CPU is 3998 and RAM is 8192 reserved. Also resource pool name is not required only reservation value and VMname is enough.

  

Resourcepool;"CPU Reservation MHz";"Mem Reservation GB";"Name"
Resources;"158658";"249724609375";"VMNAMEXXX"
Clustername-Medium;"0";"0";"VMNAMEXXX"
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

I didn't change that code, that is your code.
I only added the Where-clause, which was the question if I read correctly.


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

Reply
0 Kudos
ranjithbabhu
Enthusiast
Enthusiast
Jump to solution

Yes LucD, The main script itself i am not getting the correct output. I would like to fetch only memory and cpu reservation VMs but ending up with different output.

Can you help to correct the main script to get only memory and cpu reservation VMs  with value.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, if I understand it correctly, you want something like this.

foreach ($vCenter in $vCenters)

{

        Connect-VIServer $vCenter -Username $vcUser -Password $vcPassword

}


$report = foreach($rp in Get-ResourcePool){

    $rpCpu = Get-View -Id  $rp.ExtensionData.Vm -Property Config.Hardware.NumCpu |

        %{$_.Config.Hardware.NumCpu} | Measure-Object -Sum | select -ExpandProperty Sum

    Get-VM -Location $rp |

    where{$_.ExtensionData.Config.CpuAllocation.Reservation -gt 0 -or $_.ExtensionData.Config.MemoryAllocation.Reservation -gt 0} |

    Select @{N='Resourcepool';E={$rp.Name}},

        @{N='CPU Reservation MHz';E={$_.ExtensionData.Config.CpuAllocation.Reservation}},

        @{N='Mem Reservation GB';E={$_.ExtensionData.Config.MemoryAllocation.Reservation}},

        Name

}


$report | Export-Csv resoures.csv -NoTypeInformation -UseCulture


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

Reply
0 Kudos
ranjithbabhu
Enthusiast
Enthusiast
Jump to solution

This worked Great, Thanks LucD.

{N='CPU Reservation MHz';E={$_.ExtensionData.Config.CpuAllocation.Reservation}},

@{N='Mem Reservation GB';E={$_.ExtensionData.Config.MemoryAllocation.Reservation}}

Reply
0 Kudos