Powershell script to adjust the CPU reservation, Limit, and VirtualQuantity of VM on Hyper-V RRS feed

  • Question

  • Dear All:

    I want to use a script file to adjust the VirtualQuantity, CPU Reservation, Limit and Relative Weight of VM on Hyper-V. I found an example code in Pro Hyper-V which is designed to do so.


    Here is the example:

    $GuestVM = "Test1"
    $Namespace = "root\virtualization"
    $Computer = "WS2008NB"
    $VMService = Get-WmiObject -class "Msvm_VirtualSystemManagementService" -namespace $Namespace -ComputerName $Computer
    $VM = Get-WmiObject -namespace $Namespace -Computername $Computer -Query "Select * From Msvm_ComputerSystem Where ElementName='$GuestVM'" 
    $VMSettingData = Get-WmiObject -Namespace $Namespace -Query "Associators of {$VM} Where 
    ResultClass=Msvm_VirtualSystemSettingData AssocClass=Msvm_SettingsDefineState"
    $Vproc = (Get-WmiObject -Namespace $Namespace -Query "Associators of {$VMSettingData} Where 
    ResultClass=Msvm_ProcessorSettingData AssocClass=Msvm_VirtualSystemSettingDataComponent" | 
    where-object -FilterScript {$_.ResourceSubType -eq "Microsoft Processor"})
    $Vproc.VirtualQuantity = [string]1
    $Vproc.Reservation = [string]59
    $Vproc.Limit = [string]60
    $Vproc.Weight = [string]50
    $VMService.ModifyVirtualSystemResources($VM.Path, $Vproc.PSBase.GetText(1))

    The problem is that the code can only modify the VirtaulQuantity and Weight successfully. The Reservation and Limit will not be changed after executing the script file. Does anyone have ideas about that? Thank you very much.

    Saturday, August 13, 2011 3:12 AM