<?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>E1000E Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/e1000e/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/e1000e/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Tue, 20 Nov 2012 13:57:27 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>E1000E Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/e1000e/</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>Work with E1000E NICs in PowerCLI</title>
		<link>https://www.lucd.info/2012/11/16/work-with-e1000e-nics-in-powercli/</link>
					<comments>https://www.lucd.info/2012/11/16/work-with-e1000e-nics-in-powercli/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Fri, 16 Nov 2012 21:45:27 +0000</pubDate>
				<category><![CDATA[dvSwitch]]></category>
		<category><![CDATA[E1000E]]></category>
		<category><![CDATA[Guest OS]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[vSphere]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[Windows Server 2012]]></category>
		<category><![CDATA[NIC]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=4192</guid>

					<description><![CDATA[Now that Windows 8 and Windows Server 2012 are readily available , we [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Now that Windows 8 and Windows Server 2012 are readily available , we all want to do some exploring. But if you want to automate the creation of some test VMs for this, you are in for a surprise.</p>
<p>The current <a href="https://communities.vmware.com/community/vmtn/server/vsphere/automationtools/powercli?view=overview" target="_blank">PowerCLI 5.1 Release 1</a> doesn&#8217;t accept the <strong>E1000E</strong> NIC as a Type on the <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI51/html/New-NetworkAdapter.html" target="_blank">New-NetworkAdapter</a> cmdlet. Users start hitting this limitation, as can be seen on this PowerCLI Community <a href="https://communities.vmware.com/thread/425872?tstart=0" target="_blank">thread</a>. You can go for the <strong>E1000</strong>, but why settle for less if you can easily script the use of the E1000E NIC from PowerCLI?</p>
<p><img decoding="async" class="alignnone size-full wp-image-4194" title="Intel PRO/1000 CT Desktop Gigabit Ethernet Network Adapter PCI Express NIC" src="https://lucd.info/wp-content/uploads/2012/11/E1000E1.jpg" alt="" width="300" height="150" /></p>
<p>So even though <a href="https://twitter.com/esloof" target="_blank">Eric &#8220;the Scoop Meister&#8221; Sloof</a> debunked the <a href="https://www.ntpro.nl/blog/archives/1932-Myth-E1000-is-faster-than-VMXNET3.html" target="_blank">myth that the E1000/E1000E is faster than the VmxNet3</a>, the <strong>E1000E</strong> is the default NIC type that vSphere gives you when you create a VM for a Windows Server 2012 or Windows 8 VM. Note that the <strong>E1000</strong> apparently uses slightly more CPU resources than the <strong>E1000E</strong>. With the function in this post you can now automate this behavior.</p>
<p><strong><span style="background-color: #ffff00;">Update November 17th 2012</span></strong>: In <a href="https://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&amp;docType=kc&amp;externalId=2006859&amp;sliceId=2&amp;docTypeID=DT_KB_1_1&amp;dialogID=494484024&amp;stateId=1%200%20494482444">KB2006859</a> it seems to say that the <strong>VMXNET3</strong> NIC doesn&#8217;t work with <strong>Windows Server 2012</strong> or <strong>Windows 8</strong>. And there have been several blogs (including mine) that picked up this info. But after you apply the <strong>September 2012</strong> patch to your ESXi servers, you can also use a <strong>VMXNET3</strong> NIC for both Windows OS. See <a href="https://blogs.vmware.com/guestosguide/2012/09/windows-8-2.html" target="_blank">here</a> and <a href="https://blogs.vmware.com/guestosguide/2012/09/windows-server-2012-2.html" target="_blank">here</a> for more info.</p>
<p>Thanks to reader <a href="https://alpacapowered.wordpress.com/" target="_blank"><strong>alcapapower</strong></a> for drawing my attention to this (see his remark in the comments below).</p>
<p><span id="more-4192"></span></p>
<h2>The Script</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">function New-E1000ENic
{
&lt;#
.SYNOPSIS  Add an E1000E NIC to one or more VMs
.DESCRIPTION The function will add an E1000E NIC card to
  each VM that is passed.
.NOTES  Author:  Luc Dekens
.PARAMETER VM
  One or more virtual machines. This parameter accepts
  pipeline input.
.PARAMETER StartConnected
  Wether or not the device is connected when the VM starts
.PARAMETER MacAddress
  MAC address from the allowed range
.PARAMETER WakeOnLan
  Wether or not WOL is enabled on the NIC
.PARAMETER NetworkName
  Name of the network. This can be a portgroup name from a
  VirtualSwitch or from a DistributedSwitch
.PARAMETER DistributedSwitch
  Can only be used in combination with the PortKey.
.PARAMETER PortKey
  The port on the DistributedSwitch where the NIC shall
  connect to.
.EXAMPLE
  PS&gt; New-E1000ENic -VM MyVM -NetworkName pg1
.EXAMPLE
  PS&gt; Get-VM VM | New-E1000ENic -NetworkName pg1
.EXAMPLE
  PS&gt; New-E1000ENic -VM MyVM -DistributedSwitch sw1 -PortKey 100
#&gt;
  param(
    [CmdletBinding(DefaultParametersetName='VirtualSwitch')]
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [PSObject[]]$VM,
    [Switch]$StartConnected = $false,
    [String]$MacAddress,
    [Switch]$WakeOnLan = $false,
    [Parameter(ParameterSetName='NetworkName')]
    [String]$NetworkName,
    [Parameter(ParameterSetName='DistributedSwitch'Mandatory=$true,)]
    [PSObject]$DistributedSwitch,
    [Parameter(ParameterSetName='DistributedSwitch'Mandatory=$true,)]
    [PSObject]$PortKey
  )

  begin{
    $spec = New-Object VMware.Vim.VirtualMachineConfigSpec
    $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec
    $dev.Operation = &quot;add&quot;
    $dev.Device = New-Object VMware.Vim.VirtualE1000e
    $dev.Device.Connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo
    $dev.Device.Connectable.StartConnected = $StartConnected
    $dev.Device.WakeOnLanEnabled = $WakeOnLan
    switch ($PsCmdlet.ParameterSetName){
      &quot;NetworkName&quot; {
        $pg = Get-VirtualPortGroup -Name $networkName
        if($pg.ExtensionData -is [VMware.Vim.DistributedVirtualPortgroup]){
          $dvPort = New-Object VMware.Vim.VirtualEthernetCardDistributedVirtualPortBackingInfo
          $dvPort.port = New-Object VMware.Vim.DistributedVirtualSwitchPortConnection
          $dvPort.port.switchUuid = $pg.VirtualSwitch.ExtensionData.Uuid
          $dvPort.port.portgroupKey = $pg.Extensiondata.Key
          $dev.Device.Backing = $dvPort
        }
        else{
          $dev.Device.Backing = New-Object VMware.Vim.VirtualEthernetCardNetworkBackingInfo
          $dev.Device.Backing.DeviceName = $NetworkName
        }
      }
      &quot;DistributedSwitch&quot; {
        if($DistributedSwitch.GetType().Name -eq &quot;string&quot;){
          $DistributedSwitch = Get-VirtualSwitch -Distributed -Name $DistributedSwitch
        }
        $pg = Get-VirtualPortGroup -Distributed -VirtualSwitch $DistributedSwitch |
        where {$_.ExtensionData.Portkeys -contains $PortKey}
        if(!$pg){
          Write-Warning &quot;Portkey $PortKey not found on $DistributedSwitch.Name&quot;
          exit
        }
        $dvPort = New-Object VMware.Vim.VirtualEthernetCardDistributedVirtualPortBackingInfo
        $dvPort.port = New-Object VMware.Vim.DistributedVirtualSwitchPortConnection
        $dvPort.port.switchUuid = $dvSw.ExtensionData.Uuid
        $dvPort.port.portgroupKey = $pg.Extensiondata.Key
        $dvPort.port.portKey = $PortKey
        $dev.Device.Backing = $dvPort
      }
    }
    if($MacAddress){
      $dev.Device.MacAddress = $MacAddress
    }
    $spec.deviceChange += $dev
  }

  process{
    foreach($client in $VM){
      if($client.GetType().Name -eq &quot;string&quot;){
        $client = Get-VM -Name $client
      }
      if($client.Version -eq &quot;v8&quot;){
        $client.ExtensionData.ReconfigVM($spec)
        if($PortKey){
          $spec.DeviceChange[0].Device.Backing.port.PortKey =
            [int]$spec.DeviceChange[0].Device.Backing.port.PortKey + 1
        }
      }
      else{
        Write-Warning &quot;$client.Name is not HW version 8&quot;
      }
    }
  }
}</pre><p></p>
<h4>Annotation</h4>
<p><strong>Line 39-44</strong>: The function supports two parametersets, <strong>NetworkName</strong> and <strong>DistributedSwitch</strong>. The parameters NetworkName and DistributedSwitch/PortKey belong to different parametersets and can not be used together.</p>
<p><strong>Line 47-91</strong>: The <a href="https://pubs.vmware.com/vsphere-50/topic/com.vmware.wssdk.apiref.doc_50/vim.vm.ConfigSpec.html" target="_blank">VirtualMachineConfigSpec</a> parameter for the <a href="https://pubs.vmware.com/vsphere-50/topic/com.vmware.wssdk.apiref.doc_50/vim.VirtualMachine.html#reconfigure">ReconfigVM_Task</a> method is the same for each call, except for the PortKey property (if it is used). For this reason the object is created and configured in the Begin section of the function.</p>
<p><strong>Line 55</strong>: Depending on the parameterset used, different properties need to be set.</p>
<p><strong>Line 58</strong>: If the <strong>NetworkName</strong> is for a portgroup on a <strong>DistributedSwitch</strong> other pproperties need to be set.</p>
<p><strong>Line 71-73</strong>,<strong> 95-97</strong>: A simple implementation of Object By Name</p>
<p><strong>Line 76-79</strong>: If the function gets a <strong>PortKey</strong> that can not be mapped to a PortGroup, the function will exit.</p>
<p><strong>Line 99</strong>: The use of an E1000E NIC requires that the VM is at least on hardware <strong>version 8</strong>.</p>
<p><strong>Line 101-104</strong>: If the function is used to add an E1000E NIC on multiple VMs, and if the PortKey parameter is used, the function will automatically take the next portnumber. Make sure that there are enough free ports available to accommodate all the VMs you pass to the function.</p>
<h2>Sample run</h2>
<p>The function can be used in several ways.</p>
<p>You can call it by passing a <strong>NetworkName</strong> parameter.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$vm = Get-VM -Name W2K12
New-E1000ENic -VM $vm -NetworkName Net1 -StartConnected</pre><p></p>
<p><img fetchpriority="high" decoding="async" class="alignnone  wp-image-4209" title="E1000E-1" src="https://lucd.info/wp-content/uploads/2012/11/E1000E-11.png" alt="" width="546" height="317" srcset="https://www.lucd.info/wp-content/uploads/2012/11/E1000E-11.png 682w, https://www.lucd.info/wp-content/uploads/2012/11/E1000E-11-300x174.png 300w" sizes="(max-width: 546px) 100vw, 546px" /></p><pre class="urvanov-syntax-highlighter-plain-tag"></pre><p>And you can also use the function in a pipeline construct.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Get-VM -Name W2K12* |
New-E1000ENic -NetworkName Net1 -StartConnected</pre><p></p>
<p>The <strong>NetworkName</strong> parameter can also point to a portgroup on a DistributedSwitch</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$vm = Get-VM -Name W2K12

New-E1000ENic -VM $vm -NetworkName dvPg1 -WakeOnLan -StartConnected</pre><p></p>
<p><img decoding="async" class="alignnone  wp-image-4208" title="E1000E-2" src="https://lucd.info/wp-content/uploads/2012/11/E1000E-21.png" alt="" width="455" height="197" srcset="https://www.lucd.info/wp-content/uploads/2012/11/E1000E-21.png 569w, https://www.lucd.info/wp-content/uploads/2012/11/E1000E-21-300x129.png 300w" sizes="(max-width: 455px) 100vw, 455px" /></p><pre class="urvanov-syntax-highlighter-plain-tag"></pre><p>You can specify a specific port with the <strong>PortKey</strong> parameter. Note that this parameter always needs to be used together with the <strong>DistributedSwitch</strong> parameter.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$vm = Get-VM -Name W2K12
$dvSw = Get-VirtualSwitch -Distributed -Name dvSw1

New-E1000ENic -VM $vm -DistributedSwitch $dvSw -PortKey 101 -StartConnected</pre><p></p>
<p>The function increments the <strong>PortKey</strong> by 1 if you call the function for more than 1 VM. Make sure there are enough <strong>free ports</strong>, starting from the port you pass in PortKey, to accommodate all the VM for which you call the function.</p>
<p>My <a href="https://www.lucd.info/2012/02/14/dvswitch-scripting-part-12-find-free-ports/" target="_blank">dvSwitch scripting – Part 12 – Find free ports</a> post might come in handy here <img decoding="async" src="https://lucd.info/wp-includes/images/smilies/icon_smile.gif" alt=":-)" /></p>
<p><img loading="lazy" decoding="async" class="alignnone  wp-image-4207" title="E1000E-3" src="https://lucd.info/wp-content/uploads/2012/11/E1000E-31.png" alt="" width="412" height="208" srcset="https://www.lucd.info/wp-content/uploads/2012/11/E1000E-31.png 515w, https://www.lucd.info/wp-content/uploads/2012/11/E1000E-31-300x151.png 300w" sizes="auto, (max-width: 412px) 100vw, 412px" /></p>
<p>Enjoy !</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2012/11/16/work-with-e1000e-nics-in-powercli/feed/</wfw:commentRss>
			<slash:comments>6</slash:comments>
		
		
			</item>
	</channel>
</rss>
