PowerCLI: Set CPU Identification Mask


image

Today I received a question in my mailbox about setting the CPU Identification Mask on Multiple VM’s. The guy who asked the question wanted to set the following values:

image

So I started to search on the VMware Communities and I found the following function.

# Mask SSE 4.1 Extensions to the guest.
function Mask-Extensions($vm) {
    $view = get-view $vm.id

    $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec
    $featureMask = new-object VMware.Vim.VirtualMachineCpuIdInfoSpec
    $featureMask.info = new-object VMware.Vim.HostCpuIdInfo

    $featureMask.info.ecx = "---- ---- ---- 0--- ---- ---- ---- ----"
    $featureMask.info.level = 1

    $vmConfigSpec.CpuFeatureMask = $featureMask

    $view.ReconfigVM($vmConfigSpec)
}

I changed it a little bit, so it matches the required settings (see picture above):

function Mask-Extensions($vm) {

    $view = get-view $vm.id
    write-host "Setting Mask for: "$vm.Name

    $vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec
    $featureMask = new-object VMware.Vim.VirtualMachineCpuIdInfoSpec
    $featureMask.info = new-object VMware.Vim.HostCpuIdInfo
    $featureMask.info.eax = "-----------------------------000"
    $featureMask.info.level = 0

    $vmConfigSpec.CpuFeatureMask = $featureMask

    $view.ReconfigVM($vmConfigSpec)
}

If you want to run this function against one VM, You can run the following command:

Mask-Extensions (get-vm "My VM")

You can also use this function in the pipeline:

get-vm | % {Mask-Extensions ($_)}

 

Source: http://communities.vmware.com/message/960123#960123

Advertisements

2 thoughts on “PowerCLI: Set CPU Identification Mask

  1. Jonathan Jewett

    Thanks for this function. I can really use this in my situation. One additional question though, how would I write the script so that it displays the current CPU ID mask?

    Thanks,
    Jonathan

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s