VMware Script – Remove Resource Reservations.
In this article, we will look at the following scenario, which helps us to delete Reserved Resources for all virtual machines in a VMware cluster.
Here’s the script we’re going to use:
# Variable declaration Param ([ string ] $ server , [ Parameter (Required = $ true string ] $ username , [ Parameter (Required = $ true string ] $ password , [ string ] $ cluster # Module Initialization Add-PSSnapin VMware.VimAu tomation.Core # Body Connect-VIServer -Server $ server -Username $ username – Password $ password $ vms = Get-Cluster $ cluster | Get-VM ForEach ( $ vm in $ vms $ reservation = Get-VMResourceConfiguration -VM $ vm If ( $ reservation . CpuReservationMhz -gt 0) { Get-VM -Name $ vm | Get-VMResourceConfiguration | Set-VMResourceConfiguration -CpuReservationMhz 0}}
In the first part of the script, all of our variables are declared as parameters. We have a server, username, password and cluster parameters where we specify the vCenter server we want to connect to, admin username and password and the VMware cluster we want to connect to.
Then we import the VMware PowerCLI snap-in and connect to the vCenter server.
We then get a list of all the virtual machines in the cluster using the Get-Cluster cmdlet, analyzing its output for the Get-VM command and storing all of the output in the $ vms variable.
We then create a ForEach loop that loops through each virtual machine in the array, retrieves the resource configuration for each virtual machine using the Get-VMResourceConfiguration cmdlet, and checks if the CPUReservationMhz attribute is greater than 0. If so, it configures the virtual machine with 0 CPU redundancy.
This is done for all virtual machines in the cluster. This type of script can also be changed and other types of configurations can be obtained and so on. Thank you for your time!