Advertisement
Claudiu

Change a VM to have more than 4 VCPUs in MS Hyper-V

Aug 29th, 2011
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Set here the name of the VM as it is shown in the Hyper-V Manager and the number of VCPUs we want to allocate to it
  2. $VMname = "foo"
  3. $VCPUs = 12
  4.  
  5. if ($VCPUs -lt 1)
  6.     {
  7.     Write-Host "Cannot assign $VCPUs cores... Sorry :-("
  8.     break
  9.     }
  10.  
  11. # Get the Virtual Machine Management Service
  12. $VMMS = Get-WmiObject -Computername localhost -Namespace "root\virtualization" -Class "MSVM_VirtualSystemManagementService"
  13.  
  14. # Get the object corresponding to the virtual machine you want to modify
  15. $VM = Get-WmiObject -Computername localhost -Namespace "root\virtualization" -Class "MSVM_ComputerSystem" | where {$_.ElementName -like $VMname}
  16.  
  17. if ($VM -eq $null)
  18.     {
  19.     Write-Host "Virtual machine not found. Please check the name and try again."
  20.     break
  21.     }
  22.  
  23. # Get the object corresponding to that VM's settings
  24. $VMSettings = $VM.getRelated("MSVM_VirtualSystemSettingData") | select -first 1
  25.  
  26. $GUID = $VMSettings.SystemName
  27. $FileName = "C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\" + $GUID + ".xml"
  28.  
  29. $xml = [xml] (Get-Content $FileName)
  30. Write-Host "Current CPU Count: " $xml.configuration.settings.processors.count."#text"
  31. $xml.configuration.settings.processors.count."#text" = "$VCPUs"
  32. Write-Host "New CPU Count: " $xml.configuration.settings.processors.count."#text"
  33.  
  34. Write-Host "Please wait... Do not stop execution and ignore possible warnings about VMMS stopping; they are intended."
  35. Stop-Service vmms
  36. $xml.Save($FileName)
  37. Start-Service vmms
  38. Write-Host "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement