<?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>vMotion Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/vmotion/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/vmotion/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 08 Apr 2020 11:03:22 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.5</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>vMotion Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/vmotion/</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>Get the vMotion/svMotion history</title>
		<link>https://www.lucd.info/2013/03/31/get-the-vmotionsvmotion-history/</link>
					<comments>https://www.lucd.info/2013/03/31/get-the-vmotionsvmotion-history/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Sun, 31 Mar 2013 00:53:45 +0000</pubDate>
				<category><![CDATA[event]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[report]]></category>
		<category><![CDATA[SDRS]]></category>
		<category><![CDATA[vMotion]]></category>
		<category><![CDATA[Get-VIEvent]]></category>
		<category><![CDATA[svMotion]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=4405</guid>

					<description><![CDATA[The availability of vMotion and svMotion, provided you have a license that allows [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The availability of vMotion and svMotion, provided you have a license that allows it, in vSphere are some of its key features.</p>
<p>The DRS and SDRS functionality will use vMotion and svMotion to better use the available resources.</p>
<p>And you as a vSphere administrator can use it to facilitate your work. Just think of how easy patching or datastorecluster maintenance becomes with the help of these two features.<br />
But as an administrator you want to be able to report on what vMotion and svMotion have been doing over a specific time interval in your vSphere environment.</p>
<p>In the past I already provided a vMotion reporting tool in <a href="https://www.lucd.info/2010/06/22/events-part-8-vmotion-history/" target="_blank">Events – Part 8 – vMotion history</a>, but now it was time to provide a universal (s)vMotion reporting feature.</p>
<p style="padding-left: 60px;"><a href="https://www.lucd.info/2013/03/31/get-the-vmotionsvmotion-history/motion-reports/" rel="attachment wp-att-4408"><img fetchpriority="high" decoding="async" class="wp-image-4408 alignnone" alt="motion-reports" src="https://lucd.info/wp-content/uploads/2013/03/motion-reports.png" width="400" height="142" srcset="https://www.lucd.info/wp-content/uploads/2013/03/motion-reports.png 781w, https://www.lucd.info/wp-content/uploads/2013/03/motion-reports-300x107.png 300w" sizes="(max-width: 400px) 100vw, 400px" /></a></p>
<p><strong><span style="background-color: #ffff00;">Update October 29th 2013</span></strong>: added additional parameters to the <strong>Get-VIEventPlus</strong> function</p>
<ul>
<li><strong>User</strong>: one or more users for which to return the events</li>
<li><strong>System</strong>: a switch to return all system user events</li>
<li><strong>ScheduledTask</strong>: return all events for a specific Scheduled Task</li>
</ul>
<p><strong><span style="background-color: #ffff00;">Update February 10th 2014</span></strong>: it&#8217;s always nice to see another implementation based on one of your scripts. The <a href="https://opvizor.com/" target="_blank">Opvizor</a> solution will soon contain this function, see <a href="https://communities.vmware.com/docs/DOC-24500" target="_blank">Dennis Zimmer</a>&#8216;s post called <a href="https://opvizor.com/storage-vmotion-activities-report/" target="_blank">Storage vMotion Activities Report</a> !<span id="more-4405"></span></p>
<h2>The Script</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">function Get-VIEventPlus {
&lt;#   
.SYNOPSIS  Returns vSphere events    
.DESCRIPTION The function will return vSphere events. With
    the available parameters, the execution time can be
   improved, compered to the original Get-VIEvent cmdlet. 
.NOTES  Author:  Luc Dekens   
.PARAMETER Entity
   When specified the function returns events for the
   specific vSphere entity. By default events for all
   vSphere entities are returned. 
.PARAMETER EventType
   This parameter limits the returned events to those
   specified on this parameter. 
.PARAMETER Start
   The start date of the events to retrieve 
.PARAMETER Finish
   The end date of the events to retrieve. 
.PARAMETER Recurse
   A switch indicating if the events for the children of
   the Entity will also be returned 
.PARAMETER User
   The list of usernames for which events will be returned 
.PARAMETER System
   A switch that allows the selection of all system events. 
.PARAMETER ScheduledTask
   The name of a scheduled task for which the events
   will be returned 
.PARAMETER FullMessage
   A switch indicating if the full message shall be compiled.
   This switch can improve the execution speed if the full
   message is not needed.   
.EXAMPLE
   PS&gt; Get-VIEventPlus -Entity $vm
.EXAMPLE
   PS&gt; Get-VIEventPlus -Entity $cluster -Recurse:$true
#&gt;

  param(
    [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$Entity,
    [string[]]$EventType,
    [DateTime]$Start,
    [DateTime]$Finish = (Get-Date),
    [switch]$Recurse,
    [string[]]$User,
    [Switch]$System,
    [string]$ScheduledTask,
    [switch]$FullMessage = $false
  )

  process {
    $eventnumber = 100
    $events = @()
    $eventMgr = Get-View EventManager
    $eventFilter = New-Object VMware.Vim.EventFilterSpec
    $eventFilter.disableFullMessage = ! $FullMessage
    $eventFilter.entity = New-Object VMware.Vim.EventFilterSpecByEntity
    $eventFilter.entity.recursion = &amp;{if($Recurse){&quot;all&quot;}else{&quot;self&quot;}}
    $eventFilter.eventTypeId = $EventType
    if($Start -or $Finish){
      $eventFilter.time = New-Object VMware.Vim.EventFilterSpecByTime
    if($Start){
        $eventFilter.time.beginTime = $Start
    }
    if($Finish){
        $eventFilter.time.endTime = $Finish
    }
    }
  if($User -or $System){
    $eventFilter.UserName = New-Object VMware.Vim.EventFilterSpecByUsername
    if($User){
      $eventFilter.UserName.userList = $User
    }
    if($System){
      $eventFilter.UserName.systemUser = $System
    }
  }
  if($ScheduledTask){
    $si = Get-View ServiceInstance
    $schTskMgr = Get-View $si.Content.ScheduledTaskManager
    $eventFilter.ScheduledTask = Get-View $schTskMgr.ScheduledTask |
      where {$_.Info.Name -match $ScheduledTask} |
      Select -First 1 |
      Select -ExpandProperty MoRef
  }
  if(!$Entity){
    $Entity = @(Get-Folder -Name Datacenters)
  }
  $entity | %{
      $eventFilter.entity.entity = $_.ExtensionData.MoRef
      $eventCollector = Get-View ($eventMgr.CreateCollectorForEvents($eventFilter))
      $eventsBuffer = $eventCollector.ReadNextEvents($eventnumber)
      while($eventsBuffer){
        $events += $eventsBuffer
        $eventsBuffer = $eventCollector.ReadNextEvents($eventnumber)
      }
      $eventCollector.DestroyCollector()
    }
    $events
  }
}

function Get-MotionHistory {
&lt;#   
.SYNOPSIS  Returns the vMotion/svMotion history    
.DESCRIPTION The function will return information on all
   the vMotions and svMotions that occurred over a specific
    interval for a defined number of virtual machines 
.NOTES  Author:  Luc Dekens   
.PARAMETER Entity
   The vSphere entity. This can be one more virtual machines,
   or it can be a vSphere container. If the parameter is a
    container, the function will return the history for all the
   virtual machines in that container. 
.PARAMETER Days
   An integer that indicates over how many days in the past
   the function should report on. 
.PARAMETER Hours
   An integer that indicates over how many hours in the past
   the function should report on. 
.PARAMETER Minutes
   An integer that indicates over how many minutes in the past
   the function should report on. 
.PARAMETER Sort
   An switch that indicates if the results should be returned
   in chronological order. 
.EXAMPLE
   PS&gt; Get-MotionHistory -Entity $vm -Days 1
.EXAMPLE
   PS&gt; Get-MotionHistory -Entity $cluster -Sort:$false
.EXAMPLE
   PS&gt; Get-Datacenter -Name $dcName |
   &gt;&gt; Get-MotionHistory -Days 7 -Sort:$false
#&gt;

  param(
    [CmdletBinding(DefaultParameterSetName=&quot;Days&quot;)]
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [VMware.VimAutomation.ViCore.Impl.V1.Inventory.InventoryItemImpl[]]$Entity,
    [Parameter(ParameterSetName='Days')]
    [int]$Days = 1,
    [Parameter(ParameterSetName='Hours')]
    [int]$Hours,
    [Parameter(ParameterSetName='Minutes')]
    [int]$Minutes,
    [switch]$Recurse = $false,
    [switch]$Sort = $true
  )

  begin{
    $history = @()
    switch($psCmdlet.ParameterSetName){
      'Days' {
        $start = (Get-Date).AddDays(- $Days)
      }
      'Hours' {
        $start = (Get-Date).AddHours(- $Hours)
      }
      'Minutes' {
        $start = (Get-Date).AddMinutes(- $Minutes)
      }
    }
    $eventTypes = &quot;DrsVmMigratedEvent&quot;,&quot;VmMigratedEvent&quot;
  }

  process{
    $history += Get-VIEventPlus -Entity $entity -Start $start -EventType $eventTypes -Recurse:$Recurse |
    Select CreatedTime,
    @{N=&quot;Type&quot;;E={
        if($_.SourceDatastore.Name -eq $_.Ds.Name){&quot;vMotion&quot;}else{&quot;svMotion&quot;}}},
    @{N=&quot;UserName&quot;;E={if($_.UserName){$_.UserName}else{&quot;System&quot;}}},
    @{N=&quot;VM&quot;;E={$_.VM.Name}},
    @{N=&quot;SrcVMHost&quot;;E={$_.SourceHost.Name.Split('.')[0]}},
    @{N=&quot;TgtVMHost&quot;;E={if($_.Host.Name -ne $_.SourceHost.Name){$_.Host.Name.Split('.')[0]}}},
    @{N=&quot;SrcDatastore&quot;;E={$_.SourceDatastore.Name}},
    @{N=&quot;TgtDatastore&quot;;E={if($_.Ds.Name -ne $_.SourceDatastore.Name){$_.Ds.Name}}}
  }

  end{
    if($Sort){
      $history | Sort-Object -Property CreatedTime
    }
    else{
      $history
    }
  }
}</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 1-101</strong>: The <strong>Get-VIEventPlus</strong> function. This function adds some improvements, at least for me, to the current <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/Get-VIEvent.html" target="_blank">Get-VIEvent</a> cmdlet. It allows you to specify which specific events to return and it allows you to use a &#8216;recursive&#8217; search for events starting from the &#8216;Entity&#8217;.</p>
<p><strong>Line 52</strong>: The function uses the <a href="https://pubs.vmware.com/vsphere-51/topic/com.vmware.wssdk.apiref.doc/vim.event.EventHistoryCollector.html" target="_blank">EventHistoryCollector</a>. Access to the found events is through a &#8216;<em>sliding</em>&#8216; window. This variable defines the size of that sliding window. From my average use, I came to the conclusion that 100 events is a workable size for this window. But your mileage may vary.</p>
<p><strong>Line 55-85</strong>: These lines are the hearth of the function. In here the &#8216;<em>filter</em>&#8216; is specified for the events to search for. See the <a href="https://pubs.vmware.com/vsphere-51/topic/com.vmware.wssdk.apiref.doc/vim.event.EventFilterSpec.html" target="_blank">EventFilterSpec</a> objects for the details.</p>
<p><strong>Line 89</strong>: The <a href="https://pubs.vmware.com/vsphere-51/topic/com.vmware.wssdk.apiref.doc/vim.event.EventFilterSpec.html" target="_blank">EventFilterSpec</a> can hold only one MoRef. So if multiple entities are passed, they will have be handled one by one. This makes a big difference in execution time when you do not select the value for the Entity parameter correctly. See later.</p>
<p><strong>Line 93-96</strong>: This While construction reads all the found events.</p>
<p><strong>Line 103-187</strong>: The <strong>Get-MotionHistory</strong> function. This function uses the Get-VIEventPlus function to retrieve specific events. The returned events are used to report on all the vMotions and svMotions.</p>
<p><strong>Line 140-145</strong>: The function has 3 parametersets, each indicating a specific type of interval (Days/Hours/Minutes). The default is 1 day back in time.</p>
<p><strong>Line 151</strong>: Since the function supports pipeline input, the history records it creates must be stored in an array until all pipeline objects have been handled.</p>
<p><strong>Line 152-162</strong>: The 3 parametersets are handled with a Switch statement, and the Start parameter for the <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/Get-VIEvent.html" target="_blank">Get-VIEvent</a> cmdlet is calculated accordingly.</p>
<p><strong>Line 163</strong>: For the (s)vMotion history the function only needs these 2 types of events.</p>
<p><strong>Line 171</strong>: The vMotion and or svMotion actions can be user invoked or system invoked (DRS/SDRS)</p>
<p><strong>Line 173-176</strong>: Depending on the type of &#8216;<em>motion</em>&#8216;, the functions will include a target host or target datastore.</p>
<h2>Sample Usage</h2>
<p>The <strong>Get-MotionHistory</strong> function is quite simple to use as the following example will show.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Get-MotionHistory -Entity (Get-VM VM*) -Days 1 |
Export-Csv C:\motion-report1.csv -NoTypeINformation -UseCulture</pre><p></p>
<p>The content of the produced CSV looks like this.</p>
<p><a href="https://www.lucd.info/2013/03/31/get-the-vmotionsvmotion-history/motion-report1/" rel="attachment wp-att-4413"><img decoding="async" class="alignnone  wp-image-4413" alt="motion-report1" src="https://lucd.info/wp-content/uploads/2013/03/motion-report1.png" width="434" height="215" srcset="https://www.lucd.info/wp-content/uploads/2013/03/motion-report1.png 723w, https://www.lucd.info/wp-content/uploads/2013/03/motion-report1-300x148.png 300w" sizes="(max-width: 434px) 100vw, 434px" /></a></p>
<p>When you use the <strong>Get-MotionHistory</strong> take care of what you pass on the <strong>Entity</strong> parameter !</p>
<p>The following calls will produce the same result.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Get-Cluster -Name Cluster1 | Get-MotionHistory -Hours 4 -Recurse:$true</pre><p></p>
<p>as this one</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Get-Cluster -Name Cluster1 | Get-VM | Get-MotionHistory -Hours 4</pre><p></p>
<p>But the difference between these two calls of the function is the <strong>execution time</strong>. The second method was <strong><span style="background-color: #ff99cc;">80 times slower</span></strong> compared to the first method in my test environment, where there are about 100 VMs in that cluster.</p>
<p>The reason is that the <strong>Get-VIEventPlus</strong> function has to call the <a href="https://pubs.vmware.com/vsphere-51/topic/com.vmware.wssdk.apiref.doc/vim.event.EventHistoryCollector.html" target="_blank">EventHistoryCollector</a> for each VM in the 2nd method, while it is only called once in the 1st method !</p>
<p>That is also the main reason I introduced the <strong>Recurse</strong> parameter on the <strong>Get-VIEventPlus</strong> function. A feature that is sadly missing on the <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/Get-VIEvent.html" target="_blank">Get-VIEvent</a> cmdlet <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f625.png" alt="😥" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p>If you want to have a report for a specific set of VMs in a cluster, it is most probably better to call the <strong>Get-MotionHistory</strong> function for the complete cluster with the Recurse switch set to $true, and filter out the required VMs from the produced result. Something like this for example</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">Get-Cluster -Name Cluster1 | Get-MotionHistory -Hours 4 -Recurse:$true |
Where {$_.VM -like &quot;VM*&quot;}</pre><p></p>
<p>Enjoy !</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2013/03/31/get-the-vmotionsvmotion-history/feed/</wfw:commentRss>
			<slash:comments>89</slash:comments>
		
		
			</item>
		<item>
		<title>vSphere 5 Top 10 &#8211; vMotion</title>
		<link>https://www.lucd.info/2011/12/15/vsphere-5-top-10-vmotion/</link>
					<comments>https://www.lucd.info/2011/12/15/vsphere-5-top-10-vmotion/#respond</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Wed, 14 Dec 2011 23:12:36 +0000</pubDate>
				<category><![CDATA[2011]]></category>
		<category><![CDATA[Dutch]]></category>
		<category><![CDATA[multi-nic]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[vMotion]]></category>
		<category><![CDATA[VMUG]]></category>
		<category><![CDATA[vSphere]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=3734</guid>

					<description><![CDATA[Another post coming from our Dutch VMUG Event 2011 presentation. On position number [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Another post coming from our <a href="https://vmug.nl/cms/index.php?option=com_content&amp;view=section&amp;layout=blog&amp;id=5&amp;Itemid=55" target="_blank" rel="noopener noreferrer">Dutch VMUG Event 2011 presentation</a>. On position number <strong>10</strong>, we find the <strong>vMotion Enhancements</strong> that were introduced with <strong>vSphere 5</strong>.</p>
<p>A single vMotion can now<strong> scale</strong> over multiple NICs. This feature can use a <strong>regular vSwitch</strong> or <strong>distributed vSwitch</strong>.On YouTube there are 2 videos, uploaded by <a href="https://www.youtube.com/user/VMwareKB" target="_blank" rel="noopener noreferrer">VMwareKB</a>, that show how to configure such a vMotion enabled multi-NIC vSwitch, regular and distributed.</p>
<p>Very useful videos, but as you can imagine, I wanted to automate this. No GUI clicking for me  <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f609.png" alt="😉" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p><span id="more-3734"></span></p>
<h2>The script</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">function Set-vMotionMultiNic{
&lt;#
.SYNOPSIS  Configure multi-NIC vMotion
.DESCRIPTION The function will configure multi-NIC vMotion
  enabled portgroups on a regular vSwitch 
.NOTES  Author:  Luc Dekens
.PARAMETER VMHost
  The ESXi host where the vMotion enabled portgroups shall be
  configured.
  The parameter accepts a string or the object returned by the
  Get-VMHost cmdlet.
.PARAMETER VirtualSwitch
  The virtual switch on which the vMotion enabled portgroups
  shall be configured.
  The parameter accepts a string or the object returned by the
  Get-VirtualSwitch cmdlet.
.PARAMETER pNic
  An array with the vnics that shall be used to configure the
  portgroups. Depending on the number of provided vnics, the
  function will create the optimal number of portgroups.
  The arrays on pNic, IPaddress and SubnetMask shall have the
  same number of elements.
.PARAMETER IpAddress
  An array with the IP addresses that shall be used on the
  portgroups
.PARAMETER SubnetMask
  An array with the subnetmasks.
.EXAMPLE
  PS&gt; Set-vMotionMultiNic -VMHost MyESX -VSwitch MyvSw `
  PS&gt;&gt;   -pNic &quot;vmnic2&quot;,&quot;vmnic3&quot;,&quot;vmnic4&quot; `
  PS&gt;&gt;   -IpAddress &quot;192.168.1.1&quot;,&quot;192.168.1.2&quot;,&quot;192.168.1.3&quot; `
  PS&gt;&gt;   -SubnetMask (,&quot;255.255.255.0&quot; * 3)
#&gt;
  param(
    [psobject]$VMHost,
    [psobject]$VirtualSwitch,
    [string[]]$pNic,
    [string[]]$IpAddress,
    [string[]]$SubnetMask
  )56
  
  if($VMHost.getType().Name -eq &quot;string&quot;){
    $VMHost = Get-VMHost -Name $VMHost
  }
  if($VMHost.ApiVersion.Split('.')[0] -lt 5){
    Write-Warning &quot;MultiNic for vMotion requires at least ESXi 5.0&quot;
    exit
  }

  if($VirtualSwitch.getType().Name -eq &quot;string&quot;){
    $VirtualSwitch = $VMHost | Get-VirtualSwitch -Name $VirtualSwitch
  }
  $indices = 0..($pNic.Count - 1)
  foreach($i in $indices){
    $pg = New-VirtualPortGroup -Name (&quot;vMotion-{0:d2}&quot; -f ($i + 1)) -VirtualSwitch $VirtualSwitch
    New-VMHostNetworkAdapter -VMHost $VMHost -VirtualSwitch $VirtualSwitch -PortGroup $pg -IP $IpAddress[$i] -SubnetMask $SubnetMask[$i] -VMotionEnabled:$true | Out-Null
    Get-NicTeamingPolicy -VirtualPortGroup $pg | 
    Set-NicTeamingPolicy -MakeNicActive $pNic[$i] -MakeNicStandby $pNic[($indices | where {$_ -ne $i})] |Out-Null
  }
}</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 42-44</strong>: A simple Object By Name (OBN) implementation for the ESXi host</p>
<p><strong>Line 45-48</strong>: A check if we are configuring this for at least a vSphere 5 server</p>
<p><strong>Line 50-52</strong>: A simple Object By Name (OBN) implementation for the regular vSwitch</p>
<p><strong>Line 53</strong>: When the function is called with &#8216;n&#8217; vnics, it will have to create &#8216;n&#8217; portgroups. This calculation creates the list of suffixes that will be used on the portgroup names.</p>
<p><strong>Line 55</strong>: The creation of the portgroup. Note how the function adds a 2 digit suffix with the -format operator to the basename (&#8216;vMotion&#8217;)</p>
<p><strong>Line 56</strong>: Set the IP address and subnetmask</p>
<p><strong>Line 57-58</strong>: The Teaming is configured in the same way the VMwareKB video demonstrates.</p>
<h2>Sample use</h2>
<p>To demonstrate the function, I will use a simple configuration. We have 1 regular vSwitch that has 3 vnics connected to it.</p>
<p><a href="https://lucd.info/wp-content/uploads/2011/12/vMotion-vsw-before.png"><img decoding="async" class="alignnone size-full wp-image-3740" title="vMotion-vsw-before" src="https://lucd.info/wp-content/uploads/2011/12/vMotion-vsw-before.png" alt="" width="476" height="172" srcset="https://www.lucd.info/wp-content/uploads/2011/12/vMotion-vsw-before.png 476w, https://www.lucd.info/wp-content/uploads/2011/12/vMotion-vsw-before-300x108.png 300w" sizes="(max-width: 476px) 100vw, 476px" /></a></p>
<p>We call the function</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$IP = &quot;192.168.0.210&quot;,&quot;192.168.0.211&quot;,&quot;192.168.0.212&quot;
$MASK = &quot;255.255.255.0&quot;,&quot;255.255.255.0&quot;,&quot;255.255.255.0&quot;
$NIC = &quot;vmnic1&quot;,&quot;vmnic2&quot;,&quot;vmnic3&quot;

Set-vMotionMultiNic -VMHost 192.168.0.107 -VirtualSwitch vSwitch1 -pNic $NIC -IPAddress $IP -SubnetMask $MASK</pre><p></p>
<p>The function creates the vMotion portgroups (in the same way as the VMwareKB video shows).</p>
<p><a href="https://lucd.info/wp-content/uploads/2011/12/vMotion-vsw-after.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3742" title="vMotion-vsw-after" src="https://lucd.info/wp-content/uploads/2011/12/vMotion-vsw-after.png" alt="" width="587" height="222" srcset="https://www.lucd.info/wp-content/uploads/2011/12/vMotion-vsw-after.png 587w, https://www.lucd.info/wp-content/uploads/2011/12/vMotion-vsw-after-300x113.png 300w" sizes="auto, (max-width: 587px) 100vw, 587px" /></a></p>
<p>And each of these vMotion enabled portgroups is configured similar to the method shown in the video.</p>
<p><a href="https://lucd.info/wp-content/uploads/2011/12/vMotion-vsw-detail.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-3743" title="vMotion-vsw-detail" src="https://lucd.info/wp-content/uploads/2011/12/vMotion-vsw-detail.png" alt="" width="254" height="439" srcset="https://www.lucd.info/wp-content/uploads/2011/12/vMotion-vsw-detail.png 423w, https://www.lucd.info/wp-content/uploads/2011/12/vMotion-vsw-detail-173x300.png 173w" sizes="auto, (max-width: 254px) 100vw, 254px" /></a></p>
<p>In a following post I will show how this can be done for a dvSwitch.</p>
<p>Enjoy !</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2011/12/15/vsphere-5-top-10-vmotion/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Events &#8211; Part 8 &#8211; vMotion history</title>
		<link>https://www.lucd.info/2010/06/22/events-part-8-vmotion-history/</link>
					<comments>https://www.lucd.info/2010/06/22/events-part-8-vmotion-history/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Tue, 22 Jun 2010 21:44:41 +0000</pubDate>
				<category><![CDATA[event]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[vMotion]]></category>
		<category><![CDATA[vSphere]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[SDK]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=2385</guid>

					<description><![CDATA[Another idea triggered by a post in the PowerCLI Community. Lars wanted to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Another idea triggered by a post in the <a href="https://communities.vmware.com/community/vmtn/vsphere/automationtools/powercli" target="_blank">PowerCLI Community</a>. <strong>Lars</strong> wanted to know <a href="https://communities.vmware.com/thread/273355?tstart=0" target="_blank">where his VMs had been running</a> in the past.</p>
<p>Since <strong>vSphere</strong> doesn&#8217;t maintain any historical data with the guests themselves, we have to fall back on the <strong>Tasks and Events</strong> to create such a report. The basic algorithm to query the tasks, and their related events, is already published in <a href="https://www.lucd.info/2009/12/18/events-part-3-auditing-vm-device-changes/" target="_blank">Events – Part 3 : Auditing VM device changes</a>. But to get a historical record of the servers where your guests have been hosted requires a bit more logic in the script.</p>
<h2><span id="more-2385"></span>The script</h2>
<p>There are 2 distinct parts in the script.</p>
<ol>
<li>Get all the vMotion tasks. A <strong>vMotion</strong> can be <strong>user</strong>&#8211; or <strong>DRS</strong>-initiated. These produce different tasks.</li>
<li>Compile the final report by only looking at the <strong>selected guests</strong></li>
</ol>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$hours = 24 # Number of hours back
$start = (Get-Date).AddHours(-$hours)
$tasknumber = 999 # Windowsize for task collector
$eventnumber = 100 # Windowsize for event collector
$tgtTaskDescriptions = &quot;VirtualMachine.migrate&quot;,&quot;Drm.ExecuteVMotionLRO&quot;
$migrations = @()
$report = @()

# Get the guest for which we want the report
$vmHash = @{}
Get-Datacenter -Name &quot;MyDC&quot; | Get-VM | %{
	$vmHash[$_.Name] = $_.Host
}

# Retrieve the vMotion tasks and the corresponding events
$taskMgr = Get-View TaskManager
$eventMgr = Get-View eventManager

$tFilter = New-Object VMware.Vim.TaskFilterSpec
$tFilter.Time = New-Object VMware.Vim.TaskFilterSpecByTime
$tFilter.Time.beginTime = $start
$tFilter.Time.timeType = &quot;startedTime&quot;

$tCollector = Get-View ($taskMgr.CreateCollectorForTasks($tFilter))

$dummy = $tCollector.RewindCollector
$tasks = $tCollector.ReadNextTasks($tasknumber)

while($tasks){
	$tasks | where {$tgtTaskDescriptions -contains $_.DescriptionId} | % {
		$task = $_
		$eFilter = New-Object VMware.Vim.EventFilterSpec
		$eFilter.eventChainId = $task.EventChainId

		$eCollector = Get-View ($eventMgr.CreateCollectorForEvents($eFilter))
		$events = $eCollector.ReadNextEvents($eventnumber)
		while($events){
			$events | % {
				$event = $_
				switch($event.GetType().Name){
					&quot;VmBeingHotMigratedEvent&quot; {
						$migrations += New-Object PSObject -Property @{
							VMname = $task.EntityName
							Source = $event.Host.Name
							Destination = $event.DestHost.Name
							Start = $task.StartTime
							Finish = $task.CompleteTime
							Result = $task.State
							User = $task.Reason.UserName
							DRS = &amp;{if($task.DescriptionId -like &quot;Drm.*&quot;){$true}else{$false}}
						}
					}
					Default {}
				}
			}
			$events = $eCollector.ReadNextEvents($eventnumber)
		}
		$ecollection = $eCollector.ReadNextEvents($eventnumber)
# By default 32 event collectors are allowed. Destroy this event collector.
		$eCollector.DestroyCollector()
	}
	$tasks = $tCollector.ReadNextTasks($tasknumber)
}

# By default 32 task collectors are allowed. Destroy this task collector.
$tCollector.DestroyCollector()

# Handle the guests that have been vMotioned
$grouped = $migrations | Group-Object -Property VMname
$grouped | Sort-Object -Property Count -Descending | where{$vmHash.ContainsKey($_.Name)} | %{
	$i = 1
	$row = New-Object PSObject
	Add-Member -InputObject $row -Name VM -Value $_.Name -MemberType NoteProperty
	$_.Group | Sort-Object -Property Finish | %{
# The original location of the guest
		if($i -eq 1){
			Add-Member -InputObject $row -Name (&quot;Time&quot; + $i) -Value $start -MemberType NoteProperty
			Add-Member -InputObject $row -Name (&quot;Host&quot; + $i) -Value $_.Source -MemberType NoteProperty
			$i++
		}
# All the vMotion destinations
		Add-Member -InputObject $row -Name (&quot;Time&quot; + $i) -Value $_.Finish -MemberType NoteProperty
		Add-Member -InputObject $row -Name (&quot;Host&quot; + $i) -Value $_.Destination -MemberType NoteProperty
		Add-Member -InputObject $row -Name (&quot;DRS&quot; + $i) -Value $_.DRS -MemberType NoteProperty
		Add-Member -InputObject $row -Name (&quot;User&quot; + $i) -Value $_.User -MemberType NoteProperty
		$i++
	}
	$report += $row
	$vmHash.Remove($_.Name)
}

# Add remaining guests to report
$vmHash.GetEnumerator() | %{
	$row = New-Object PSObject
	Add-Member -InputObject $row -Name VM -Value $_.Name -MemberType NoteProperty
	Add-Member -InputObject $row -Name Time1 -Value $start -MemberType NoteProperty
	Add-Member -InputObject $row -Name Host1 -Value $_.Value -MemberType NoteProperty
	Add-Member -InputObject $row -Name DRS1 -Value $false -MemberType NoteProperty
	$report += $row
}

$report | Export-Csv &quot;C:\vMotion-history.csv&quot; -NoTypeInformation -UseCulture</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 1-2</strong>: Specify how far back you want to report on through the <strong>$start</strong> variable</p>
<p><strong>Line 5</strong>: The vMotion tasks can be triggered by a user or by DRS.</p>
<p><strong>Line 10-13</strong>: We collect all the guests on which we want to report. This can be changed at will, just make sure the hash table <strong>$vmHash</strong> is populated.</p>
<p><strong>Line 15-66</strong>: This is the same logic as was used in <a href="https://www.lucd.info/2009/12/18/events-part-3-auditing-vm-device-changes/" target="_blank">Events – Part 3 : Auditing VM device changes</a></p>
<p><strong>Line 69-70</strong>: We group the discovered vMotions per guest and then we sort the groups descending on the Count property. This is required because we will later use the Export-Csv cmdlet and if the array holds rows of varying length, the longest row should be first.</p>
<p><strong>Line 76-80</strong>: For the vMotioned guest we first make an entry with the original location at time $start.</p>
<p><strong>Line 82-86</strong>: For each vMotion we add the same properties Time, Host, DRS and User, but each time with an incremented suffix number.</p>
<p><strong>Line 89</strong>: A guest that was vMotioned is removed from hash table to avoid duplicate entries later one.</p>
<p><strong>Line 93-100</strong>: The guest that were not vMotioned during the reporting interval are added to the report.</p>
<h2>Sample output</h2>
<p>The script produces a CSV file that contains quite a bit of information.</p>
<p>A guest that was <span style="background-color: #00ff00;">not vMotioned</span> during the reporting interval will only have a <strong>Time1</strong> and <strong>Host1</strong> column.</p>
<p>Guests that were vMotioned will have additional <span style="background-color: #ffff00;"><strong>Time<em>n</em></strong> and <strong>Host<em>n</em></strong></span> columns. Notice the <span style="background-color: #99ccff;"><strong>DRS<em>n</em></strong></span> column which indicates if a vMotion was triggered by DRS or by a user.  The <span style="background-color: #ff99cc;"><strong>User<em>n</em></strong></span> column will display the username if it was a user-invoked vMotion.</p>
<p><a href="https://lucd.info/wp-content/uploads/2010/06/vMotion-history.png"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-2392" title="vMotion-history" src="https://lucd.info/wp-content/uploads/2010/06/vMotion-history.png" alt="" width="833" height="333" srcset="https://www.lucd.info/wp-content/uploads/2010/06/vMotion-history.png 1190w, https://www.lucd.info/wp-content/uploads/2010/06/vMotion-history-300x120.png 300w, https://www.lucd.info/wp-content/uploads/2010/06/vMotion-history-1024x409.png 1024w" sizes="auto, (max-width: 833px) 100vw, 833px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2010/06/22/events-part-8-vmotion-history/feed/</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
	</channel>
</rss>
