<?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>VSVC4944 Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/category/vmworld/2013/vsvc4944/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/category/vmworld/2013/vsvc4944/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 09 Nov 2022 08:11:08 +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>VSVC4944 Archives - LucD notes</title>
	<link>https://www.lucd.info/category/vmworld/2013/vsvc4944/</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>Event-O-Matic</title>
		<link>https://www.lucd.info/2013/09/02/event-o-matic/</link>
					<comments>https://www.lucd.info/2013/09/02/event-o-matic/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Sun, 01 Sep 2013 23:54:03 +0000</pubDate>
				<category><![CDATA[2013]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VSVC4944]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[VMworld]]></category>
		<category><![CDATA[WIndows Forms]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=4550</guid>

					<description><![CDATA[One of the questions, related to working with vSphere events and tasks, that [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>One of the questions, related to working with vSphere <strong>events</strong> and <strong>tasks</strong>, that often appear in the <a href="https://communities.vmware.com/community/vmtn/automationtools/powercli" target="_blank" rel="noopener noreferrer">PowerCLI Community</a>, is how do we know which events to select for a query.</p>
<p>To make that task a bit easier, I wrote the <strong>Event-O-Matic</strong> script. It&#8217;s a GUI that allows you to pick a number of events, and the script will generate the PowerShell code, and place it in the <span style="background-color: #ffff00;"><strong>clipboard</strong></span>. The Event-O-Matic script was mentioned during our <strong>VMworld 2013 US</strong> session VSVC4944.</p>
<p><a href="https://www.lucd.info/2013/09/02/event-o-matic/event-o-matic-3-2/" rel="attachment wp-att-4572"><img fetchpriority="high" decoding="async" class="alignnone size-full wp-image-4572" src="https://lucd.info/wp-content/uploads/2013/09/event-o-matic-3-2.png" alt="event-o-matic-3-2" width="598" height="396" srcset="https://www.lucd.info/wp-content/uploads/2013/09/event-o-matic-3-2.png 598w, https://www.lucd.info/wp-content/uploads/2013/09/event-o-matic-3-2-300x198.png 300w" sizes="(max-width: 598px) 100vw, 598px" /></a></p>
<p><strong><span style="color: #000000; background-color: #ffff00;">Update November 9th 2022</span>: </strong></p>
<ul>
<li>removed PSSnapin loaded test</li>
</ul>
<p><strong><span style="color: #000000; background-color: #ffff00;">Update September 7th 2013</span>: </strong></p>
<ul>
<li>added at least PowerShell v3 test</li>
<li>added PowerCLI core pssnapin loaded test</li>
</ul>
<p><span id="more-4550"></span></p>
<p>The script presents a GUI based on Windows Forms. The PowerShell code to generate the GUI was created by the <a href="https://www.sapien.com/software/communitytools#PrimalFormsCE" target="_blank" rel="noopener noreferrer">Sapien PrimalForms Community Edition</a>.</p>
<p>Due to the size of the script, I did not place the complete script inline in this post, but rather I provided a download link. Make sure to &#8220;<span style="background-color: #ffff00;"><strong><em>unblock</em></strong></span>&#8221; the script after you downloaded it, to avoid problems with the PowerShell execution policy.</p>
<p>[wpfilebase tag=file id=28]</p>
<p>The use of the script is quite easy (we think). A short overview of a typical session:</p>
<ol>
<li>Start the script</li>
<li>In the <strong>vSphere Server</strong> text-box enter the name or IP address of an <strong>ESXi</strong> or a <strong>vCenter server</strong>.</li>
<li>Click the <strong>Connect</strong> button.
<ol>
<li>If the connection is successful, the line below the vSphere Server text-box will display the version of the vSphere Server.</li>
<li>The <strong>Events</strong> box will list all the events that exist on the vSphere server.</li>
<li>The number of events that are found will be displayed just above the Events box.</li>
</ol>
</li>
<li>When you <strong>hover</strong> over a specific event, the <strong>description</strong> of the event (if present) will be displayed in a pop-up box.</li>
<li>You can also use the Name and Description <strong>radio-buttons</strong> to switch between the eventname and it&#8217;s description.</li>
<li>You can search for text that should appear in the Name or Description field. Enter the text in the <strong>Search text box</strong> and click <strong>Search</strong>. The Events window will now only show the events that have the specific text in the <strong>Name</strong> of in the <strong>Description</strong> field.</li>
<li>When you <strong>select</strong> an event by clicking on it, the event will appear in the <strong>Selected</strong> box.</li>
<li>When you <strong>click</strong> on an event in the Selected box, the event will be <strong>removed</strong>.</li>
<li>When all the required events are selected, click the Generate Code button. The code will be stored <span style="background-color: #ffff00;">in the clipboard</span>.</li>
<li>By default the code generator uses the <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/Get-VIEvent.html" target="_blank" rel="noopener noreferrer">Get-VIEvent</a> cmdlet, but by selected the <strong>Get-VIEventPlus switch</strong>, you can generate code that uses the <strong>Get-VIEventPlus</strong> function. See my <a href="https://www.lucd.info/2013/03/31/get-the-vmotionsvmotion-history/" target="_blank" rel="noopener noreferrer">Get the vMotion/svMotion history</a> post for the Get-VIEventPlus function.</li>
<li>The Finish button is self-explaining I assume.</li>
</ol>
<p>During our VMworld US 2013 session, we showed a short video that demonstrated the use of the script.</p>
<p><iframe title="Event-O-Matic 3.1" width="770" height="578" src="https://www.youtube.com/embed/LMathNe0bYE?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe></p>
<p>Enjoy !</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2013/09/02/event-o-matic/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
		<item>
		<title>SiW &#8211; Robust Sessions and PowerCLI</title>
		<link>https://www.lucd.info/2013/08/27/siw-robust-sessions-and-powercli/</link>
					<comments>https://www.lucd.info/2013/08/27/siw-robust-sessions-and-powercli/#comments</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Tue, 27 Aug 2013 14:08:32 +0000</pubDate>
				<category><![CDATA[2013]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[remote session]]></category>
		<category><![CDATA[robust]]></category>
		<category><![CDATA[SiW]]></category>
		<category><![CDATA[VMworld]]></category>
		<category><![CDATA[VSVC4944]]></category>
		<category><![CDATA[Session]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=4534</guid>

					<description><![CDATA[One of the new features that came with PowerShell v3 was the introduction [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>One of the new features that came with <strong>PowerShell v3</strong> was the introduction of &#8220;<strong>robust</strong>&#8221; or &#8220;<strong>persistent</strong>&#8221; sessions. This is, imho, a huge improvement on the concept of <strong>remote sessions</strong> who were introduced in <strong>PowerShell v2</strong>.<br />
In short, before robust sessions, you had to keep the the client, that created the session, <strong>open</strong> to keep the remote session <strong>alive</strong>. With robust sessions, the client side can be closed, and you can reconnect to the robust session, even from another client.<br />
This new remote session concept is something that can be used to solve a number of known <a href="https://communities.vmware.com/community/vmtn/automationtools/powercli" target="_blank">PowerCLI</a> &#8220;issues&#8221;.</p>
<p><a href="https://lucd.info/wp-content/uploads/2013/08/siw-icon.png">                        <img decoding="async" class="alignnone size-full wp-image-4544" alt="siw-icon" src="https://lucd.info/wp-content/uploads/2013/08/siw-icon.png" width="226" height="224" srcset="https://www.lucd.info/wp-content/uploads/2013/08/siw-icon.png 226w, https://www.lucd.info/wp-content/uploads/2013/08/siw-icon-150x150.png 150w" sizes="(max-width: 226px) 100vw, 226px" /></a></p>
<p style="font-size: 9px;">Siw stands for Server in Waiting. We selected that term since we liked the sound of it, no double entendre should be suspected <img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f642.png" alt="🙂" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<p><span id="more-4534"></span>Some of these issues, that most of you probably know:</p>
<ul>
<li><a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI51R2/html/Connect-VIServer.html" target="_blank">Connect-VIServer</a> can be slow</li>
<li>The 1st cmdlet in a session is slow</li>
<li>Keep the PowerCLI version aligned on all the stations were it is used</li>
<li>Have powerfull stations to run scripts against &#8220;big&#8221; vSphere environments</li>
</ul>
<p>The idea is that you would have a &#8220;workhorse&#8221; station, with enough resources to cope with the bigger vSphere environments. On this workhorse station you set up a number of robust sessions, and when you need to run a PowerCLI script on a client, you would connect from the client to such a robust session, and execute your script in that robust session.</p>
<p><a href="https://lucd.info/wp-content/uploads/2013/08/siw-schematic.png">         <img loading="lazy" decoding="async" class="alignnone size-medium wp-image-4543" alt="siw-schematic" src="https://lucd.info/wp-content/uploads/2013/08/siw-schematic-300x123.png" width="413" height="180" /></a></p>
<p>To make the creation and usage of these robust sessions in combination with PowerCLI easier, I created a number of functions.</p>
<h2>The Functions</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">function New-SiwSession {

&lt;#  
.SYNOPSIS  Creates a number of robust PowerCLI sessions   
.DESCRIPTION The function will create a number of
  robust remote sessions on a specific server. The
  remote sessions will be initialised to run PowerCLI
  scripts
.NOTES  Author:  Luc Dekens  
.PARAMETER ComputerName
  The hostname of the server where the robust PowerCLI
  sessions will be created
.PARAMETER Credential
  A PSCredential object that contains the credentials for
  the robust session.
.PARAMETER SiwType
  The name prefix for the robust PowerCLI sessions
.PARAMETER NumberOfSessions
  The number of robust PowerCLI sessions that shall be
  created. The maximum number is 99.
.PARAMETER vServer
  The name of the vSphere server to which the robust PowerCLI
  session shall connect
 .PARAMETER vCredential
  The PSCredential object that will be used to connect to the
  $vServer server. If $null, the session credentials will be
  used

.EXAMPLE
  PS&gt; New-SiwSession -ComputerName $tgtServer -Credential $cred `
  &gt;&gt; -SiwType &quot;PowerCLI&quot; -NumberOfSessions 3 -vServer &quot;vCenter&quot;
#&gt;

  param(
    [String]$ComputerName,
    [System.Management.Automation.PSCredential]$Credential,
    [String]$SiwType,
    [ValidateRange(1,99)] 
    [Int]$NumberOfSessions,
	[String]$vServer,
    [System.Management.Automation.PSCredential]$vCredential
  )

  if(!$vCredential){$vCredential = $Credential}
  $pclStartUp = {
    param($vServer,$Credential)

    Add-PSSnapin VMware.VimAutomation.Core
    Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -Confirm:$false | Out-Null
    Connect-VIServer -Server $vServer -Credential $Credential | Out-Null
    Get-Datacenter | Out-Null
  }

  $newSiwOption = @{
    IdleTimeout = -1
    NoMachineProfile = $true
    SkipCACheck = $true
    SkipCNCheck = $true
    SkipRevocationCheck = $true
  }
  $SiwOptions = New-PSSessionOption @newSiwOption 

  $newSiwSession = @{
    ComputerName = $ComputerName
    Credential = $Credential
    EnableNetworkAccess = $true
    Name = $null
    SessionOption = $SiwOptions
  }

  1..$NumberOfSessions | %{
    $newSiwSession.Name = $SiwType + (&quot;-{0:d2}&quot; -f $_)
    $SiwSession = New-PSSession @newSiwSession
    $pclInit = @{
      Session = $SiwSession
      ScriptBlock = $pclStartUp
      ArgumentList = $vServer,$Credential
    }
    Invoke-Command @pclInit
    Disconnect-PSSession -Session $SiwSession -Confirm:$false | Out-Null
  }
}

function Get-SiwSession {

&lt;#  
.SYNOPSIS  Returns a robust PowerCLI session
.DESCRIPTION The function will return an available robust
  PowerCLI session. If no robust sessions are available,
  function  will return $null
.NOTES  Author:  Luc Dekens  
.PARAMETER ComputerName
  The hostname of the server where the robust PowerCLI
  sessions will be created
.PARAMETER Credential
  A PSCredential object that contains the credentials for
  the robust session.
.PARAMETER SiwType
  The name prefix for the robust PowerCLI sessions
.EXAMPLE
  PS&gt; Get-SiwSession -ComputerName $tgtServer -Credential $cred `
  &gt;&gt; -SiwType &quot;PowerCLI&quot;
#&gt;

  param(
    [String]$ComputerName,
    [System.Management.Automation.PSCredential]$Credential,
    [String]$SiwType 
  )

  $getSiwSession = @{
    ComputerName = $ComputerName
    Credential = $Credential
  }

  Get-PSSession @getSiwSession |
  Where {$_.Name -match &quot;^$($SiwType)&quot; -and $_.Availability -eq &quot;None&quot;} |
  Get-Random
}

function Abort-SiwSession {

&lt;#  
.SYNOPSIS  Aborts robust PowerCLI sessions   
.DESCRIPTION The function abort all robust PowerCLI
  sessions on a server.
.NOTES  Author:  Luc Dekens  
.PARAMETER Session
  The handle of the session that needs to be aborted.
.EXAMPLE
  PS&gt; Abort-SiwSession -Session $pcliSession
#&gt;

  param( 
    [CmdletBinding()]
    [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
    [System.Management.Automation.Runspaces.PSSession]$Session
  )

  $session | %{
    $cimInstance = @{
      ComputerName = $_.ComputerName
            ClassName = &quot;Win32_Process&quot;
      Filter = &quot;Name Like 'wsmprovhost.exe'&quot;
    }
    Get-CimInstance @cimInstance |
    Invoke-CimMethod -MethodName Terminate -Confirm:$false
  }
}</pre><p></p>
<h4>Annotations</h4>
<p><strong>Line 38</strong>: The function allows a request to create up to99 robust PowerCLI sessions. But keep in mind that PowerShell itself has a throttle limit of 32 sessions. In other words PowerShell handle the instructions in the first 32 sessions and place the other remote sessions in wait.</p>
<p><strong>Line 45-52</strong>: These are the lines that set up the robust session as a PowerCLI session.Line 49: The robust session can&#8217;t handle PowerCLI warning messages correctly, so we suppress those.</p>
<p><strong>Line 51</strong>: This random PowerCLI cmdlet avoids the delay you normally see on the 1st PowerCLI cmdlet that is executed in a new session.</p>
<p><strong>Line 54-60</strong>: The session options.</p>
<p><strong>Line 63-69</strong>: The parameters used to create the remote session.</p>
<p><strong>Line 71-81</strong>: The loop and code block that create the requested number of robust PowerCLI sessions</p>
<p><strong>Line 46,77,79</strong>: Notice how the values for the PowerCLI code block are passed to the remote session.</p>
<p><strong>Line 80</strong>: The remote session is immediately disconnected.</p>
<p><strong>Line 107</strong>: Since you can only connect to a robust session with the same credentials as the ones which created the session, the function requires these as a parameter as well.</p>
<p><strong>Line 118</strong>: To avoid over-using the 1st robust session that is returned, the function will return a &#8220;random&#8221; available session.</p>
<p><strong>Line 146</strong>: Since this function is/was primarily used to &#8220;kill&#8221; unresponsive functions, it uses the Win32_Process instance that corresponds with a robust session on that target remote server.</p>
<h2>Sample Usage</h2>
<p>Since the hard work for setting up and using robust PowerCLI sessions is done in the functions, the use of these robust PowerCLI sessions is quite simple.</p>
<p>First you create a number of sessions.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$tgtServer = &quot;SRV1&quot;
$vCenter = &quot;VCENTER&quot;

$pswdSecure = ConvertTo-SecureString -String $pswd -AsPlainText -Force
$cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username,$pswdSecure

# Create 3 Siw sessions
New-SiwSession -ComputerName $tgtServer -Credential $cred -SiwType &quot;PowerCLI&quot; -NumberOfSessions 3 -vServer $vCenter</pre><p></p>
<p>Once the sessions are created, you connect to one of the available ones to run your PowerCLI code.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag"># Use one of the sessions to run PowerCLI code on SRV1
$session = Get-SiwSession -ComputerName $tgtServer -Credential $cred -SiwType &quot;PowerCLI&quot;

Connect-PSSession -Session $session | Out-Null
Invoke-Command -Session $session -ScriptBlock {Get-VMHost}
Disconnect-PSSession -Session $session | Out-Null

# Drop the sessions
Get-PSSession -ComputerName $tgtServer -Credential $cred | Remove-PSSession</pre><p></p>
<p>Should something go wrong and the robust PowerCLI session is stuck, you can try the abort function to kill the session.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag"># Abort the sessions
Get-PSSession -ComputerName SRV1 -Credential $cred | Abort-SiwSession</pre><p></p>
<p>Enjoy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2013/08/27/siw-robust-sessions-and-powercli/feed/</wfw:commentRss>
			<slash:comments>9</slash:comments>
		
		
			</item>
	</channel>
</rss>
