<?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>Profile Archives - LucD notes</title>
	<atom:link href="https://www.lucd.info/category/powershell/powercli/ta2650-powercli-powershell/profile-ta2650-powercli-powershell-powercli-powershell/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.lucd.info/category/powershell/powercli/ta2650-powercli-powershell/profile-ta2650-powercli-powershell-powercli-powershell/</link>
	<description>My PowerShell ramblings</description>
	<lastBuildDate>Wed, 08 Apr 2020 09:47:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.9</generator>

<image>
	<url>https://www.lucd.info/wp-content/uploads/2018/12/cropped-120px-Tibetan_Dharmacakra-32x32.png</url>
	<title>Profile Archives - LucD notes</title>
	<link>https://www.lucd.info/category/powershell/powercli/ta2650-powercli-powershell/profile-ta2650-powercli-powershell-powercli-powershell/</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>At Your Fingertips</title>
		<link>https://www.lucd.info/2019/09/05/at-your-fingertips/</link>
					<comments>https://www.lucd.info/2019/09/05/at-your-fingertips/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Thu, 05 Sep 2019 10:41:47 +0000</pubDate>
				<category><![CDATA[2019]]></category>
		<category><![CDATA[HBI1729BU]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[VMworld]]></category>
		<category><![CDATA[Git]]></category>
		<guid isPermaLink="false">http://www.lucd.info/?p=6384</guid>

					<description><![CDATA[How often have you been finding out the PowerShell version you were using, [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>How often have you been finding out the PowerShell version you were using, or to which vSphere Server you were connected, or in which git repo/branch your code was being stored, or&#8230; Despair no more, it can now be available at your fingertips.</p>



<figure class="wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><img fetchpriority="high" decoding="async" width="1024" height="420" src="https://www.lucd.info/wp-content/uploads/2019/09/fingers-PCLI-1-1024x420.png" alt="" data-id="6393" data-link="https://www.lucd.info/?attachment_id=6393" class="wp-image-6393" srcset="https://www.lucd.info/wp-content/uploads/2019/09/fingers-PCLI-1.png 1024w, https://www.lucd.info/wp-content/uploads/2019/09/fingers-PCLI-1-300x123.png 300w, https://www.lucd.info/wp-content/uploads/2019/09/fingers-PCLI-1-768x315.png 768w, https://www.lucd.info/wp-content/uploads/2019/09/fingers-PCLI-1-720x295.png 720w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure></li></ul></figure>



<p>The following is a write up of a part of session <a rel="noreferrer noopener" href="https://my.vmworld.com/widget/vmware/vmworld19us/us19catalog?src=so_5cd1af8d1a916&amp;cid=7012H000001OK2o&amp;search=HBI1729BU" target="_blank">HBI1729BU</a> ,that was presented at <strong>VMworld US 2019</strong>. </p>



<p>The code shown in this post is also available in the <a rel="noreferrer noopener" aria-label="PowerCLI Community Repository (opens in a new tab)" href="https://github.com/vmware/PowerCLI-Example-Scripts/tree/master/Scripts/At_Your_Fingertips" target="_blank">PowerCLI Community Repository</a>.</p>



<span id="more-6384"></span>



<h2>Concept</h2>



<p>The idea behind this snippet came when I had checked what was in <strong>$global:DefaultVIServers</strong> for the n-th time in a short PowerCLI session. </p>



<p>And it&#8217;s probably not only that specific variable that must be all too familiar to most of us. Any entry in the following list of variables and cmdlets must have been executed by most of us multiple times.</p>



<pre class="wp-block-code"><code>$Global:DefaultVIServer
$Global:DefaultVIServers
$PSVersionTable
Get-Location
Get-Module -Name VMware.PowerCLI</code></pre>



<p>It would be an important timesaver, when the information returned by those instructions, would be permanently in view. <strong>At your fingertips</strong>, so to say.</p>
<p>The use of the <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-6" target="_blank" rel="noopener noreferrer">PowerShell profile(s)</a> and the <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_prompts?view=powershell-6" target="_blank" rel="noopener noreferrer">Prompt function</a>, immediately came to mind.</p>
<p>Not to overload your PS prompt, I decided to show part of the information in the console&#8217;s Window Title bar. That can be done by assigning a value to <strong>$host.ui.RawUI.WindowTitle</strong>.&nbsp;</p>



<h2 class="wp-block-heading">Implementation</h2>



<h3>The Code</h3>



<pre class="wp-block-code"><code>#
# Provide environment information in the PS Console
#
# History:
# 1.0 - August 4th 2019 - LucD
#       Initial version (for session HBI1729BU VMworld US 2019)
#
# 1) PS prompt
# - current (local) time
# - execution time of the previous command
# - shortened PWD
# 2) Window title
# - User/Admin
# - PS-32/54-Edition-Version
# - PCLI version
# - git repo/branch
# - VC/ESXi:defaultServer-User &#91;# connections]

function prompt
{
    # Current time
    $date = (Get-Date).ToString('HH:mm:ss')
    Write-Host -Object '&#91;' -NoNewline
    Write-Host -Object $date -ForegroundColor Cyan -BackgroundColor DarkBlue -NoNewline
    Write-Host -Object ']' -NoNewline

    # Execution time previous command
    $history = Get-History -ErrorAction Ignore -Count 1
    if ($history)
    {
        $time = (&#91;DateTime](New-TimeSpan -Start $history.StartExecutionTime -End $history.EndExecutionTime).Ticks).ToString('HH:mm:ss.ffff')
        Write-host -Object '&#91;' -NoNewLine
        Write-Host -Object "$time" -ForegroundColor Yellow -BackgroundColor DarkBlue -NoNewline
        Write-host -Object '] ' -NoNewLine
    }

    # Shorted PWD
    $path = $pwd.Path.Split('\')
    if ($path.Count -gt 3)
    {
        $path = $path&#91;0], '..', $path&#91;-2], $path&#91;-1]
    }
    Write-Host -Object "$($path -join '\')" -NoNewline

    # Prompt function needs to return something,
    # otherwise the default 'PS>' will be added
    "> "

    # Refresh the window's title
    Set-Title
}

function Set-Title
{
    # Running as Administrator or a regular user
    $userInfo = &#91;Security.Principal.WindowsIdentity]::GetCurrent()
    if ((New-Object Security.Principal.WindowsPrincipal $userInfo).IsInRole(&#91;Security.Principal.WindowsBuiltinRole]::Administrator))
    {
        $role = 'Admin'
    }
    else
    {
        $role = 'User'
    }

    # Usertype user@hostname
    $user = "$role $($userInfo.Name)@$($env:computername)"

    # PowerShell environment/PS version
    $bits = 32
    if (&#91;Environment]::Is64BitProcess)
    {
        $bits = 64
    }
    $ps = " - PS-$($bits): $PSEdition/$($PSVersionTable.PSVersion.ToString())"

    # PowerCLI version (derived from module VMware.PowerCLI)
    $pcliModule = Get-Module -Name VMware.PowerCLI -ListAvailable |
    Sort-Object -Property Version -Descending |
    Select-Object -First 1
    $pcli = " - PCLI: $(if($pcliModule){$pcliModule.Version.ToString()}else{'na'})"

    # If git is present and if in a git controlled folder, display repositoryname/current_branch
    $gitStr = ''
    if ((Get-Command -Name 'git' -CommandType Application -ErrorAction SilentlyContinue).Count -gt 0)
    {
        $gitTopLevel = git rev-parse --show-toplevel 2> $null
        if ($gitTopLevel.Length -ne 0)
        {
            $gitRepo = Split-Path -Path $gitTopLevel -Leaf
            $gitBranch = (git branch | Where-Object { $_ -match "\*" }).Trimstart('* ')
            $gitStr = " - git: $gitRepo/$gitBranch"
        }
    }

    # If there is an open vSphere Server connection
    # display &#91;VC|ESXi] last_connected_server-connected_user &#91;number of open server connections]
    if ($global:defaultviserver)
    {
        $vcObj = (Get-Variable -Scope global -Name 'DefaultVIServer').Value
        if ($vcObj.ProductLine -eq 'vpx')
        {
            $vcSrv = 'VC'
        }
        else
        {
            $vcSrv = 'ESXi'
        }
        $vc = " - $($vcSrv): $($vcObj.Name)-$($vcObj.User) &#91;$($global:DefaultVIServers.Count)]"
    }

    # Update the Window's title
    $host.ui.RawUI.WindowTitle = "$user$ps$pcli$vc$gitStr"
}

# Set title after starting session
Set-Title</code></pre>



<h3 class="wp-block-heading">Annotations</h3>



<p><strong>Line 19-51</strong>: Replacement function for the PS prompt.</p>



<p><strong>Line 22-25</strong>: Current time in the format &#8216;HH:mm:ss&#8217;. Note that &#8216;HH&#8217; asks for a 24-hour value.</p>



<p><strong>Line 28-35</strong>: The execution time of the previous command, in the format &#8216;HH:mm:ss:ffff&#8217;.</p>



<p><strong>Line 28</strong>: The execution time is based on the content of <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_history?view=powershell-6">PS History</a>. With <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/get-history?view=powershell-6">Get-History</a> we obtain the start time of the command, and with <a rel="noreferrer noopener" aria-label="New-TimeSpan (opens in a new tab)" href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/new-timespan?view=powershell-6" target="_blank">New-TimeSpan</a> we obtain the duration for running that command.</p>



<p><strong>Line 38-43</strong>: These lines take the path to the current folder, and shorten that path to only show the start of the path and the last two directories. When the path is shortened, it is  indicated by two dots.</p>



<p><strong>Line 53-114</strong>: Function to populate the Windows Title bar</p>



<p><strong>Line 56-64</strong>: These lines determine if the PS session is started &#8220;As Administrator&#8221; or as a regular user.</p>



<p><strong>Line 67</strong>: The user and station information.</p>



<p><strong>Line 70-75</strong>: The PS edition (Desktop or Core) and the PS version.</p>



<p><strong>Line 78-81</strong>: If installed, the version of VMware PowerCLI. Note that this looks at the VMware.PowerCLI module to obtain that version number.</p>



<p><strong>Line 84-94</strong>: If the git command is present on the station, these lines will check if the current directory is inside a git repository. It will then display the name of the git repository and the current branch.</p>



<p><strong>Line 98-110</strong>: These lines check if there is an open connection to a vSphere Server. It will show if the connected vSphere Server is a vCenter or an ESXi node. </p>



<p><strong>Line 109</strong>: If multiple connections to a vSphere Servers are open, this will display the number of these connections. The vSphere Server that is shown is the last connected one. This corresponds with what is kept in the<strong> $global:DefaultVIServer</strong> variable.</p>



<p><strong>Line 117</strong>: Initial call to the <strong>Set-Title </strong>function. This will populate the Windows Title bar when the PS console is opened.</p>



<h3>Installation</h3>



<p>You can just copy and rename the code to one of the <a rel="noreferrer noopener" aria-label="profile files (opens in a new tab)" href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-6" target="_blank">profile files</a>. To make that process easier, I also provide the following installation script.</p>



<pre class="wp-block-code"><code>[cmdletbinding(SupportsShouldProcess = $true, ConfirmImpact = 'High')]
param(
    #        [Parameter(Mandatory = $true)]
    [ValidateSet('CurrentUserCurrentHost', 'CurrentUserAllHosts',
        'AllUsersCurrentHost', 'AllUsersAllHosts')]
    [string]$Scope,
    [switch]$NoClobber,
    [switch]$Backup,
    [string]$NewProfile = '.\NewProfile.ps1'
)

if ($PSCmdlet.ShouldProcess("$($Profile.$Scope)", "Create $Scope profile"))
{
    $profilePath = $Profile."$Scope"
    Write-Verbose -Message "Target is $profilePath"
    $createProfile = $true
    if (Test-Path -Path $profilePath)
    {
        Write-Verbose -Message "Target exists"
        if ($NoClobber)
        {
            Write-Verbose -Message "Cannot overwrite target due to NoClobber"
            $createProfile = $false
        }
        elseif ($Backup)
        {
            Write-Verbose -Message "Create a backup as $profilePath.bak"
            Copy-Item -Path $profilePath -Destination "$profilePath.bak" -Confirm:$false -Force
        }
        elseif (-not $NoClobber)
        {
            Write-Verbose -Message "Target will be overwritten"
        }
        else
        {
            Write-Verbose -Message "Use -NoClobber:$false or -Backup"
        }
    }
    if ($createProfile)
    {
        if (-not $NewProfile)
        {
            $script:MyInvocation.MyCommand | select *
            $folder = Split-Path -Parent -Path $script:MyInvocation.MyCommand.Path
            $folder = Get-Location
            $NewProfile = "$folder\NewProfile.ps1"
        }
        Write-Verbose -Message "New profile expected at $NewProfile"
        if (Test-Path -Path $NewProfile)
        {
            Write-Verbose -Message "Copy $NewProfile to $profilePath"
            Copy-Item -Path $NewProfile -Destination $profilePath -Confirm:$false
        }
        else
        {
            Write-Warning -Message "Could not find the new profile file!"
            Write-Warning -Message "Use the NewProfile parameter or store a NewProfile.ps1 file in folder $folder."
        }
    }
}</code></pre>



<p>Save the above code to a .ps1 file, let&#8217;s say <strong>install-profile.ps1</strong>. Also copy the profile code to a .ps1 file, let&#8217;s say <strong>newprofile.ps1</strong>.</p>



<p>You can now install this new profile with a simple call.</p>



<pre class="wp-block-code"><code>.\install-profile.ps1 -NewProfile .\NewProfile.ps1 -Scope CurrentUserCurrentHost -Backup </code></pre>



<p>The installation script has a number of parameters:</p>



<ul class="wp-block-list"><li><strong>NewProfile</strong> : the file that contains the profile you want to install</li><li><strong>Scope</strong> : for which Scope you want to install the new profile.</li><li><strong>Backup</strong> : backup the current profile before overwriting it.</li><li><strong>NoClobber</strong> : avoids overwriting an existing profile file.</li></ul>



<h3 class="wp-block-heading">Usage</h3>



<p>When the new profile is installed, and when you restart your console session, you will see the new profile in action.</p>



<p>The following screenshot shows the features of the new profile.</p>



<figure class="wp-block-image"><img decoding="async" width="1024" height="346" src="https://www.lucd.info/wp-content/uploads/2019/09/demo-1024x346.png" alt="" class="wp-image-6413" srcset="https://www.lucd.info/wp-content/uploads/2019/09/demo-1024x346.png 1024w, https://www.lucd.info/wp-content/uploads/2019/09/demo-300x101.png 300w, https://www.lucd.info/wp-content/uploads/2019/09/demo-768x259.png 768w, https://www.lucd.info/wp-content/uploads/2019/09/demo-720x243.png 720w, https://www.lucd.info/wp-content/uploads/2019/09/demo.png 1223w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>And the following short video shows the installation process and the features the profile offers.</p>



<figure class="wp-block-video"><video height="1080" style="aspect-ratio: 1764 / 1080;" width="1764" controls src="https://www.lucd.info/wp-content/uploads/2019/09/VMworld19-Profile.mp4"></video><figcaption>At Your Fingertips</figcaption></figure>



<p>Enjoy!</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2019/09/05/at-your-fingertips/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		<enclosure url="https://www.lucd.info/wp-content/uploads/2019/09/VMworld19-Profile.mp4" length="3867096" type="video/mp4" />

			</item>
		<item>
		<title>TA2650 scripts &#8211; Part 3 &#8211; Checking cluster node configurations</title>
		<link>https://www.lucd.info/2009/09/09/ta2650-scripts-part-3-checking-cluster-node-configurations/</link>
					<comments>https://www.lucd.info/2009/09/09/ta2650-scripts-part-3-checking-cluster-node-configurations/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Tue, 08 Sep 2009 23:31:05 +0000</pubDate>
				<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[TA2650]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">http://lucd.info/?p=162</guid>

					<description><![CDATA[With the cluster profile XML file created in TA2650 scripts – Part 1 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>With the cluster profile XML file created in <a href="https://lucd.info/2009/09/05/ta2650-scripts-part-1-profiling-your-vsphere-environment/" target="_blank">TA2650 scripts – Part 1  – Profiling your vSphere environment</a> you can verify the configuration of the nodes against a reference node.</p>
<p><span id="more-162"></span>In the XML file the configuration settings of each node are present in the <strong>Config</strong> nodes.</p>
<p><img decoding="async" class="aligncenter size-full wp-image-173" title="cluster-node-compare" src="https://lucd.info/wp-content/uploads/2009/09/cluster-node-compare.png" alt="cluster-node-compare" width="542" height="149" srcset="https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare.png 542w, https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare-300x82.png 300w" sizes="(max-width: 542px) 100vw, 542px" /></p>
<p>With the following script you select one of the nodes as the <strong>reference node</strong> and the script will then compare the <strong>config properties</strong> of all the <strong>other nodes</strong> against this reference node.</p>
<p><script src="https://PoshCode.org/embed/1313" type="text/javascript"></script></p>
<p>The script will produce a CSV file that contains all differences.</p>
<p><strong>Note</strong> that a lot of these differences are quite obvious, like for example hostname, MAC address&#8230;, and can thus be safely ignored during the review.</p>
<p>The CSV file has this layout</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-167" title="cluster-node-compare-2" src="https://lucd.info/wp-content/uploads/2009/09/cluster-node-compare-2-1024x213.png" alt="cluster-node-compare-2" width="1024" height="213" srcset="https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare-2-1024x213.png 1024w, https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare-2-300x62.png 300w, https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare-2.png 1069w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></p>
<p>The first column, named Path, is the XMLPath to the property in the XML file.</p>
<p>The 2nd and 3rd columns show the name of the reference node (RefHost) and the name of the node (CmpHost) that was compared against the reference node.</p>
<p>The Name column shows the name of the property.</p>
<p>The RefValue and CmpValue show the property values that were found on the reference node and on the node that was compared against the reference node.</p>
<p>The AttributeDiscrepancy and the ChildrenDiscrepancy columns are Boolean flags that show if the script at one point lost synchronisation between the RefHost and the CmpHost for the attributes or for the child nodes.</p>
<p>As an example of the possible benefit of such a comparison, I discovered that on my test environment the CSV file showed a difference for the <strong>Inventory/Cluster/Host/Config/Firewall/Ruleset</strong> <strong>Count</strong> between the two cluster nodes.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-170" title="cluster-node-compare-3" src="https://lucd.info/wp-content/uploads/2009/09/cluster-node-compare-3-1024x213.png" alt="cluster-node-compare-3" width="1024" height="213" srcset="https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare-3-1024x213.png 1024w, https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare-3-300x62.png 300w, https://www.lucd.info/wp-content/uploads/2009/09/cluster-node-compare-3.png 1069w" sizes="auto, (max-width: 1024px) 100vw, 1024px" />This indicated that the firewall rules on both ESX nodes were not the same. And indeed after further checking I discovered that I forgot to active a firewall rule on the 2nd node.</p>
<p>Note that current script is not too intelligent. It will not try to synchronise between the two nodes when one of the nodes is missing an entry. As an example you will notice that the firewall rules will run async from a certain point onwards. On the other hand this also gives you a good indication where the problem is located. In this case the <strong>aam</strong> firewall rule was missing on the 2nd node.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2009/09/09/ta2650-scripts-part-3-checking-cluster-node-configurations/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>TA2650 scripts &#8211; Part 2  &#8211; Using the profile XML file for SDK programming</title>
		<link>https://www.lucd.info/2009/09/08/ta2650-scripts-part-1-using-the-profile-xml-file-for-sdk-programming/</link>
					<comments>https://www.lucd.info/2009/09/08/ta2650-scripts-part-1-using-the-profile-xml-file-for-sdk-programming/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Mon, 07 Sep 2009 23:41:55 +0000</pubDate>
				<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[TA2650]]></category>
		<category><![CDATA[SDK]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">http://lucd.info/?p=106</guid>

					<description><![CDATA[The XML file that can be created with the script from TA2650 scripts [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>The XML file that can be created with the script from <a href="https://lucd.info/2009/09/05/ta2650-scripts-part-1-profiling-your-vsphere-environment/" target="_blank">TA2650 scripts – Part 1  – Profiling your vSphere environment</a> can also be used to assist you when you need to use the SDK.<span id="more-106"></span></p>
<p>As an example let&#8217;s take the &#8220;<strong>Enable VM Monitoring</strong>&#8221; option for a cluster.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-130" title="DRS-VM-monitoring" src="https://lucd.info/wp-content/uploads/2009/09/DRS-VM-monitoring1.png" alt="DRS-VM-monitoring" width="667" height="181" srcset="https://www.lucd.info/wp-content/uploads/2009/09/DRS-VM-monitoring1.png 667w, https://www.lucd.info/wp-content/uploads/2009/09/DRS-VM-monitoring1-300x81.png 300w" sizes="auto, (max-width: 667px) 100vw, 667px" /></p>
<p>This option belongs to the <strong>HA</strong> settings of a cluster. The only fact you have to know, is that the HA settings of a cluster are stored under the DAS properties in the SDK. And that is most probably the case for historical reasons.</p>
<p>In the XML file that contains the cluster&#8217;s profile we can easily find the property.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-133" title="DAS-VM-monitoring-1" src="https://lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-12.png" alt="DAS-VM-monitoring-1" width="708" height="328" srcset="https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-12.png 708w, https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-12-300x138.png 300w" sizes="auto, (max-width: 708px) 100vw, 708px" /></p>
<p>The next step is to find out how we can change the property.A method I use regularly, and which works in most cases, is the following.</p>
<p>The <strong>VmMonitoring</strong> property belongs to the <strong>ClusterDasConfigInfo</strong> object as can be seen in the <strong>Type</strong> attribute..</p>
<p>In the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/index.html" target="_blank">vSphere API Reference Documentation</a> we go, via the Data Object Types, to the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.cluster.DasConfigInfo.html" target="_blank">ClusterDasConfigInfo</a> object. At the top of the right panel we see that the object is a property of the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.cluster.ConfigSpec.html#field_detail" target="_blank">ClusterConfigSpec</a>.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-119" title="DAS-VM-monitoring-2" src="https://lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-2.png" alt="DAS-VM-monitoring-2" width="653" height="197" srcset="https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-2.png 653w, https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-2-300x90.png 300w" sizes="auto, (max-width: 653px) 100vw, 653px" /></p>
<p>Via the hyperlink we go to the description of that object. On the reference page we see that the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.cluster.ConfigSpec.html#field_detail" target="_blank">ClusterConfigSpec</a> object is a parameter to the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ClusterComputeResource.html#reconfigure" target="_blank">ReconfigureCluster_Task</a> method.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-121" title="DAS-VM-monitoring-3" src="https://lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-31.png" alt="DAS-VM-monitoring-3" width="791" height="189" srcset="https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-31.png 791w, https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-31-300x71.png 300w" sizes="auto, (max-width: 791px) 100vw, 791px" /></p>
<p>The <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ClusterComputeResource.html#reconfigure" target="_blank">ReconfigureCluster_Task</a> page contains a message that states we should use the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ComputeResource.html#reconfigureEx" target="_blank">ReconfigureComputeResource_Task</a> since API 2.5. Since we are working in a vSphere environment, which is <strong>API 4.0</strong>, we go for the new method.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-123" title="DAS-VM-monitoring-4" src="https://lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-41.png" alt="DAS-VM-monitoring-4" width="563" height="147" srcset="https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-41.png 563w, https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-41-300x78.png 300w" sizes="auto, (max-width: 563px) 100vw, 563px" />On the reference page for the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk400pubs/ReferenceGuide/vim.ComputeResource.html#reconfigureEx" target="_blank">ReconfigureComputeResource_Task</a> method we see which parameters we will need.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-124" title="DAS-VM-monitoring-5" src="https://lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-5.png" alt="DAS-VM-monitoring-5" width="963" height="201" srcset="https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-5.png 963w, https://www.lucd.info/wp-content/uploads/2009/09/DAS-VM-monitoring-5-300x62.png 300w" sizes="auto, (max-width: 963px) 100vw, 963px" /></p>
<p>How to call _Task methods from the SDK will be the subject of another post.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2009/09/08/ta2650-scripts-part-1-using-the-profile-xml-file-for-sdk-programming/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<item>
		<title>TA2650 scripts &#8211; Part 1 &#8211; Profiling your vSphere environment</title>
		<link>https://www.lucd.info/2009/09/05/ta2650-scripts-part-1-profiling-your-vsphere-environment/</link>
					<comments>https://www.lucd.info/2009/09/05/ta2650-scripts-part-1-profiling-your-vsphere-environment/#comments</comments>
		
		<dc:creator><![CDATA[LucD]]></dc:creator>
		<pubDate>Sat, 05 Sep 2009 21:15:02 +0000</pubDate>
				<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[TA2650]]></category>
		<category><![CDATA[XML]]></category>
		<guid isPermaLink="false">http://lucd.info/?p=7</guid>

					<description><![CDATA[Scripts from TA2650 - Profiling your vSphere environment.]]></description>
										<content:encoded><![CDATA[<p>During VMworld 2009 in San Francisco, Hal Rottenberg and myself presented a session called &#8220;TA2650 &#8211; Take PowerCLI to the Next Level&#8221;. During the session we promised to publish the scripts we showed (and those we did not show due to lack of time).</p>
<p>This is part 1 of these scripts. This script shows and explains how I used PowerShell to export the configuration of my vSphere environment, or part of it, to an <a href="https://en.wikipedia.org/wiki/Xml" target="_blank" rel="noopener noreferrer">XML</a> file.<span id="more-7"></span></p>
<p>If you investigate any of the Managed Objects which are based on the <a href="https://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/vim.ManagedEntity.html" target="_blank" rel="noopener noreferrer">ManagedEntity</a> object, in your vSPhere environment, you will notice that all configuration parameters are contained in an object under the property called <strong>configuration</strong> or <strong>configurationEx</strong>.</p>
<p>For example within a <strong>HostSystem</strong> object there is a <strong>configuration</strong> object.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-55" title="hostsystem-config" src="https://lucd.info/wp-content/uploads/2009/09/hostsystem-config2-1024x288.png" alt="hostsystem-config" width="1024" height="288" srcset="https://www.lucd.info/wp-content/uploads/2009/09/hostsystem-config2-1024x288.png 1024w, https://www.lucd.info/wp-content/uploads/2009/09/hostsystem-config2-300x84.png 300w, https://www.lucd.info/wp-content/uploads/2009/09/hostsystem-config2.png 1026w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></p>
<p>Within a <strong>ComputeResource</strong> object there is since API 2.5 a <strong>configurationEx</strong> object.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-large wp-image-58" title="compute-configEx" src="https://lucd.info/wp-content/uploads/2009/09/compute-configEx2-1024x223.png" alt="compute-configEx" width="1024" height="223" srcset="https://www.lucd.info/wp-content/uploads/2009/09/compute-configEx2-1024x223.png 1024w, https://www.lucd.info/wp-content/uploads/2009/09/compute-configEx2-300x65.png 300w, https://www.lucd.info/wp-content/uploads/2009/09/compute-configEx2.png 1131w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></p>
<p>If we could &#8220;dump&#8221; the content in a usable format to an external file, we would have an exact description of the Managed Object on file.</p>
<p>That&#8217;s when I came up with the following script. It will start from an vSphere inventory location, and from there it will write all the configuration parameters to an XML file.</p>
<p>The concept of recursively investigating all the properties of a managed object has been done before, in a somewhat different form, by <a href="https://peetersonline.nl/" target="_blank" rel="noopener noreferrer">Hugo Peeters</a>. See his <a title="Permanent Link: List ALL properties and subproperties of a variable in Powershell" rel="bookmark" href="https://www.peetersonline.nl/index.php/powershell/list-all-properties-and-subproperties-of-a-variable-in-powershell/">List ALL properties and subproperties of a variable in Powershell</a> article.</p>
<p>The following script exports all properties to an XML file.</p>
<p><script type="text/javascript" src="https://PoshCode.org/embed/1312"></script></p>
<p>The script takes a number of parameters that determine what will be exported to the XML file.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-176" title="vProfile-params" src="https://lucd.info/wp-content/uploads/2009/09/vProfile-params.png" alt="vProfile-params" width="868" height="135" srcset="https://www.lucd.info/wp-content/uploads/2009/09/vProfile-params.png 868w, https://www.lucd.info/wp-content/uploads/2009/09/vProfile-params-300x46.png 300w" sizes="auto, (max-width: 868px) 100vw, 868px" /></p>
<p>Looking at resulting XML file (which can be quite big depending on the size of your vSPhere environment), you notice that the <strong>Hosts &amp; Clusters</strong> view on the cluster is present. For each of the cluster elements the XML file also contains all the configuration properties.<br />
<img loading="lazy" decoding="async" class="aligncenter size-full wp-image-94" title="clus1-xml" src="https://lucd.info/wp-content/uploads/2009/09/clus1-xml.png" alt="clus1-xml" width="559" height="162" srcset="https://www.lucd.info/wp-content/uploads/2009/09/clus1-xml.png 559w, https://www.lucd.info/wp-content/uploads/2009/09/clus1-xml-300x86.png 300w" sizes="auto, (max-width: 559px) 100vw, 559px" /></p><pre class="urvanov-syntax-highlighter-plain-tag">&lt;span style=&quot;text-decoration: underline;&quot;&gt;Note&lt;/span&gt;: I use &lt;a href=&quot;http://www.xmlpad.com/xmlpad3.htm&quot;&gt;XMLPad 3&lt;/a&gt; to browse the XML files. The screenshot shows the Table View.</pre><p>In the Config and ConfigurationEx nodes you can find all the properties of these objects. This gives you an easy and offline method if looking up specific settings and configuration options for the cluster.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-102" title="ntp-config" src="https://lucd.info/wp-content/uploads/2009/09/ntp-config4.png" alt="ntp-config" width="585" height="290" srcset="https://www.lucd.info/wp-content/uploads/2009/09/ntp-config4.png 585w, https://www.lucd.info/wp-content/uploads/2009/09/ntp-config4-300x148.png 300w" sizes="auto, (max-width: 585px) 100vw, 585px" /></p>
<p>The previous screenshot shows how you can, for example,  easily <strong>report</strong> on the <a href="https://en.wikipedia.org/wiki/Network_Time_Protocol" target="_blank" rel="noopener noreferrer">NTP</a> settings of an ESX server.</p>
<p>Another useful feature is that these XML files allow you to keep an <strong>audit track</strong> of the configuration of your vSphere environment. There are a number of 3rd party tools available that allow you compare XML files.</p>
<p>The XML file also tells you what <strong>type</strong> a specific property is. For arrays the script uses a special convention to show the array elements. Since an XML nodename can&#8217;t contain square brackets, the array elements are shown as <strong>Server-0-</strong> instead of <strong>Server[0]</strong>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.lucd.info/2009/09/05/ta2650-scripts-part-1-profiling-your-vsphere-environment/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
	</channel>
</rss>
