VMware Cloud Community
justin_emerson
Enthusiast
Enthusiast
Jump to solution

Removing CPUID settings?

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.

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership
Jump to solution

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
Jump to solution

LucD,

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
justin_emerson
Enthusiast
Enthusiast
Jump to solution

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.

Reply
0 Kudos
justin_emerson
Enthusiast
Enthusiast
Jump to solution

LucD,

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You're welcome Smiley Wink

Seriously, feel free to ask.


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

ngerasim
Contributor
Contributor
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ngerasim
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
ngerasim
Contributor
Contributor
Jump to solution

I get the error.

The ' | Set-NxFlag -Hide:$true

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
ngerasim
Contributor
Contributor
Jump to solution

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

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos