<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>CPU Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/category/vsphere/cpu/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/category/vsphere/cpu/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Fri, 04 Feb 2011 00:05:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.7</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>CPU Archives - LucD notes</title>
	<link>https://www.lucd.info/category/vsphere/cpu/</link>
	<width>32</width>
	<height>32</height>
</image> 
<atom:link rel="hub" href="https://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="https://pubsubhubbub.superfeedr.com"/><atom:link rel="hub" href="https://websubhub.com/hub"/>	<item>
		<title>NX/XD flag setting report</title>
		<link>https://www.lucd.info/2010/05/13/nxxd-flag-setting-report/</link>
					<comments>https://www.lucd.info/2010/05/13/nxxd-flag-setting-report/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Thu, 13 May 2010 14:37:24 +0000</pubDate>
				<category><![CDATA[CPU]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[vSphere]]></category>
		<category><![CDATA[mask]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=2221</guid>

					<description><![CDATA[Michael asked if it was possible to produce a report that showed the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Michael asked if it was possible to produce a report that showed the <strong>NX/XD flag</strong> setting for all the guests.</p>
<p>Piece of cake I thought, but it turned out to be a bit more complex than that. If you don&#8217;t set the NX/XD flag (<strong>expose</strong> or <strong>hide</strong>) explicitly on the guest, the hyper-visor will use a <strong>default</strong> that is defined<strong> per OS</strong> you can have on the guest.</p>
<p>In the end I think I came up with a script that seems to handle all the different possibilities I encountered.</p>
<p><span id="more-2221"></span></p>
<p>The script</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$report = @()

Get-View -ViewType VirtualMachine | where {!$_.Config.Template} | %{
	$vm = $_

	$osDefault = $false
	$osDefaultAmd = $false
	if($vm.Config.CpuFeatureMask){
		$flagLocation = 11
		$mask = $vm.Config.CpuFeatureMask
		$cpuLvl80000001 = $mask | where {$_.Level -eq 0x80000001 -and !$_.Vendor}
		if($cpuLvl80000001){
			$defaultFlag = $cpuLvl80000001.Edx.ToCharArray()[$flagLocation]
			if($defaultFlag -eq &quot;-&quot;){
				$osDefault = $true
			}
		}
		else{
			$osDefault = $true
		}
		$cpuLvl80000001Amd = $mask | where {$_.Level -eq 0x80000001 -and $_.Vendor -eq &quot;amd&quot;}
		if($cpuLvl80000001Amd){
			$amdFlag = $cpuLvl80000001Amd.Edx.ToCharArray()[$flagLocation]
			if($amdFlag -eq &quot;-&quot;){
				$osDefaultAmd = $true
			}
		}
		else{
			$osDefaultAmd = $true
		}
	}
	else{
		$osDefault = $true
		$osDefaultAmd = $true
	}
	if($osDefault -or $osDefaultAmd){
		$flagLocation = 13
		$envBrowser = Get-View $vm.environmentBrowser
		$params = @($null,$null)
		$vmConfigOption = $envBrowser.GetType().GetMethod(&quot;QueryConfigOption&quot;).Invoke($envBrowser,$params)
		$mask = ($vmConfigOption.GuestOSDescriptor | where {$_.FullName -eq $vm.Config.GuestFullName}).CpuFeatureMask
		if($osDefault){
			$defaultFlag = ($mask | where {$_.Level -eq 0x80000001 -and !$_.Vendor}).Edx.ToCharArray()[$flagLocation]
		}
		if($osDefaultAmd){
			$amdFlag = ($mask | where {$_.Level -eq 0x80000001 -and $_.Vendor -eq &quot;amd&quot;}).Edx.ToCharArray()[$flagLocation]
		}
	}

	$row = &quot;&quot; | Select VMname, OSdefault,&quot;NX/XD flag&quot;,&quot;AMD OSdefault&quot;,&quot;AMD NX/XD flag&quot;
	$row.VMname = $vm.Name
	$row.OSdefault = $osDefault
	$row.&quot;NX/XD flag&quot; = &amp;{if($defaultFlag -eq &quot;0&quot;){&quot;hide&quot;}elseif($defaultFlag -eq &quot;H&quot;){&quot;expose&quot;}}
	$row.&quot;AMD OSdefault&quot; = $osDefaultAmd
	$row.&quot;AMD NX/XD flag&quot; = &amp;{if($amdFlag -eq &quot;0&quot;){&quot;hide&quot;}elseif($defaultFlag -eq &quot;H&quot;){&quot;expose&quot;}}
	$report += $row
}
$report | Sort-Object -Property VMname | ft -AutoSize -Force</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 3</strong>: The line excludes templates since these don&#8217;t have the notion of an NX/XD flag (yet). Once you deploy a new guest from the template, the OS default mask will be used.</p>
<p><strong>Line 8</strong>: If the mask hasn&#8217;t been set explicitly on the guest, the CpuFeatureMask property will be $null</p>
<p><strong>Line 9,37</strong>: The way the mask is represented in the VirtualMachine object and the way it is returned by the QueryConfigOption method is different, hence the different offsets to the location of the NX/XD bit.</p>
<p><strong>Line 14</strong>: If a bit is represented by a &#8220;-&#8221; character that means that the OS default is used.</p>
<p><strong>Line 40</strong>: A standard trick to allow the passing of <strong>empty strings</strong> as a parameter to an SDK method from within PowerShell.</p>
<h2>The report</h2>
<p>In the following sample report you can see several possibilities.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-flag-report.png"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-2226" title="nx-xd-flag-report" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-flag-report.png" alt="" width="479" height="171" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-flag-report.png 479w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-flag-report-300x107.png 300w" sizes="(max-width: 479px) 100vw, 479px" /></a></p>
<p>To following screenshots of the actual settings on these guests will clarify how to interprete the report.</p>
<h3><span style="background-color: #ccffcc;">PC11/PC13/PC15</span>: default configuration</h3>
<p>The <strong>OSdefault</strong> and <strong>AMD OSdefault</strong> columns tell you that the guest is using the OS specific defaults. In the guest&#8217;s settings you will see this.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc11.png"><img decoding="async" class="alignnone size-full wp-image-2227" title="nx-xd-pc11" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc11.png" alt="" width="323" height="237" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc11.png 323w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc11-300x220.png 300w" sizes="(max-width: 323px) 100vw, 323px" /></a></p>
<h3><span style="background-color: #99ccff;"><span style="color: #000000;">PC12</span></span>: customised, different AMD mask</h3>
<p>From the <strong>OSdefault</strong> and <strong>AMD OSdefault</strong> columns you can see that the settings were configured explicitly.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc12.png"><img decoding="async" class="alignnone size-full wp-image-2228" title="nx-xd-pc12" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc12.png" alt="" width="325" height="242" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc12.png 325w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-300x223.png 300w" sizes="(max-width: 325px) 100vw, 325px" /></a></p>
<p>From the <strong>NX/XD flag</strong> and <strong>AMD NX/XD flag</strong> columns you see  that different settings were used.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-800000011.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2230" title="nx-xd-pc12-80000001" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-800000011.png" alt="" width="278" height="174" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-800000011.png 348w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-800000011-300x187.png 300w" sizes="auto, (max-width: 278px) 100vw, 278px" /></a><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-80000001-amd.png"> <img loading="lazy" decoding="async" class="alignnone size-full wp-image-2231" title="nx-xd-pc12-80000001-amd" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-80000001-amd.png" alt="" width="285" height="178" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-80000001-amd.png 356w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc12-80000001-amd-300x187.png 300w" sizes="auto, (max-width: 285px) 100vw, 285px" /></a></p>
<h3><span style="background-color: #ff99cc;">PC14</span>: hide flag</h3>
<p>No OS defaults, flags manually set to hidden.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc14.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2232" title="nx-xd-pc14" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc14.png" alt="" width="327" height="241" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc14.png 327w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc14-300x221.png 300w" sizes="auto, (max-width: 327px) 100vw, 327px" /></a></p>
<h3><span style="background-color: #ffff99;">PC16</span>: flag in the regular mask from the OS default, flag in the AMD mask set manually</h3>
<p>From the <strong>OSdefault</strong> column you can see that the OS default was used.</p>
<p>From the <strong>AMD OSdefault</strong> column you see that this is a manual setting.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc16.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2234" title="nx-xd-pc16" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc16.png" alt="" width="319" height="238" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc16.png 319w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-300x223.png 300w" sizes="auto, (max-width: 319px) 100vw, 319px" /></a></p>
<p>And the flag settings for the regular and the AMD mask.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-800000011.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2235" title="nx-xd-pc16-80000001" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-800000011.png" alt="" width="283" height="174" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-800000011.png 354w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-800000011-300x184.png 300w" sizes="auto, (max-width: 283px) 100vw, 283px" /> </a><a href="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-80000001-amd.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2236" title="nx-xd-pc16-80000001-amd" src="https://lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-80000001-amd.png" alt="" width="287" height="176" srcset="https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-80000001-amd.png 359w, https://www.lucd.info/wp-content/uploads/2010/05/nx-xd-pc16-80000001-amd-300x183.png 300w" sizes="auto, (max-width: 287px) 100vw, 287px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2010/05/13/nxxd-flag-setting-report/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
