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
Ok, if I understand it correctly, you want something like this.
{
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
Try adding this Where-clause
{
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
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";"2497 | 24609375";"VMNAMEXXX" |
Clustername-Medium;"0";"0";"VMNAMEXXX" |
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
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.
Ok, if I understand it correctly, you want something like this.
{
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
This worked Great, Thanks LucD.
{N='CPU Reservation MHz';E={$_.ExtensionData.Config.CpuAllocation.Reservation}},
@{N='Mem Reservation GB';E={$_.ExtensionData.Config.MemoryAllocation.Reservation}}