<?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>PeetersOnline &#187; Disconnect</title>
	<atom:link href="http://www.peetersonline.nl/index.php/tag/disconnect/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peetersonline.nl</link>
	<description>Using Powershell for (virtually) everything!</description>
	<lastBuildDate>Fri, 19 Aug 2011 09:22:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>To Disconnect(-VIServer) or not to Disconnect</title>
		<link>http://www.peetersonline.nl/index.php/vmware/to-disconnect-viserver-or-not-to-disconnect/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/to-disconnect-viserver-or-not-to-disconnect/#comments</comments>
		<pubDate>Wed, 20 Aug 2008 07:04:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[Disconnect]]></category>
		<category><![CDATA[Disconnect-VIServer]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[VI Toolkit]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/index.php/vmware/to-disconnect-viserver-or-not-to-disconnect/</guid>
		<description><![CDATA[With the release of VI Toolkit v1.0, the bèta-cmdlet Get-VIServer has been renamed to Connect-VIServer, which more accurately describes the action. The opposite action is now also available in the form of Disconnect-VIServer. Every script you start with Connect-VIServer should end with Disconnect-VIServer if you&#8217;d like to keep the amount of open sessions to your <a href='http://www.peetersonline.nl/index.php/vmware/to-disconnect-viserver-or-not-to-disconnect/'>[...]</a>
Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>With the release of <a href="http://www.vmware.com/sdk/vitk_win/index.html" target='_blank'>VI Toolkit</a> v1.0, the bèta-cmdlet Get-VIServer has been renamed to Connect-VIServer, which more accurately describes the action. The opposite action is now also available in the form of Disconnect-VIServer. <strong>Every script you start with Connect-VIServer should end with Disconnect-VIServer</strong> if you&#8217;d like to keep the amount of open sessions to your Virtual Center Server to a minimum. And you do if you like having any sort of performance from your VC Server.</p>
<p>Here&#8217;s three ways you can make sure you don&#8217;t end up with unnecessary sessions:</p>
<p><span id="more-50"></span></p>
<p><strong><u>1. Find scripts that lack the Disconnect-VIServer command:</u></strong></p>
<blockquote><p>$Path = &#8220;D:\Scripts&#8221;<br />
$ConnectMatches = Get-ChildItem $Path -Recurse |<br />
   Where {$_.PSIsContainer -eq $False} |<br />
   Select-String &#8220;Connect-VIServer&#8221; |<br />
   Where {$_.Line -notmatch &#8220;Disconnect&#8221;}<br />
$DisconnectMatches = Get-ChildItem $Path -Recurse |<br />
   Where {$_.PSIsContainer -eq $False} |<br />
   Select-String &#8220;Disconnect-VIServer&#8221;<br />
Compare-Object -ReferenceObject $ConnectMatches`<br />
  -DifferenceObject $DisconnectMatches -Property Path</p></blockquote>
<p><strong><u>2. Disconnect old sessions through the VI Client GUI</u></strong></p>
<p>On the Administration page of the VI Client, click on the Sessions tab. Sort by Status, Select the sessions that have been idle for a long time and click Terminate.</p>
<p><strong><u>3. Use a script to disconnect old sessions</u></strong></p>
<p>That&#8217;s more like it! Now who would want to go clicking and sorting about in the VI Client? ;) Thank goodness we have the <a href="http://www.vmware.com/sdk/vitk_win/index.html" target='_blank'>VI Toolkit</a>. Here&#8217;s the code:</p>
<blockquote><p>$VCServerName = &#8220;YourVCServerName&#8221;<br />
$HoursOld = 24        # Modify value at your pleasure</p>
<p>$VC = Connect-VIServer $VCServerName<br />
$ServiceInstance = Get-View ServiceInstance<br />
$SessionManager = Get-View $ServiceInstance.Content.SessionManager<br />
$SessionManager.SessionList |<br />
   Where {$_.LastActiveTime -lt (Get-Date).AddHours(-$HoursOld)} |<br />
   % {$SessionManager.TerminateSession($_.Key)}<br />
Disconnect-VIServer -Confirm:$False<br />
Write-Host &#8220;The VI Toolkit ROCKS!&#8221;</p></blockquote>
<p>Enjoy!</p>
<p>Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/to-disconnect-viserver-or-not-to-disconnect/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

