<?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>Remote Session Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/tag/remote-session-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/tag/remote-session-2/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 08 Apr 2020 10:56:01 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.10</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>Remote Session Archives - LucD notes</title>
	<link>https://www.lucd.info/tag/remote-session-2/</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>How to run View PowerCLI</title>
		<link>https://www.lucd.info/2014/01/01/how-to-run-view-powercli/</link>
					<comments>https://www.lucd.info/2014/01/01/how-to-run-view-powercli/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Wed, 01 Jan 2014 17:28:04 +0000</pubDate>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[remote session]]></category>
		<category><![CDATA[View]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Remote Session]]></category>
		<category><![CDATA[VMUG]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=4618</guid>

					<description><![CDATA[During my recent presentation at the 20th VMUGBE+ session, I showed different ways [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>During my recent presentation at the <a href="https://erikerik.mygreencloud.be/?p=401" target="_blank" rel="noopener noreferrer">20th VMUGBE+</a> session, I showed different ways to run View PowerCLI cmdlets and scripts.</p>
<p>Several of the methods I showed, are already discussed on other blogs (to which I will include the links of course), but there is a new PowerShell feature that hasn&#8217;t been used until now (afaik).</p>
<p><a href="https://www.lucd.info/2014/01/01/how-to-run-view-powercli/view5/" rel="attachment wp-att-4629"><img fetchpriority="high" decoding="async" class="alignnone  wp-image-4629" alt="view5" src="https://lucd.info/wp-content/uploads/2014/01/view5.png" width="464" height="304" srcset="https://www.lucd.info/wp-content/uploads/2014/01/view5.png 580w, https://www.lucd.info/wp-content/uploads/2014/01/view5-300x196.png 300w" sizes="(max-width: 464px) 100vw, 464px" /></a></p>
<p>And since I never found a complete overview of all the available methods, I decided to create this post.</p>
<p><span id="more-4618"></span></p>
<h2>Method 1 &#8211; On a Connection Server</h2>
<p><a href="https://www.lucd.info/2014/01/01/how-to-run-view-powercli/view1/" rel="attachment wp-att-4620"><img decoding="async" class="alignnone size-full wp-image-4620" alt="view1" src="https://lucd.info/wp-content/uploads/2014/01/view1.png" width="411" height="238" srcset="https://www.lucd.info/wp-content/uploads/2014/01/view1.png 411w, https://www.lucd.info/wp-content/uploads/2014/01/view1-300x173.png 300w" sizes="(max-width: 411px) 100vw, 411px" /></a></p>
<h3>Method 1A &#8211; From the View PowerCLI prompt</h3>
<p>This is the most straightforward method, and also the first one shown in the <a href="http://pubs.vmware.com/view-52/topic/com.vmware.view.integration.doc/view_integration_powershell.5.1.html" target="_blank" rel="noopener noreferrer">View documentation</a>. You start a View PowerCLI session through the provided Start menu shortcut, or you start a plain PowerShell session and make sure the <strong>VMware.View.Broker</strong> PSSnapin is loaded.</p>
<p>Note that the View PowerCLI PSSNapin has a problem when you use it in a <strong>PowerShell v3</strong> (or higher) engine. A bypass for this problem is to start the PowerShell engine in <strong>Version 2 mode</strong>.</p>
<p>One way of doing that is by adding a parameter to the View PowerCLI shortcut in the Start menu. The following short script will update the Start menu entry to do this.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$extraArgument = &quot;-version 2 &quot;

if($PSVersionTable.PSVersion.Major -gt 2) {
  $relativePath = &quot;VMware\View PowerCLI.lnk&quot;
  $shell = New-Object -com &quot;WScript.Shell&quot;
  $start = $shell.SpecialFolders.item(&quot;AllUsersPrograms&quot;)
  $shortcut = $shell.CreateShortcut(&quot;$($start)\$relativePath&quot;)
  if($shortcut.Arguments -notmatch $extraArgument){
    $shortcut.Arguments = &quot;$($extraArgument)$($shortcut.Arguments)&quot;
    $shortcut.Save()
  }
}</pre><p></p>
<p>The shortcut will have an extra argument, the <a href="https://technet.microsoft.com/en-us/library/hh847899.aspx" target="_blank" rel="noopener noreferrer">Version parameter</a>, after you run the script on your Connection server.</p>
<p><a href="https://www.lucd.info/2014/01/01/how-to-run-view-powercli/view2/" rel="attachment wp-att-4621"><img decoding="async" class="alignnone  wp-image-4621" alt="view2" src="https://lucd.info/wp-content/uploads/2014/01/view2.png" width="634" height="226" srcset="https://www.lucd.info/wp-content/uploads/2014/01/view2.png 704w, https://www.lucd.info/wp-content/uploads/2014/01/view2-300x106.png 300w" sizes="(max-width: 634px) 100vw, 634px" /></a></p>
<p>A short demo of this</p>
<div style="width: 770px;" class="wp-video"><video class="wp-video-shortcode" id="video-4618-1" width="770" height="482" preload="metadata" controls="controls"><source type="video/mp4" src="https://lucd.info/wp-content/uploads/2014/01/demo2.mp4?_=1" /><a href="https://lucd.info/wp-content/uploads/2014/01/demo2.mp4">https://lucd.info/wp-content/uploads/2014/01/demo2.mp4</a></video></div>
<h3>Method 1B &#8211; As a PowerShell background job</h3>
<p>An alternative, that uses the same concept, is to run your View PowerCLI cmdlets and script as background jobs, and use the PSVersion parameter.</p>
<p>This method was described by <a href="https://twitter.com/andreleibovici" target="_blank" rel="noopener noreferrer">Andre Leibovici</a> in his <a href="https://myvirtualcloud.net/?p=4178" target="_blank" rel="noopener noreferrer">How to use VMware View PowerCLI with PowerShell 3.0</a> post.</p>
<p><a href="https://www.lucd.info/2014/01/01/how-to-run-view-powercli/view3/" rel="attachment wp-att-4623"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4623" alt="view3" src="https://lucd.info/wp-content/uploads/2014/01/view3.png" width="411" height="399" srcset="https://www.lucd.info/wp-content/uploads/2014/01/view3.png 411w, https://www.lucd.info/wp-content/uploads/2014/01/view3-300x291.png 300w" sizes="auto, (max-width: 411px) 100vw, 411px" /></a></p>
<p>A short demo of this method</p>
<div style="width: 770px;" class="wp-video"><video class="wp-video-shortcode" id="video-4618-2" width="770" height="482" preload="metadata" controls="controls"><source type="video/mp4" src="https://lucd.info/wp-content/uploads/2014/01/demo3.mp4?_=2" /><a href="https://lucd.info/wp-content/uploads/2014/01/demo3.mp4">https://lucd.info/wp-content/uploads/2014/01/demo3.mp4</a></video></div>
<p>The major disadvantage of this method in all it&#8217;s forms, is that you are logging on to a Connection Server and running your script interactively on the server. Something that might not be permitted in a production environment.</p>
<p>Another disadvantage, is that while you are running in a Version 2 engine, you will <strong>not have access</strong> to any of the PowerShell v3 (or higher) cmdlets.</p>
<h2>Method 2 &#8211; Remote Session</h2>
<p>The first mention of using a PowerShell Remote Session to run View PowerCLI cmdlets and scripts comes from <a href="https://twitter.com/alanrenouf" target="_blank" rel="noopener noreferrer">Alan Renouf</a> in his <a href="https://www.virtu-al.net/2011/05/28/using-the-view-powercli-cmdlets-from-another-machine/" target="_blank" rel="noopener noreferrer">Using the View PowerCLI cmdlets from another machine</a> post.</p>
<p><a href="https://twitter.com/andreleibovici" target="_blank" rel="noopener noreferrer">Andre Leibovici</a> did a post on this concept later on in his <a href="https://myvirtualcloud.net/?p=3474" target="_blank" rel="noopener noreferrer">Remote use of VMware.View.Broker PowerCLI</a> post. The great novelty that he introduced there, was that he uses PowerCLI&#8217;s <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI55/html/Invoke-VMScript.html" target="_blank" rel="noopener noreferrer">Invoke-VMScript</a> cmdlet to configure the <a href="https://technet.microsoft.com/en-us/magazine/ff700227.aspx" target="_blank" rel="noopener noreferrer">winrm</a> settings on the Connection server.</p>
<p>But neither of these posts seems to mention that you need <strong>PowerShell v1 or v2</strong> on the Connection Server. And with the <a href="https://technet.microsoft.com/en-us/library/hh849717.aspx" target="_blank" rel="noopener noreferrer">New-PSSession</a> cmdlet you do not have the option to pass a <strong>Version</strong> parameter.</p>
<p>In <strong>PowerShell v4</strong> the <strong>PSSessionConfiguration</strong> concept was introduced. With the <a href="https://technet.microsoft.com/en-us/library/hh849741.aspx" target="_blank" rel="noopener noreferrer">Register-PSSessionConfiguration</a> cmdlet you create and register a session configuration on a computer. With this we can solve the requirement that the View PowerCLI PSSnapin needs PowerShell v1 or v2.</p>
<p><a href="https://www.lucd.info/2014/01/01/how-to-run-view-powercli/view4/" rel="attachment wp-att-4628"><img loading="lazy" decoding="async" class="alignnone size-full wp-image-4628" alt="view4" src="https://lucd.info/wp-content/uploads/2014/01/view4.png" width="482" height="342" srcset="https://www.lucd.info/wp-content/uploads/2014/01/view4.png 482w, https://www.lucd.info/wp-content/uploads/2014/01/view4-300x212.png 300w" sizes="auto, (max-width: 482px) 100vw, 482px" /></a></p>
<p>We can define a PS v2 configuration on the Connection Server remotly like this. Note that this assumes that remote sessions to the Connection server are already configured. If not, you can use Andre&#8217;s <strong>PSRemoteSession-Configure</strong> function to do that.</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$PS2 = {Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0 -Confirm:$false}
$session = New-PSSession -ComputerName view1
Invoke-Command -Session $session -ScriptBlock $PS2
Remove-PSSession -Session $session</pre><p></p>
<p>Once this session configuration is defined, we can run our View PowerCLI cmdlets and scripts like this</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$session = New-PSSession -ComputerName view1 -ConfigurationName PS2
Invoke-Command -Session $session -ScriptBlock {Add-PSSnapin VMware.View.Broker}
Invoke-Command -Session $session -ScriptBlock {Get-Pool}
Remove-PSSession -Session $session</pre><p></p>
<p>A short demo</p>
<div style="width: 770px;" class="wp-video"><video class="wp-video-shortcode" id="video-4618-3" width="770" height="482" preload="metadata" controls="controls"><source type="video/mp4" src="https://lucd.info/wp-content/uploads/2014/01/Demo4.mp4?_=3" /><a href="https://lucd.info/wp-content/uploads/2014/01/Demo4.mp4">https://lucd.info/wp-content/uploads/2014/01/Demo4.mp4</a></video></div>
<p>No more holding back on your PowerShell updates on the Connection servers.</p>
<p>A <strong>closing thought</strong>; the fact that the View PowerCLI PSSnapin officially still requires <strong>PowerShell v1</strong>, is to say the least annoying. Perhaps the team that develops the View PowerCLI PSSnapin could put <strong>PowerShell v4</strong> support, and a few other improvements I will gladly share with them if needed, on their New Year&#8217;s resolution list <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>Enjoy !</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2014/01/01/how-to-run-view-powercli/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		<enclosure url="https://lucd.info/wp-content/uploads/2014/01/demo2.mp4" length="6448372" type="video/mp4" />
<enclosure url="https://lucd.info/wp-content/uploads/2014/01/demo3.mp4" length="1424444" type="video/mp4" />
<enclosure url="https://lucd.info/wp-content/uploads/2014/01/Demo4.mp4" length="2725138" type="video/mp4" />

			</item>
	</channel>
</rss>
