justin_emerson
Enthusiast
Enthusiast

Removing CPUID settings?

Jump to solution

I'm working on a cluster where it seems like half the VMs have advanced CPUID settings on them. We are migrating them to vSphere and we need to remove all these (EVC will do it for us). I've seen several threads on how to set this value, but nothing on how to remove it. What I'm looking for is the POwerCLI equivalent of checking the 'expose NX flag to guest" radio button (the second option). I could set the advanced CPU mask to all -'s but that's different that removing everything. Any suggestions? The API documentation doesn't show how to remove it, as far as I can tell (of course, I'm not a master when it comes to the actual API).

Any help would be very appreciated.

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership

Yes, it will. The script does the same as the "expose NX flag to guest" radio button.

You want to just set the Nx flag bit in the mask ? Like the "Advanced" option ?

That requires a different logic but is possible as well.

Just let me know.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
13 Replies
LucD
Leadership
Leadership

The following script should allow you to set the Nx flag to Hidden or Exposed.

filter Set-NxFlag {
	param([switch]$hide = $false)
	$view = get-view $_.id

	$vmConfigSpec = new-object VMware.Vim.VirtualMachineConfigSpec
	$featureMask = new-object VMware.Vim.VirtualMachineCpuIdInfoSpec
	$featureMask.Operation = "edit"
	$featureMask.info = new-object VMware.Vim.HostCpuIdInfo
	$featureMaskAMD = new-object VMware.Vim.VirtualMachineCpuIdInfoSpec
	$featureMaskAMD.Operation = "edit"
	$featureMaskAMD.info = new-object VMware.Vim.HostCpuIdInfo

	if($hide){
		$featureMask.info.edx = "-----------0--------------------"
		$featureMaskAMD.info.edx = "-----------0--------------------"
	}
	else{
		$featureMask.info.edx = "-----------H--------------------"
		$featureMaskAMD.info.edx = "-----------H--------------------"
	}

	$featureMask.info.level = 0x80000001
	$featureMaskAMD.info.level = 0x80000001
	$featureMaskAMD.info.vendor = "amd"
	$vmConfigSpec.CpuFeatureMask = $featureMask,$featureMaskAMD

	$view.ReconfigVM($vmConfigSpec)
}

Get-VM <VM-name> | Set-NxFlag -Hide:$false

The function Set-NxFlag is conceived as a filter, this will allow you to use it in a pipeline.

The -Hide switch allows to specify if the Nx flag should be hidden (-Hide:$true) or exposed (-Hidden:$false).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

justin_emerson
Enthusiast
Enthusiast

LucD,

Thank you so much. Will this erase all the custom CPUID settings that are set?

0 Kudos
LucD
Leadership
Leadership

Yes, it will. The script does the same as the "expose NX flag to guest" radio button.

You want to just set the Nx flag bit in the mask ? Like the "Advanced" option ?

That requires a different logic but is possible as well.

Just let me know.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
justin_emerson
Enthusiast
Enthusiast

LucD,

Setting the radio button (which removes all the custom attributes) is exactly what I need. Thanks so much, I'll let you know if it works.

0 Kudos
justin_emerson
Enthusiast
Enthusiast

LucD,

This did exactly what I needed. Thanks again. A "you're welcome" post would earn you an extra 1 forum point Smiley Wink

0 Kudos
LucD
Leadership
Leadership

You're welcome Smiley Wink

Seriously, feel free to ask.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

ngerasim
Contributor
Contributor

What would happen if this was run against a group of VMs that were still powered on?

My understanding was this change should/could only be made when the VM is in a powered off state. Any advice?

0 Kudos
LucD
Leadership
Leadership

I think the script will run without a problem, but when you power off the guest the values in the VMX file will be overwritten with the active CPUID settings.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ngerasim
Contributor
Contributor

So in theory if I was to run this, and then power cycle the VMs after, they would attain the new reset values?

0 Kudos
ngerasim
Contributor
Contributor

I get the error.

The ' | Set-NxFlag -Hide:$true

0 Kudos
LucD
Leadership
Leadership

The text "<VM-name>" serves as a placeholder.

You would have to replace that string with a name of one of your VMs.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ngerasim
Contributor
Contributor

What if I wanted to use this as a wildcard though?

0 Kudos
LucD
Leadership
Leadership

That would work without a problem with the filter function.

The last line would be something like this

Get-VM PC* | Set-NxFlag -Hide:$false

which would select all guests whose name starts with "PC".

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos