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

Connect to a vSphere server.


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

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)

Get the virtual machine object by using the Get-VIObjectByVIView cmdlet and start the virtual machine.

$vm =  Get-VIObjectByVIView $vmView  | Start-VM