Enabling processor compatibility with a script [Hyper-V]

Enabling processor compatibility with a script [Hyper-V]

Rate This
  • Comments 4


When we released Windows Server 2008 R2 we added the ability to make a virtual machines processor more compatible for migration between different hardware platforms (details here).  Here is a PowerShell script to do this for you:

# Function for handling WMI jobs / return values
Function ProcessResult($result, $successString, $failureString)
{
   #Return success if the return value is "0"
   if ($result.ReturnValue -eq 0)
      {write-host $successString} 
 
   #If the return value is not "0" or "4096" then the operation failed
   ElseIf ($result.ReturnValue -ne 4096)
      {write-host $failureString "  Error value:" $result.ReturnValue}
 
   Else
      {#Get the job object
      $job=[WMI]$result.job
 
      #Provide updates if the jobstate is "3" (starting) or "4" (running)
      while ($job.JobState -eq 3 -or $job.JobState -eq 4)
         {write-host $job.PercentComplete "% complete"
          start-sleep 1
 
          #Refresh the job object
          $job=[WMI]$result.job}
 
       #A jobstate of "7" means success
       if ($job.JobState -eq 7)
          {write-host $successString}
       Else
          {write-host $failureString
          write-host "ErrorCode:" $job.ErrorCode
          write-host "ErrorDescription" $job.ErrorDescription}
       }
}
 
# Prompt for the Hyper-V Server to use
$HyperVServer = Read-Host "Specify the Hyper-V Server to use (enter '.' for the local computer)"
 
# Prompt for the virtual machine to use
$VMName = Read-Host "Specify the name of the virtual machine"
 
# Get the management service
$VMMS = gwmi -namespace root\virtualization Msvm_VirtualSystemManagementService -computername $HyperVServer
 
# Get the virtual machine object
$VM = gwmi MSVM_ComputerSystem -filter "ElementName='$VMName'" -namespace "root\virtualization" -computername $HyperVServer
 
# SettingType = 3 ensures that we do not get snapshots
$SystemSettingData = $VM.getRelated("Msvm_VirtualSystemSettingData") | where {$_.SettingType -eq 3}
 
# Get the processor setting data
$ProcSetting = $SystemSettingData.getRelated("Msvm_ProcessorSettingData") | select -first 1
 
# Enable processor compatibility
$ProcSetting.LimitProcessorFeatures = $true
 
# Apply the changes to the processor setting data back to the virtual machine
$result = $VMMS.ModifyVirtualSystemResources($VM, $ProcSetting.GetText(1))
 
# Process the result
ProcessResult $result "Enabled limited processor features." "Failed to enable limited processor features."

Cheers,
Ben

Attachment: ProcessorCompatibility.zip
Leave a Comment
  • Please add 4 and 2 and type the answer here:
  • Post
  • I mean, I do not think you will be able to migrate from an Intel to an AMD? Or yes?

  • You can't go from Intel to AMD.  This feature will allow you to migrate within the same processor family.  For example you could migrate a VM created on an Intel Q94XX series ('Core' based) to E55XX series ('Nehalem' based), for example.

    I have never had problems going from OLD to NEW, just the other way around.

    But I have not used the processor compatibility feature as I am concerned (perhaps unwarranted?) that I will loose too much performance, so I make sure all our Hyper-V environments have the same CPU family.

  • Will this scrpt work even when the guest machine is powered on and take effect at next reboot or can it only change the setting when the machine is shutdown?

  • Will this scrpt work even when the guest machine is powered on and take effect at next reboot or can it only change the setting when the machine is shutdown?

Page 1 of 1 (4 items)