Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 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
- $VMname = "foo"
- $VCPUs = 12
- if ($VCPUs -lt 1)
- {
- Write-Host "Cannot assign $VCPUs cores... Sorry :-("
- break
- }
- # Get the Virtual Machine Management Service
- $VMMS = Get-WmiObject -Computername localhost -Namespace "root\virtualization" -Class "MSVM_VirtualSystemManagementService"
- # Get the object corresponding to the virtual machine you want to modify
- $VM = Get-WmiObject -Computername localhost -Namespace "root\virtualization" -Class "MSVM_ComputerSystem" | where {$_.ElementName -like $VMname}
- if ($VM -eq $null)
- {
- Write-Host "Virtual machine not found. Please check the name and try again."
- break
- }
- # Get the object corresponding to that VM's settings
- $VMSettings = $VM.getRelated("MSVM_VirtualSystemSettingData") | select -first 1
- $GUID = $VMSettings.SystemName
- $FileName = "C:\ProgramData\Microsoft\Windows\Hyper-V\Virtual Machines\" + $GUID + ".xml"
- $xml = [xml] (Get-Content $FileName)
- Write-Host "Current CPU Count: " $xml.configuration.settings.processors.count."#text"
- $xml.configuration.settings.processors.count."#text" = "$VCPUs"
- Write-Host "New CPU Count: " $xml.configuration.settings.processors.count."#text"
- Write-Host "Please wait... Do not stop execution and ignore possible warnings about VMMS stopping; they are intended."
- Stop-Service vmms
- $xml.Save($FileName)
- Start-Service vmms
- Write-Host "Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement