If this was asked I apologize. How does one remove all the CPU reservations (across all clusters) and return them to 0 with the VI toolkit?
Thanks,
Ian
For resource pools you could use the Set-ResourcePool cmdlet.
But I suspect you want to do this for guests ?
Then you can do something like this
Get-VM |% {Get-View $_.ID} | % {
$spec = new-object VMware.Vim.VirtualMachineConfigSpec;
$spec.CPUAllocation = $_.ResourceConfig.CpuAllocation
$spec.CpuAllocation.Reservation = 0;
$_.ReconfigVM_Task($spec)
}
With the Get-VM you get all the guests managed by your VC.
You can use a mask to limit the guests, for example
Get-VM PC* | ...
This would change all guests where the name starts with "PC"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
For resource pools you could use the Set-ResourcePool cmdlet.
But I suspect you want to do this for guests ?
Then you can do something like this
Get-VM |% {Get-View $_.ID} | % {
$spec = new-object VMware.Vim.VirtualMachineConfigSpec;
$spec.CPUAllocation = $_.ResourceConfig.CpuAllocation
$spec.CpuAllocation.Reservation = 0;
$_.ReconfigVM_Task($spec)
}
With the Get-VM you get all the guests managed by your VC.
You can use a mask to limit the guests, for example
Get-VM PC* | ...
This would change all guests where the name starts with "PC"
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome. You guessed correctly I wanted to do all guests.
How would I change this if I wanted to specify guests on particular clusters?
Thanks!
Ian
That's where one of the nice PowerShell features comes into play, the pipeline.
The Get-VM cmdlet has a parameter called -Location where you can limit the returned guest to only that location.
This parameter accepts pipeline input.
So you could do something like this
Get-Cluster <Cluster-Name> | Get-VM | ...
And you do this with datacenters, folders, resourcepools..., as long as the first cmdlet returns a location that is acceptable for the Get-VM cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Perfect. Thanks!
hi guys -
i know i may be asking the obvious but how would one pull back that same information - ie the CPU Reserves and display to screen? Tried a few variants of above code to no avail
There is a sample in the FAQ under Reporting.
If you only want to see the reservations you can use this
get-vm | % { get-view $_.ID } | `
Select-Object Name,
@{ Name="MemReservation"; Expression={$_.Summary.Config.memoryReservation}} ,
@{ Name="CpuReservation"; Expression={$_.Summary.Config.cpuReservation}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
fantastic! thank you LucD
This question stems from my lack of understanding of the ins and outs of PowerCLI and the objects. I understand the Get-View command which exposes properties of the object to queries against the object model which is defined by the SDK, and there is a wealth of information that can be gathered by this method if you know what properties and methods are available. Is it necessary to understand the SDK very well to be able to utilize these, and if so what's the best way to learn? For example in the script below I don't understand why the get-view command is run against the VMobject.ID property instead of just the VM, but it obviously works well in this case.
You're right, this could also be run as
Get-VM | Get-View | `
Select-Object Name,
@{ Name="MemReservation"; Expression={$_.Summary.Config.memoryReservation}} ,
@{ Name="CpuReservation"; Expression={$_.Summary.Config.cpuReservation}}
With a bit of basic knowledge of the SDK you cna already get a long way.
And the newer PowerCLI builds make it less and less of a requirement to go to the SDK methods and properties.
The above can nowadays be obtained with
Get-VM | Get-VMResourceConfiguration | Select-Object Name, CpuReservationMhz, MemReservationMB
If you need some intro on the SDK have a look at my SDK posts PowerCLI and the SDK – Part 1 and PowerCLI and the SDK – Part 2 – Prepare the trip.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
