<?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; function</title>
	<atom:link href="http://www.peetersonline.nl/index.php/tag/function/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>User Confirmation in Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/user-confirmation-in-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/user-confirmation-in-powershell/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 13:48:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=407</guid>
		<description><![CDATA[Built-in cmdlets usually offer the -Confirm parameter whenever you need user confirmation. When writing your own scripts, you might want to ask the eventual user of the script for confirmation yourself. This handy little function (store it in your profile!) allows you to ask for confirmation whenever, where-ever. (Try not to bug your users too <a href='http://www.peetersonline.nl/index.php/powershell/user-confirmation-in-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Built-in cmdlets usually offer the -Confirm parameter whenever you need user confirmation. When writing your own scripts, you might want to ask the eventual user of the script for confirmation yourself. This handy little function (store it in your profile!) allows you to ask for confirmation whenever, where-ever. (Try not to bug your users too much.)</p>
<p><span id="more-407"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Description: Ask a user to answer a question with either yes or no.</span>
&nbsp;
<span style="color: #008000;"># Example use: </span>
<span style="color: #008000;"># If (Ask-YesOrNo)</span>
<span style="color: #008000;"># 	{ </span>
<span style="color: #008000;">#	# User has confirmed</span>
<span style="color: #008000;">#	...</span>
<span style="color: #008000;">#	}</span>
<span style="color: #008000;">#	Else</span>
<span style="color: #008000;">#	{</span>
<span style="color: #008000;">#	# User did not confirm</span>
<span style="color: #008000;">#	...</span>
<span style="color: #008000;">#	}</span>
&nbsp;
<span style="color: #0000FF;">Function</span> Ask<span style="color: pink;">-</span>YesOrNo
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$title</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Confirm&quot;</span><span style="color: pink;">,</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$message</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Are you sure?&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$choiceYes</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Management.Automation.Host.ChoiceDescription <span style="color: #800000;">&quot;&amp;Yes&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Answer Yes.&quot;</span>
	<span style="color: #800080;">$choiceNo</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Management.Automation.Host.ChoiceDescription <span style="color: #800000;">&quot;&amp;No&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Answer No.&quot;</span>
	<span style="color: #800080;">$options</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Management.Automation.Host.ChoiceDescription<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$choiceYes</span><span style="color: pink;">,</span> <span style="color: #800080;">$choiceNo</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$result</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.ui.PromptForChoice<span style="color: #000000;">&#40;</span><span style="color: #800080;">$title</span><span style="color: pink;">,</span> <span style="color: #800080;">$message</span><span style="color: pink;">,</span> <span style="color: #800080;">$options</span><span style="color: pink;">,</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0000FF;">switch</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$result</span><span style="color: #000000;">&#41;</span>
    	<span style="color: #000000;">&#123;</span>
			<span style="color: #804000;">0</span> 
			<span style="color: #000000;">&#123;</span>
			<span style="color: #0000FF;">Return</span> <span style="color: #800080;">$true</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #804000;">1</span> 
			<span style="color: #000000;">&#123;</span>
			<span style="color: #0000FF;">Return</span> <span style="color: #800080;">$false</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/user-confirmation-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Translate Vml to LUN Path with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/translate-vml-to-lun-path-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/translate-vml-to-lun-path-with-powershell/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 10:01:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[VI Toolkit]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=365</guid>
		<description><![CDATA[While checking the vmkernel logs on our VMware ESX Servers today, I ran into some errors referencing luns using a vml string. It looks something like this: vml.827149017315617. I would like to know what lun this error is referencing, but I prefer the LUN Path notation, e.g.: vmhba1:2:137. So I wrote this Powershell VI Toolkit function <a href='http://www.peetersonline.nl/index.php/vmware/translate-vml-to-lun-path-with-powershell/'>[...]</a>
Related posts:<ol>
<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>
<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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>While checking the vmkernel logs on our <a href="http://www.vmware.com/" target='_blank'>VMware</a> ESX Servers today, I ran into some errors referencing luns using a vml string. It looks something like this: vml.827149017315617. I would like to know what lun this error is referencing, but I prefer the LUN Path notation, e.g.: vmhba1:2:137. So I wrote this <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> <a href="http://www.vmware.com/sdk/vitk_win/index.html" target='_blank'>VI Toolkit</a> function that can translate the vml into the lun path:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Function: Translate a VML (e.g.: vml.9364839746917650) to a Lun Path (e.g.: vmhba1:2:137)</span>
&nbsp;
<span style="color: #0000FF;">function</span> Translate<span style="color: pink;">-</span>VmlToLunPath
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$VMHostName</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Vml</span>
	<span style="color: #000000;">&#41;</span>
	<span style="color: #0000FF;">Return</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMHost <span style="color: #800080;">$VMhostName</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>ScsiLun <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.ConsoleDeviceName <span style="color: #FF0000;">-match</span> <span style="color: #800080;">$Vml</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.CanonicalName
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Feed it a host name and a vml string and it will return the lun path. Here&#8217;s an example script that uses this function when looking for LUNs with SCSI Reservation Errors:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Example use in a script: Get LUNs with SCSI Reservation Conflicts</span>
&nbsp;
<span style="color: #800080;">$VIServerName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;myVIServer&quot;</span>
<span style="color: #800080;">$NumLines</span> <span style="color: pink;">=</span> <span style="color: #804000;">1000</span>
&nbsp;
<span style="color: #800080;">$VC</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$VIServerName</span>
&nbsp;
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VMHost</span> <span style="color: #0000FF;">in</span> Get<span style="color: pink;">-</span>VMHost<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Log</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VMHost</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>Log <span style="color: #008080; font-style: italic;">-Key</span> vmkernel <span style="color: pink;">-</span>NumLines <span style="color: #800080;">$NumLines</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$MatchedEntries</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Log</span>.Entries <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;reservation&quot;</span> <span style="color: #FF0000;">-and</span> <span style="color: #000080;">$_</span> <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;vml.\d*&quot;</span><span style="color: #000000;">&#125;</span>
		<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VmlId</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$matches</span>.values<span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$myObj</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> VMHost<span style="color: pink;">,</span> ErrorLun
			<span style="color: #800080;">$myObj</span>.VMHost <span style="color: pink;">=</span> <span style="color: #800080;">$VMHost</span>.Name
			<span style="color: #800080;">$myObj</span>.ErrorLun <span style="color: pink;">=</span> Translate<span style="color: pink;">-</span>VmlToLunPath <span style="color: pink;">-</span>VMHostName <span style="color: #800080;">$VMHost</span>.Name <span style="color: pink;">-</span>Vml <span style="color: #800080;">$VmlId</span>
			<span style="color: #0000FF;">Return</span> <span style="color: #800080;">$myObj</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #008080; font-style: italic;">-Confirm</span>:$False</pre></div></div>

<p>Enjoy!<br />
Hugo</p>
<p>Related posts:<ol>
<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>
<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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/translate-vml-to-lun-path-with-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Regular Expression Magic in Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/regular-expression-magic-in-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/regular-expression-magic-in-powershell/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 14:42:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Regular Expressions]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=291</guid>
		<description><![CDATA[I have been looking at regular expressions in Windows Powershell recently. Although it seems very complex, the power of regular expressions (regex) is worth the effort! Think about server naming conventions for example. It&#8217;s easy for a human to recognise a server name that begins with a location code and contains a status (Development, Test, <a href='http://www.peetersonline.nl/index.php/powershell/regular-expression-magic-in-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I have been looking at regular expressions in Windows <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> recently. Although it seems very complex, the power of regular expressions (regex) is worth the effort! Think about server naming conventions for example. It&#8217;s easy for a human to recognise a server name that begins with a location code and contains a status (Development, Test, Acceptance or Production) amongst other things. RegEx allows you to learn <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> to recognise the same things.</p>
<p>The attached script contains a function that finds matches for a regular expresion and converts the named matches to object properties. Sounds complex? Take a look at this example for server names:</p>
<p><a href="http://www.peetersonline.nl/wp-content/regex.jpg"><img class="alignnone size-full wp-image-292" title="RegEx" src="http://www.peetersonline.nl/wp-content/regex.jpg" alt="RegEx" width="562" height="328" /></a></p>
<p>If you can create the regular expression, this function does the matching and objectizing. It requires <strong>no modification</strong> <strong>at all</strong> for working with regular expressions that match other kinds of things, because you name the matching groups inside the regex definition. Cool stuff!</p>
<p><a href="http://www.peetersonline.nl/wp-content/obj-regex.txt">Obj-RegEx (Rename to .ps1)</a></p>
<p>Enjoy!</p>
<p>Hugo</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/regular-expression-magic-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Puzzle</title>
		<link>http://www.peetersonline.nl/index.php/powershell/puzzle/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/puzzle/#comments</comments>
		<pubDate>Wed, 21 Jan 2009 06:00:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[puzzle]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=283</guid>
		<description><![CDATA[Just having a bit of fun with Powershell: 48 6F 6C 64 20 66 61 73 74 20 74 6F 20 64 72 65 61 6D 73 A 46 6F 72 20 69 66 20 64 72 65 61 6D 73 20 64 69 65 A 4C 69 66 65 20 69 73 20 61 <a href='http://www.peetersonline.nl/index.php/powershell/puzzle/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Just having a bit of fun with <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a>:</p>
<blockquote><p>48 6F 6C 64 20 66 61 73 74 20 74 6F 20 64 72 65 61 6D 73 A 46 6F 72 20 69 66 20 64 72 65 61 6D 73 20 64 69 65 A 4C 69 66 65 20 69 73 20 61 20 62 72 6F 6B 65 6E 2D 77 69 6E 67 65 64 20 62 69 72 64 A54 68 61 74 20 63 61 6E 6E 6F 74 20 66 6C 79 2E A 48 6F 6C 64 20 66 61 73 74 20 74 6F 20 64 72 65 61 6D 73 A 46 6F 72 20 77 68 65 6E 20 64 72 65 61 6D 73 20 67 6F A 4C 69 66 65 20 69 73 20 61 20 62 61 72 72 65 6E 20 66 69 65 6C 64 A 46 72 6F 7A 65 6E 20 77 69 74 68 20 73 6E 6F 77 2E 20 A A 2D 2D 4C 61 6E 67 73 74 6F 6E 20 48 75 67 68 65 73</p></blockquote>
<p>Solution:<br />
<a href="http://www.peetersonline.nl/wp-content/convert-texttohexandback.ps1">convert-texttohexandback</a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/puzzle/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>From HEX to DEC and back</title>
		<link>http://www.peetersonline.nl/index.php/powershell/from-hex-to-dec-and-back/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/from-hex-to-dec-and-back/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 06:00:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[decimal]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[hexadecimal]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=280</guid>
		<description><![CDATA[Why do computer nerds mix up Halloween and Christmas? Because 31 OCT = 25 DEC :) I always mix up the commands used to convert integers to and from decimal, hexadecimal and octal in Powershell. That&#8217;s why I wrote these functions and put them in my profile: # Description: Coverts a decimal into a hexadecimal <a href='http://www.peetersonline.nl/index.php/powershell/from-hex-to-dec-and-back/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<blockquote><p>Why do computer nerds mix up Halloween and Christmas? Because 31 OCT = 25 DEC :)</p></blockquote>
<p>I always mix up the commands used to convert integers to and from decimal, hexadecimal and octal in <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a>. That&#8217;s why I wrote these functions and put them in my profile:</p>
<blockquote><p># Description: Coverts a decimal into a hexadecimal</p>
<p>function Convert-DECtoHEX<br />
{<br />
param($DEC)<br />
ForEach ($value in $DEC)<br />
{<br />
&#8220;{0:x}&#8221; -f [Int]$value<br />
}<br />
}</p></blockquote>
<blockquote><p># Description: Coverts a hexadecimal into a decimal</p>
<p>function Convert-HEXtoDEC<br />
{<br />
param($HEX)<br />
ForEach ($value in $HEX)<br />
{<br />
[Convert]::ToInt32($value,16)<br />
}<br />
}</p></blockquote>
<blockquote><p># Description: Coverts an octal into a decimal</p>
<p>function Convert-OCTtoDEC<br />
{<br />
param($OCT)<br />
ForEach ($value in $OCT)<br />
{<br />
[Convert]::ToInt32($value,8)<br />
}<br />
}</p></blockquote>
<p>Here are some example uses:<br />
<a href="http://www.peetersonline.nl/wp-content/2009-01-19_112552.jpg"><img class="alignnone size-full wp-image-281" title="2009-01-19_112552" src="http://www.peetersonline.nl/wp-content/2009-01-19_112552.jpg" alt="2009-01-19_112552" width="310" height="346" /></a></p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/from-hex-to-dec-and-back/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Compare ESX configurations with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/compare-esx-configurations-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/compare-esx-configurations-with-powershell/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 08:00:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[datastores]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[portgroups]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[VI Toolkit]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=221</guid>
		<description><![CDATA[One of the challenges in managing a large VMware Infrastructure is keeping all ESX Servers within a cluster equal. This is essential for having vmotion capabilities and therefore essential for a solid HA configuration. I have showed you earlier how to add the LUN Count for each ESX Server to your VI Client. This allows you <a href='http://www.peetersonline.nl/index.php/vmware/compare-esx-configurations-with-powershell/'>[...]</a>
Related posts:<ol>
<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>
<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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>One of the challenges in managing a large <a href="http://www.vmware.com/" target='_blank'>VMware</a> Infrastructure is keeping all ESX Servers within a cluster equal. This is essential for having vmotion capabilities and therefore essential for a solid HA configuration. I have <a href="http://www.peetersonline.nl/index.php/vmware/add-snapshot-information-to-the-vi-client-using-powershell/">showed you earlier</a> how to add the <a href="http://www.peetersonline.nl/index.php/vmware/add-custom-fields-to-vi-client-with-powershell-samples/">LUN Count</a> for each ESX Server to your VI Client. This allows you to spot differences quickly. But finding exactly which datastores are missing on which ESX Server can be a bigger challenge.</p>
<p>Here are some small functions that can help you determine where the major differences are.</p>
<p>Comparing datastores:</p>
<blockquote><p>function Compare-VMHostDatastores<br />
{<br />
param([string]$host1,[string]$host2)<br />
$a = Get-VMHost $host1 | Get-Datastore | %{$_.Name}<br />
$b = Get-VMHost $host2 | Get-Datastore | %{$_.Name}<br />
Compare-Object $a $b<br />
}</p></blockquote>
<blockquote><p>Compare-VMHostDatastores esxServer1 esxServer2</p>
<p>InputObject                         SideIndicator<br />
&#8212;&#8212;&#8212;&#8211;                                &#8212;&#8212;&#8212;&#8212;-<br />
esxServer1_Local             &lt;=<br />
esxServer2_Local             =&gt;<br />
DATASTORE_TEST1         =&gt;</p></blockquote>
<p>And comparing Port Groups:</p>
<blockquote><p>function Compare-VMHostPortgroups<br />
{<br />
param([string]$host1,[string]$host2)<br />
$a = Get-VirtualPortGroup (Get-VMHost $host1) | %{$_.Name}<br />
$b = Get-VirtualPortGroup (Get-VMHost $host2) | %{$_.Name}<br />
Compare-Object $a $b<br />
}</p></blockquote>
<blockquote><p>Compare-VMHostPortgroups esxServer1 esxServer2</p>
<p>InputObject                SideIndicator<br />
&#8212;&#8212;&#8212;&#8211;                      &#8212;&#8212;&#8212;&#8212;-<br />
PortGroup_TEST     &lt;=<br />
Internal                       &lt;=</p></blockquote>
<p>Maybe you prefer to go the other way around and check to which ESX servers a specific datastore is attached?</p>
<blockquote><p>function Get-DatastoreHosts<br />
{<br />
param([string]$datastore)<br />
Get-VMHost -Datastore (Get-Datastore $datastore) | Sort Name | %{$_.Name}<br />
}</p></blockquote>
<blockquote><p>PS D:Scripts&gt; Get-DatastoreHosts DATASTORE_TEST1</p>
<p>esxServer2<br />
esxServer3</p></blockquote>
<p>Thank <a href="http://www.microsoft.com" target='_blank'>Microsoft</a> for <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> and the Compare-Object cmdlet!</p>
<p>Hugo</p>
<p>Related posts:<ol>
<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>
<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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/compare-esx-configurations-with-powershell/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Countdown to 2009</title>
		<link>http://www.peetersonline.nl/index.php/powershell/countdown-to-2009/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/countdown-to-2009/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 13:05:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[countdown]]></category>
		<category><![CDATA[Fun]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=207</guid>
		<description><![CDATA[function CountDown {  While ((Get-Date).Year -lt 2009)  {   Clear-Host   Write-Host &#8220;COUNTDOWN TO 2009:&#8221;   (Get-Date &#8220;1/1/2009 0:00&#8243;) &#8211; (Get-Date) &#124; Format-Table Days, Hours, Minutes, Seconds -AutoSize   Write-Host &#8220;Countdown brought to you by:&#8221;   Write-Host &#8220;http://www.peetersonline.nl&#8221;   Start-Sleep -Seconds 1  }  Clear-Host  Write-Host &#8220;HAPPY NEW YEAR!&#8221;  Write-Host &#8220;from Hugo at http://www.peetersonline.nl&#8221; } CountDown Happy Holidays to all of you! <a href='http://www.peetersonline.nl/index.php/powershell/countdown-to-2009/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<blockquote><p>function CountDown<br />
{<br />
 While ((Get-Date).Year -lt 2009)<br />
 {<br />
  Clear-Host<br />
  Write-Host &#8220;COUNTDOWN TO 2009:&#8221;<br />
  (Get-Date &#8220;1/1/2009 0:00&#8243;) &#8211; (Get-Date) | Format-Table Days, Hours, Minutes, Seconds -AutoSize<br />
  Write-Host &#8220;Countdown brought to you by:&#8221;<br />
  Write-Host &#8220;<a href="http://www.peetersonline.nl">http://www.peetersonline.nl</a>&#8221;<br />
  Start-Sleep -Seconds 1<br />
 }<br />
 Clear-Host<br />
 Write-Host &#8220;HAPPY NEW YEAR!&#8221;<br />
 Write-Host &#8220;from Hugo at <a href="http://www.peetersonline.nl">http://www.peetersonline.nl</a>&#8221;<br />
}<br />
CountDown</p></blockquote>
<p>Happy Holidays to all of you!</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/countdown-to-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershell function to find event log explanations</title>
		<link>http://www.peetersonline.nl/index.php/powershell/powershell-function-to-find-event-log-explanations/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/powershell-function-to-find-event-log-explanations/#comments</comments>
		<pubDate>Fri, 12 Dec 2008 08:45:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Event]]></category>
		<category><![CDATA[Event Log]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Internet]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/index.php/powershell/powershell-function-to-find-event-log-explanations/</guid>
		<description><![CDATA[Today I am attending the Dutch VMware User Group (VMUG) Meeting. No doubt I&#8217;ll return with lost of inspiration for new Powershell VI Toolkit scripts. In the meantime, I will show you a nifty little function that will come in handy if you are troubleshooting Windows Server Event Log errors and / or warings. The <a href='http://www.peetersonline.nl/index.php/powershell/powershell-function-to-find-event-log-explanations/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Today I am attending the Dutch <a href="http://www.vmware.com/" target='_blank'>VMware</a> User Group (<a href="http://www.vmug.nl/">VMUG</a>) Meeting. No doubt I&#8217;ll return with lost of inspiration for new <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> <a href="http://www.vmware.com/sdk/vitk_win/index.html" target='_blank'>VI Toolkit</a> scripts.<br />
In the meantime, I will show you a nifty little function that will come in handy if you are troubleshooting Windows Server Event Log errors and / or warings. The usage is super-simple:</p>
<blockquote><p>Find-Event EventID [Source]<br />
For example: Find-Event 18056<br />
Or: Find-Event 1 MSSQLServer</p>
</blockquote>
<p>What it does? Give it a go (it&#8217;s harmless)&#8230; ;)</p>
<p>Here&#8217;s the code:</p>
<p><span id="more-122"></span></p>
<blockquote><p>Function Find-Event<br />
	{<br />
	param($EventID=&#8221;blank&#8221;,$Source)<br />
	If ($EventID -eq &#8220;blank&#8221;)<br />
		{<br />
		Write-Warning &#8220;USAGE: Find-Event [-EventID] <EVENTID> [[-Source] <SOURCE>]&#8221;<br />
		}<br />
	Else<br />
		{<br />
		(New-Object -ComObject Shell.Application).Open(&#8220;http://www.eventid.net/display.asp?eventID=$EventID&#038;source=$Source&#8221;)<br />
		}<br />
	}</p>
</blockquote>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/powershell-function-to-find-event-log-explanations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handy little function: Create-Script</title>
		<link>http://www.peetersonline.nl/index.php/powershell/handy-little-function-create-script/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/handy-little-function-create-script/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 08:12:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/index.php/powershell/handy-little-function-create-script/</guid>
		<description><![CDATA[One of the great features of Windows Powershell is the combination of the rich scripting language and the interactive shell. I often find myself playing around in the interactive shell until I know how to get the information I need. Then I start to put the code into a script for easy use. (And to <a href='http://www.peetersonline.nl/index.php/powershell/handy-little-function-create-script/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>One of the great features of Windows <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> is the combination of the rich scripting language and the interactive shell. I often find myself playing around in the interactive shell until I know how to get the information I need. Then I start to put the code into a script for easy use. (And to share it with you, of course.) And although the shell allows for copy/paste, I wouldn&#8217;t be much of a scripting enthusiast if I didn&#8217;t want that to be easier ;)<br />
Enter Create-Script. This little function belongs in any scripter&#8217;s profile. It copies your entire history into a file and opens it for you. Just remove the obsolete lines and add formatting and comment and your script is as good as done!</p>
<blockquote><p>function Create-Script<br />
   {<br />
   $ScriptFile = &#8216;D:\scripts\newscript.ps1&#8242;<br />
   Remove-Item $ScriptFile -Confirm<br />
   ForEach ($i in (Get-History -Count 999))<br />
      {<br />
      Add-Content $ScriptFile $i.CommandLine<br />
      }<br />
   Invoke-Item $ScriptFile<br />
   }</p></blockquote>
<p>The function re-uses the same file each time, asking for confirmation to overwrite it. Don&#8217;t forget to use Save As&#8230; to store your finished work.</p>
<p>I can&#8217;t wait to see the masterpieces you will create. Don&#8217;t forget to share them!<br />
Hugo</p>
<p>PS: You might want to consider to increase the amount of commands kept in your history. Just set the $MaximumHistoryCount variable to the desired value.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/handy-little-function-create-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Finding and Stopping VI Sessions with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/finding-and-stopping-vi-sessions-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/finding-and-stopping-vi-sessions-with-powershell/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 11:23:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[session]]></category>
		<category><![CDATA[VI Toolkit]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=104</guid>
		<description><![CDATA[If you have been trying out the VMware VI Toolkit for Windows Powershell, you have probably noticed. You have to disconnect (disconnect-viserver) each session you set up to the VI Server (connect-viserver), or it will linger for eternity (or until the next reboot at least). That&#8217;s why I always include a disconnect-viserver command at the <a href='http://www.peetersonline.nl/index.php/vmware/finding-and-stopping-vi-sessions-with-powershell/'>[...]</a>
Related posts:<ol>
<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>
<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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you have been trying out the <a href="http://www.vmware.com/" target='_blank'>VMware</a> <a href="http://www.vmware.com/sdk/vitk_win/index.html" target='_blank'>VI Toolkit</a> for Windows <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a>, you have probably noticed. You have to disconnect (disconnect-viserver) each session you set up to the VI Server (connect-viserver), or it will linger for eternity (or until the next reboot at least). That&#8217;s why I always include a disconnect-viserver command at the end of my <a href="http://www.vmware.com/sdk/vitk_win/index.html" target='_blank'>VI Toolkit</a> scripts. But what happens in real life: when debugging a script, it hardly ever reaches the end of the script. It will stop at an error or be cancelled by me to fix some bug I notice. I regularly check the Sessions tab in my VI Client and terminate all my idle sessions to keep VI clean and fast. So why not automate that too? Here&#8217;s how:</p>
<blockquote><p>function Get-Session<br />
{<br />
	$Global:SI = Get-View ServiceInstance<br />
	$Global:SM = Get-View $SI.Content.SessionManager<br />
	Return $SM.SessionList<br />
}</p>
<p>function Stop-Session<br />
{<br />
	Process<br />
		{<br />
		ForEach ($Session in $_)<br />
			{<br />
			If ($Session.Key -ne $SM.CurrentSession.Key)<br />
				{<br />
					$Key = $session.Key<br />
					$SM.TerminateSession($Key)<br />
					Write-Host &#8220;Session $Key terminated.&#8221;<br />
					$Key = $null<br />
				}<br />
			Else<br />
				{<br />
				Write-Warning &#8220;Cannot terminate current session.&#8221;<br />
				}<br />
			}<br />
		}<br />
}</p>
</blockquote>
<p>The function Get-Session lists the currently active sessions. You can then filter them as you do any collection of objects in <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> and pipe them to Stop-Session to have them terminated. Note that VI Client sessions appear to create two actual sessions and that the API (and therefore my function) will not allow you to terminate the current session.<br />
Example:</p>
<blockquote><p>Get-Session | Where { ((Get-Date) &#8211; $_.LastActiveTime).TotalHours -ge 8 } | Stop-Session</p>
</blockquote>
<p>Enjoy!</p>
<p>Related posts:<ol>
<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>
<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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/finding-and-stopping-vi-sessions-with-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

