Modify the CPU Levels of a Virtual Machine with Get–View and Get–VIObjectByVIView

You can use Get-View in combination with Get–VIObjectByVIView to invoke a vSphere Management API view object and retrieve its PowerCLI variant.

You can modify the CPU levels of a virtual machine by using a combination of the Get-View and Get-VIObjectByVIView cmdlets.

Prerequisites

Verify that you are connected to a vCenter Server system.

Procedure

  1. Get the VM2 virtual machine, shut it down, and pass it to the Get-View cmdlet to view the virtual machine view object.
    $vmView = Get-VM VM2 | Stop-VM | Get-View
  2. Create a VirtualMachineConfigSpec object to modify the virtual machine CPU levels and call the ReconfigVM method of the virtual machine view managed object.
    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec;
    $spec.CPUAllocation = New-Object VMware.Vim.ResourceAllocationInfo;
    $spec.CpuAllocation.Shares = New-Object VMware.Vim.SharesInfo;
    $spec.CpuAllocation.Shares.Level = "normal";
    $spec.CpuAllocation.Limit = -1;
    $vmView .ReconfigVM_Task($spec)
  3. Get the virtual machine object by using the Get-VIObjectByVIView cmdlet and start the virtual machine.
    $vm =  Get-VIObjectByVIView $vmView  | Start-VM