<?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>Get-EsxCli Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/category/powershell/powercli/get-esxcli/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/category/powershell/powercli/get-esxcli/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Fri, 22 Apr 2016 14:33:03 +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>Get-EsxCli Archives - LucD notes</title>
	<link>https://www.lucd.info/category/powershell/powercli/get-esxcli/</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>A closer look at Get-EsxCli V2</title>
		<link>https://www.lucd.info/2016/04/22/closer-look-get-esxcli-v2/</link>
					<comments>https://www.lucd.info/2016/04/22/closer-look-get-esxcli-v2/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Fri, 22 Apr 2016 14:31:13 +0000</pubDate>
				<category><![CDATA[Get-EsxCli]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[V2]]></category>
		<category><![CDATA[Invoke()]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=5139</guid>

					<description><![CDATA[In IT we don&#8217;t like breaking changes in our software. But sometimes you [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In IT we don&#8217;t like breaking changes in our software. But sometimes you do need to break an egg to make an omelet. Standing still is ultimately moving backwards.</p>
<p><a href="https://www.lucd.info/2016/04/22/closer-look-get-esxcli-v2/esxcli-v2-2/" rel="attachment wp-att-5141"><img decoding="async" class="wp-image-5141 aligncenter" src="https://lucd.info/wp-content/uploads/2016/04/esxcli-v2-1.jpg" alt="esxcli-v2" width="175" height="171" /></a>In the most recent <a href="https://communities.vmware.com/community/vmtn/automationtools/powercli" target="_blank">PowerCLI</a> Release (<a href="https://pubs.vmware.com/Release_Notes/en/powercli/63r1/powercli63r1-releasenotes.html" target="_blank">v6.3 R1</a>) such a change was introduced for the <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI63R1/html/Get-EsxCli.html" target="_blank">Get-EsxCli</a> cmdlet. With the ingenious introduction of the <strong>V2</strong> switch this is <span style="background-color: #ffff00;">not yet</span> a breaking change, but you should be aware that the &#8220;old&#8221; way of using <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI63R1/html/Get-EsxCli.html" target="_blank">Get-EsxCli</a> will ultimately go away.</p>
<p>In the <a href="https://eu.wiley.com/WileyCDA/WileyTitle/productCd-1118925114.html" target="_blank">VMware vSphere PowerCLI Reference: Automating vSphere Administration, 2nd Edition</a>, we included a script (Chapter 15, Listing 15-2), that allowed you to create a handy <strong>Reference Chart</strong> of the available methods under the <a href="https://www.vmware.com/support/developer/PowerCLI/PowerCLI63R1/html/Get-EsxCli.html" target="_blank">Get-EsxCli</a> cmdlet. This post provides an <strong>update</strong> to that script for V2.<br />
<span id="more-5139"></span></p>
<h2>The Script</h2>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">function Get-EsxCliCommand {
&lt;#
.SYNOPSIS
  Returns all available namespaces through the Get-EsxCli object 
.DESCRIPTION
  The Get-EsxCli cmdlet returns an object that can be used to
  access all properties and methods that are available. This
  function retuns all available methods in thes namespaces,
  together with a short help text and the method's Parameters.
.NOTES
  Source: Original: Automating vSphere Administration, 2nd Edition
  Author: Luc Dekens
.ParamETER VMHost
  The host for which to list the esxcli namespaces
.Parameter V2
  Switch to use the EsxCli object version 2, that was
  introduced in PowerCLI 6.3 Release 1
.EXAMPLE
  Get-EsxCliCommand -VMHost $esx -V2
#&gt;

    [CmdLetBinding()]
    Param(
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)]
        [PSObject]$VMHost,
        [Switch]$V2
    )

    Process{
        if($V2){
            $esxcli = Get-EsxCli -VMHost $VMHost -V2
            $cmd = {$esxcli.esxcli.command.list.Invoke()}
        }
        else{
            $esxcli = Get-EsxCli -VMHost $VMHost
            $cmd = {$esxcli.esxcli.command.list()}
        }

        Invoke-Command -ScriptBlock $cmd | Foreach-Object {
            $steps = $_.NameSpace.Split('.') + $_.Command
            if($V2){
                $stepsHelp = $_.NameSpace.Split('.') + $_.Command
            }
            else{
                $stepsHelp = $_.NameSpace.Split('.') + 'help'
            }
            
            # Get the namespace object
            $nSpace = $esxcli
            $steps | Foreach-Object {
                $nSpace = $($nSpace.$($_))
            }
            if($V2){
                $nSpace = $($nSpace.Invoke)
            }
            
            # Get the namespace Help object
            $helpObject = $esxcli
            $stepsHelp | Foreach-Object {
                $helpObject = $($helpObject.$($_))
            }
            # Fetch the help for the method
            if($helpObject){
                if($V2){
                    $helpObjectelp = $helpObject.Help()
                }
                else{
                    $helpObjectelp = $helpObject.Invoke($_.Command)
                }
            }
            else{
                $helpObjectelp = $null
            }
            
            # Method details
            $_ | Select @{N='Command';E={
                &quot;`$esxcli.$($_.NameSpace).$($_.Command)&quot;}},
            @{N='Syntax/Parameter';E={&quot;$($nSpace.Value.ToString())&quot;}},
            @{N='Help';E={$helpObjectelp.Help}}
            
            # Parameter details
            if($helpObject){
                $helpObjectelp.Param | Select @{N='Command';E={''}},
                @{N='Syntax/Parameter';E={$_.DisplayName}},
                @{N='Help';E={$_.Help}}
            }
        }
    }
}</pre><p></p>
<h3>Annotations</h3>
<p><strong>Line 26:</strong> This version of the function introduces a new switch, named V2, that allows you to select which mode to use, V1 or V2</p>
<p><strong>Line 32:</strong> The V2 version makes use of the Invoke() method to call the methods available in the different namespaces.</p>
<p><strong>Line 39:</strong> To be able to use a single loop for V1 and V2, the script uses the Invoke-Command cmdlet. The actual codeblock used depends on the setting of the V2 switch</p>
<p><strong>Line 54:</strong> Another adaptation to use the V2 Invoke() method</p>
<p><strong>Line 68:</strong> Same as for line 32 and 54, the Help function is called via the Invoke() method</p>
<h2>Sample Usage</h2>
<p>To create a Reference Chart that holds the V1 and V2 syntax of the different namespaces and available methods, the following sample uses <a href="https://twitter.com/dfinke" target="_blank">Doug Finke</a>&#8216;s <a href="https://github.com/dfinke/ImportExcel" target="_blank">ImportExcel</a> module.</p>
<p>This <a href="https://github.com/dfinke/ImportExcel" target="_blank">ImportExcel</a> module is an indispensable tool if you need to do reporting in your PowerShell scripts. And not just for tabular data, the charting feature and the conditional formatting feature make this one of more valuable modules available in the <a href="https://www.powershellgallery.com/" target="_blank">PowerShell Gallery</a>! And there is a lot more available!</p>
<p></p><pre class="urvanov-syntax-highlighter-plain-tag">$fileName = 'C:\Users\lucd\Scripts\esxcli.xlsx'

Get-EsxCliCommand -VMHost esx1.local.lab | Export-Excel -Path $fileName -WorkSheetname 'V1' -FreezeTopRow -AutoSize
Get-EsxCliCommand -VMHost esx1.local.lab -V2 | Export-Excel -Path $fileName -WorkSheetname 'V2' -FreezeTopRow -AutoSize</pre><p></p>
<p>The resulting worksheet look like this.</p>
<p>The V1 XRef</p>
<p><a href="https://www.lucd.info/2016/04/22/closer-look-get-esxcli-v2/esxcli-v1-xref-2/" rel="attachment wp-att-5144"><img decoding="async" class="alignnone wp-image-5144 size-medium" src="https://lucd.info/wp-content/uploads/2016/04/esxcli-v1-xref-1-300x89.jpg" alt="esxcli-v1-xref" width="300" height="89" srcset="https://www.lucd.info/wp-content/uploads/2016/04/esxcli-v1-xref-1-300x89.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/04/esxcli-v1-xref-1-768x228.jpg 768w, https://www.lucd.info/wp-content/uploads/2016/04/esxcli-v1-xref-1.jpg 992w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>The V2 XRef</p>
<p><a href="https://www.lucd.info/2016/04/22/closer-look-get-esxcli-v2/esxcli-v2-xref-2/" rel="attachment wp-att-5145"><img decoding="async" class="alignnone wp-image-5145 size-medium" src="https://lucd.info/wp-content/uploads/2016/04/esxcli-v2-xref-1-300x89.jpg" alt="esxcli-v2-xref" width="300" height="89" srcset="https://www.lucd.info/wp-content/uploads/2016/04/esxcli-v2-xref-1-300x89.jpg 300w, https://www.lucd.info/wp-content/uploads/2016/04/esxcli-v2-xref-1-768x227.jpg 768w, https://www.lucd.info/wp-content/uploads/2016/04/esxcli-v2-xref-1.jpg 1010w" sizes="(max-width: 300px) 100vw, 300px" /></a></p>
<p>The important differences that were introduced with V2 are</p>
<ul>
<li>the way the methods are called. This happens with the <strong>Invoke()</strong> method.</li>
<li>the way the parameters are passed. This is done with a HashTable, so no more positional parameters</li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2016/04/22/closer-look-get-esxcli-v2/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
