<?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>TechProsaic &#187; Scripting</title>
	<atom:link href="http://halr9000.com/article/category/programming/scripting/feed" rel="self" type="application/rss+xml" />
	<link>http://halr9000.com</link>
	<description>(powershell &#38; other stuff)</description>
	<lastBuildDate>Mon, 06 Sep 2010 20:08:50 +0000</lastBuildDate>
	<language>en-us</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Paper.Li, a Neat Way to Read Twitter</title>
		<link>http://halr9000.com/article/910</link>
		<comments>http://halr9000.com/article/910#comments</comments>
		<pubDate>Mon, 06 Sep 2010 20:08:50 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[doctordns]]></category>
		<category><![CDATA[newspaper]]></category>
		<category><![CDATA[paper.li]]></category>
		<category><![CDATA[powerscripting]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/910</guid>
		<description><![CDATA[I just read a blog post from Thomas Lee that talked about Paper.Li. I really like this site and thought I’d share as well. In particular, there is a feature to browse tweets by hashtag. I can see this as being really useful for me as I prepare the show notes for the PowerScripting Podcast [...]]]></description>
			<content:encoded><![CDATA[<!-- no icon for 'Internet' --><a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p>I just read a <a href="http://tfl09.blogspot.com/2010/09/paperli-organising-twitter-information.html">blog post</a> from <a href="http://twitter.com/doctordns">Thomas Lee</a> that talked about <a href="http://paper.li/">Paper.Li</a>. I really like this site and thought I’d share as well. In particular, there is a feature to browse tweets by hashtag. I can see this as being really useful for me as I prepare the show notes for the <a href="http://powerscripting.net">PowerScripting Podcast</a> (the #<a href="http://paper.li/tag/PowerShell">powershell tag</a>, of course). Here’s a screenshot:</p>
<p><a href="http://paper.li/tag/PowerShell"><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://halr9000.com/wp-content/uploads/2010/09/image.png" width="679" height="558" /></a></p>
<p>Go check out paper.li!</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/910/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick PowerCLI Tip: Determine vNetwork Teaming Uplinks for Distributed Virtual Switch PortGroups</title>
		<link>http://halr9000.com/article/903</link>
		<comments>http://halr9000.com/article/903#comments</comments>
		<pubDate>Sat, 17 Jul 2010 19:01:25 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[portgroup]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/903</guid>
		<description><![CDATA[Need to determine what the uplink policy is for your DVSwitches? Here is a quick PowerCLI snippet to do that. I’d go into more detail but I don’t have time this moment. Consider this longer than a tweet, but shorter than my normal blog post. Here is the corresponding screen in the vSphere Client (pardon [...]]]></description>
			<content:encoded><![CDATA[<!-- no icon for 'PowerCLI' --><a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'VMware' --><p>Need to determine what the uplink policy is for your DVSwitches? Here is a quick <a href="http://vmware.com/go/powercli">PowerCLI</a> snippet to do that. I’d go into more detail but I don’t have time this moment. Consider this longer than a tweet, but shorter than my normal blog post. <img style="border-bottom-style: none; border-right-style: none; border-top-style: none; border-left-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://halr9000.com/wp-content/uploads/2010/07/wlEmoticonsmile.png" /></p>
<p>Here is the corresponding screen in the vSphere Client (pardon the font issues, I’m running blind-person-size-font) with the relevant portion highlighted:</p>
<p><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" class="wlDisabledImage" title="vSphere client screenshot" border="0" alt="vSphere client screenshot" src="http://halr9000.com/wp-content/uploads/2010/07/image.png" width="753" height="469" /></p>
<p>And the code:</p>
<pre><span style="color: #0000ff">PS</span><span style="color: #000000">&gt;</span><span style="color: #000000"> </span><span style="color: #800080">$pgName</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800000">'</span><span style="color: #800000">Name of your DV port group</span><span style="color: #800000">'</span><span style="color: #000000">
</span><span style="color: #0000ff">PS</span><span style="color: #000000">&gt;</span><span style="color: #000000"> </span><span style="color: #800080">$pg</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #5f9ea0">Get-View</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-ViewType</span><span style="color: #000000"> </span><span style="color: #0000ff">DistributedVirtualPortgroup</span><span style="color: #000000"> </span><span style="color: #5f9ea0">-Filter</span><span style="color: #000000"> </span><span style="color: #000000">@</span><span style="color: #000000">{ </span><span style="color: #0000ff">Name</span><span style="color: #000000"> </span><span style="color: #ff0000">=</span><span style="color: #000000"> </span><span style="color: #800080">$pgName</span><span style="color: #000000"> }
</span><span style="color: #0000ff">PS</span><span style="color: #000000">&gt;</span><span style="color: #000000"> </span><span style="color: #800080">$pg</span><span style="color: #000000">.</span><span style="color: #8b4513">Config</span><span style="color: #000000">.</span><span style="color: #8b4513">DefaultPortConfig</span><span style="color: #000000">.</span><span style="color: #8b4513">UplinkTeamingPolicy</span><span style="color: #000000">.</span><span style="color: #8b4513">UplinkPortOrder</span><span style="color: #000000">

</span><span style="color: #0000ff">ActiveUplinkPort</span><span style="color: #000000">  </span><span style="color: #000000">:</span><span style="color: #000000"> {</span><span style="color: #0000ff">dvUplink1</span><span style="color: #000000">,</span><span style="color: #000000"> </span><span style="color: #0000ff">dvUplink2</span><span style="color: #000000">}
</span><span style="color: #0000ff">StandbyUplinkPort</span><span style="color: #000000"> </span><span style="color: #000000">:</span><span style="color: #000000">
</span><span style="color: #0000ff">Inherited</span><span style="color: #000000">         </span><span style="color: #000000">:</span><span style="color: #000000"> </span><span style="color: #0000ff">True</span><span style="color: #000000">
</span><span style="color: #0000ff">DynamicType</span><span style="color: #000000">       </span><span style="color: #000000">:</span><span style="color: #000000">
</span><span style="color: #0000ff">DynamicProperty</span><span style="color: #000000">   </span><span style="color: #000000">:</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/903/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Book News</title>
		<link>http://halr9000.com/article/896</link>
		<comments>http://halr9000.com/article/896#comments</comments>
		<pubDate>Thu, 24 Jun 2010 15:13:04 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Book]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/896</guid>
		<description><![CDATA[There have been many book releases in the months since PowerShell V2 has been released, and there are several still in the works. It’s also neat to see all of the localized book projects—that really shows how important PowerShell is the entire world over. Here is a list of the books that I’ve heard about [...]]]></description>
			<content:encoded><![CDATA[<!-- no icon for 'Book' --><a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p>There have been many book releases in the months since PowerShell V2 has been released, and there are several still in the works. It’s also neat to see all of the localized book projects—that really shows how important PowerShell is the entire world over. Here is a list of the books that I’ve heard about lately, in alpha order by title:</p>
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="110">
<p align="center"><strong>Author</strong></p>
</td>
<td width="322">
<p align="center"><strong>Title</strong></p>
</td>
<td width="79">
<p align="center"><strong>Language</strong></p>
</td>
<td width="116">
<p align="center"><strong>Publisher</strong></p>
</td>
<td width="66">
<p align="center"><strong>Release</strong></p>
</td>
</tr>
<tr>
<td width="110">Ragnar Harper</td>
<td><a href="http://www.idgbooks.no/product_info.php?products_id=3815&amp;osCsid=649cb610ecfce511b1cc5623094c4b9b">Kom igang med Powershell 2.0</a></td>
<td>Norwegian</td>
<td width="116">IDG</td>
<td>&#160;</td>
</tr>
<tr>
<td width="110">Jeff Hicks</td>
<td width="322"><a href="http://www.sapienpress.com/">Managing Active Directory with Windows PowerShell: TFM 2nd edition</a></td>
<td>English</td>
<td width="116">&#160;</td>
<td width="66">&#160;</td>
</tr>
<tr>
<td>Soós Tibor</td>
<td><a href="http://www.iqjb.hu/UserFiles/book/Microsoft%20Powershell%202.0_v2.docx_HTML/Microsoft%20Powershell%202.0_v2.docx.htm">PowerShell 2.0 Theory and Practice (free ebook)</a></td>
<td>Hungarian</td>
<td width="116">Microsoft Magyarország</td>
<td>2010</td>
</tr>
<tr>
<td width="110">Don Jones, Jeff Hicks</td>
<td width="322"><a href="http://www.sapienpress.com/PowerShell3.asp">PowerShell 2.0: TFM</a></td>
<td>English</td>
<td width="116">SAPIEN Press</td>
<td width="66">Jan-10 </td>
</tr>
<tr>
<td width="110">Bruce Payette</td>
<td width="322"><a href="http://www.manning.com/payette2/">PowerShell in Action v2</a></td>
<td>English</td>
<td width="116">Manning</td>
<td width="66">Aug 2010 (est.)</td>
</tr>
<tr>
<td width="110">Richard Siddaway</td>
<td width="322"><a href="http://www.manning.com/siddaway/">PowerShell in Practice</a></td>
<td>English</td>
<td width="116">Manning</td>
<td width="66">Jun-10</td>
</tr>
<tr>
<td width="110">Tobias Weltner</td>
<td width="322"><a href="http://www.microsoft-press.de/product.asp?cnt=product&amp;id=ms-5669&amp;lng=0&amp;titel=Scripting">Scripting mit Windows PowerShell 2.0 &#8211; Schritt für Schritt</a></td>
<td>German</td>
<td width="116">MS Press Germany</td>
<td width="66">Jun-10</td>
</tr>
<tr>
<td width="110">Max Trinidad</td>
<td width="322">Teach Yourself PowerShell 2.0 in 24 Hours</td>
<td>English</td>
<td width="116">Sams</td>
<td width="66">2011</td>
</tr>
<tr>
<td width="110">Al Renouf, Luc Dekens</td>
<td width="322"><a href="http://www.virtu-al.net/2010/05/04/were-writing-a-book/">VMware vSphere PowerCLI Reference: Automating vSphere Administration</a></td>
<td>English</td>
<td width="116">Sybex</td>
<td width="66">1Q-2011</td>
</tr>
<tr>
<td width="110">Arnaud Petitjean &amp; Robin Lemesle</td>
<td width="322"><a href="http://www.editions-eni.fr/Livres/Windows-PowerShell-versions-1-et-2-Guide-de-reference-pour-l-administration-systeme/">Windows PowerShell (versions 1 et 2): guide référence pour l&#8217;administration système</a></td>
<td>French</td>
<td width="116">Editions ENI</td>
<td width="66">&#160;</td>
</tr>
<tr>
<td width="110">Steve Sequis</td>
<td width="322"><a href="http://www.dummies.com/store/product/Windows-PowerShell-2-For-Dummies.productCd-0470371986.html">Windows PowerShell 2 For Dummies</a> (note: released before PS v2 was complete)</td>
<td>English</td>
<td width="116">For Dummies</td>
<td width="66">Aug-2009</td>
</tr>
<tr>
<td width="110"><a name="RANGE!A12">Lee Holmes</a></td>
<td width="322"><a href="http://oreilly.com/catalog/9780596801519/">Windows PowerShell Cookbook, 2nd Ed.</a></td>
<td>English</td>
<td width="116">O&#8217;Reilly</td>
<td width="66">Aug-10</td>
</tr>
</tbody>
</table>
<p>If you know of any that I have missed, please let me know in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/896/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Security Authorization in vSphere</title>
		<link>http://halr9000.com/article/894</link>
		<comments>http://halr9000.com/article/894#comments</comments>
		<pubDate>Thu, 24 Jun 2010 02:14:18 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Screencast]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[train signal]]></category>
		<category><![CDATA[vsphere]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/894</guid>
		<description><![CDATA[I thought I’d share another slide with you tonight. This is also from my upcoming Train Signal vSphere Pro video. Before tackling a set of PowerCLI cmdlets, I like to give you a good base understanding of the concepts.]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'Screencast' --><!-- no icon for 'VMware' --><p>I thought I’d share another slide with you tonight. This is also from my upcoming <a href="http://trainsignal.com">Train Signal</a> vSphere Pro video. Before tackling a set of <a href="http://vmware.com/go/powercli">PowerCLI</a> cmdlets, I like to give you a good base understanding of the concepts.</p>
<p><a href="http://halr9000.com/wp-content/uploads/2010/06/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://halr9000.com/wp-content/uploads/2010/06/image_thumb1.png" width="644" height="484" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/894/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Get-Stat cmdlet is a bit hard to work with</title>
		<link>http://halr9000.com/article/890</link>
		<comments>http://halr9000.com/article/890#comments</comments>
		<pubDate>Sat, 19 Jun 2010 19:32:53 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Screencast]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/890</guid>
		<description><![CDATA[As evidenced by the slide I’m working on at the moment for the upcoming TrainSignal vSphere Pro Series lesson titled “Performance with PowerCLI”. I really wanted to use stars for the difficulty level and make them vibrate like they do in the game, but I was spending too much time on this slide as it [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'Screencast' --><!-- no icon for 'VMware' --><p>As evidenced by the slide I’m working on at the moment for the upcoming <a href="http://www.trainsignal.com/VMware-vSphere-Pro-Series-Training-Vol-1-P91.aspx">TrainSignal vSphere Pro Series</a> lesson titled “Performance with PowerCLI”.</p>
<p>I really wanted to use stars for the difficulty level and make them vibrate like they do in the game, but I was spending too much time on this slide as it was. <img src='http://halr9000.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://halr9000.com/wp-content/uploads/2010/06/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://halr9000.com/wp-content/uploads/2010/06/image_thumb.png" width="644" height="484" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/890/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Range of Letters, an Alternate Method</title>
		<link>http://halr9000.com/article/877</link>
		<comments>http://halr9000.com/article/877#comments</comments>
		<pubDate>Tue, 11 May 2010 01:26:16 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/877</guid>
		<description><![CDATA[PowerShell.com just posted a tip today on how to create a range of letters. The tip looks like this: 65..90 &#124; Foreach-Object { &#34;$([char]$_):&#34; } That works fine, but I have another way to share with you in case you don’t want to look up the ASCII values every time. This is very similar to [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p>PowerShell.com just posted <a href="http://powershell.com/cs/blogs/tips/archive/2010/05/10/creating-range-of-letters.aspx">a tip today</a> on how to create a range of letters. The tip looks like this:</p>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">65..90 | Foreach-Object { <span style="color: #006080">&quot;$([char]$_):&quot;</span> }</pre>
<p></div>
</p>
<p>That works fine, but I have another way to share with you in case you don’t want to look up the ASCII values every time. This is very similar to a technique used in my <a href="http://halr9000.com/article/859">Random Letters</a> post of not too long ago:</p>
<div>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[char[]]([char]<span style="color: #006080">'a'</span>..[char]<span style="color: #006080">'z'</span>)</pre>
</div>
<div>&#160;</div>
<div>That prints each letter on a line. If you’d like them in a row, cast the whole thing to a string:</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">[string]( [char[]]([char]<span style="color: #006080">'a'</span>..[char]<span style="color: #006080">'z'</span>) )</pre>
</div>
<div>&#160;</div>
<div>Or, you can place it within a sub-expression, and quotes:</div>
<div>&#160;</div>
<div id="codeSnippetWrapper">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet"><span style="color: #006080">&quot;$([char[]]([char]'a'..[char]'z'))&quot;</span></pre>
</div>
<div>&#160;</div>
<div>Read my original post for an explanation of how this method works. PowerShell is a very flexible language, and as they say, there’s more than one way to skin a cat!</div>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/877/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>IPconfig in PowerShell</title>
		<link>http://halr9000.com/article/872</link>
		<comments>http://halr9000.com/article/872#comments</comments>
		<pubDate>Wed, 21 Apr 2010 13:17:06 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Powershell Ideas]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/872</guid>
		<description><![CDATA[First, let me give credit up front that this tip was inspired by one or two recent Power Tips from PowerShell.com. With that out of the way, I wanted to show you real quick that if you want the sort of information that you get from ipconfig.exe, then the command is even simpler: PS &#62; [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'Powershell Ideas' --><p>First, let me give credit up front that this tip was inspired by <a href="http://powershell.com/cs/blogs/tips/archive/2010/04/20/getting-assigned-ip-addresses.aspx">one</a> or <a href="http://powershell.com/cs/blogs/tips/archive/2010/04/21/ipv4-address-lists.aspx">two</a> recent Power Tips from PowerShell.com.</p>
<p>With that out of the way, I wanted to show you real quick that if you want the sort of information that you get from ipconfig.exe, then the command is even simpler:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; gwmi win32_networkadapterconfiguration | ? { $_.IPAddress }

DHCPEnabled      : True</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">IPAddress        : {151.140.143.41}</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">DefaultIPGateway : {151.140.142.1}</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">DNSDomain        : halr9000.com</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">ServiceName      : b57w2k</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Description      : Broadcom NetXtreme Gigabit Ethernet - Packet Scheduler Miniport</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Index            : 8

DHCPEnabled      : True</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">IPAddress        : {151.140.143.41}</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">DefaultIPGateway : {151.140.142.1}</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">DNSDomain        : whatever.<span style="color: #0000ff;">local</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;"> </span>ServiceName      : AR5416</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Description      : Broadcom NetXtreme Gigabit Ethernet - Packet Scheduler Miniport</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Index            : 10</pre>
</div>
<p>You can rely on the default output of the Win32_NetworkAdapterConfiguration WMI class to display some of the more important bits here—just like ipconfig. But what if you want more—in other words, “ipconfig /all”? That data is already in there, but it’s not displayed to the screen by default. To get at it, you can pipe to Format-List and stick an asterisk at the end to tell it to display everything, like so:</p>
<div id="codeSnippetWrapper" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; width: 97.5%; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; cursor: text; border: silver 1px solid; padding: 4px;">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; gwmi win32_networkadapterconfiguration | ? { $_.IPAddress } | fl *

DHCPLeaseExpires             : 20100427081921.000000-240</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Index                        : 8</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">Description                  : Broadcom NetXtreme Gigabit Ethernet - Packet Scheduler Miniport</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">DHCPEnabled                  : True</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">DHCPLeaseObtained            : 20100421081921.000000-240</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">DHCPServer                   : 165.130.252.36</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">...</pre>
</div>
<p>I used a couple of aliases in the above examples because it saves typing. To be clear for those who don’t know them, here are the definitions:</p>
<p>gwmi = Get-WmiObject</p>
<p>? = Where-Object</p>
<p>fl = Format-List</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/872/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Please vote for my PowerCLI Codestock session!</title>
		<link>http://halr9000.com/article/870</link>
		<comments>http://halr9000.com/article/870#comments</comments>
		<pubDate>Sat, 13 Mar 2010 18:43:53 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/870</guid>
		<description><![CDATA[If you are in the Southeast US, you may be interested in the upcoming Codestock event coming up in June in Knoxville, TN. It seems to be heavily slanted towards developers, but they are doing IT Pro and Entrepeneur tracks this year as well. I have submitted one session for my Managing VMware with PowerShell [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'VMware' --><p>If you are in the Southeast US, you may be interested in the upcoming <a href="http://codestock.org">Codestock</a> event coming up in June in Knoxville, TN. It seems to be heavily slanted towards developers, but they are doing IT Pro and Entrepeneur tracks this year as well. I have submitted one session for my <a href="http://codestock.org/sessions/managing-vmware-with-windows-powershell-and-powercli.aspx">Managing VMware with PowerShell thing</a>. If you have a minute, please go over to the site to register and vote my session up. </p>
<p>I’ve never been to Codestock before, but it looks like fun. In fact, it looks like a lot more fun than your typical canned vendor convention. I don’t plan on doing many speaker engagements this year aside from the occasional <a href="http://atlsmug.org">SMUG</a> or <a href="http://powershellgroup.org/atlanta.ga">APUG</a> meeting here in Atlanta, but I thought going to Knoxville might be a neat excuse to get out an d see a new city. The drive to Knoxville from Atlanta is pretty nice if you go through Chattahoochee and Nantahala national forests, so we are looking forward to that.</p>
<p><img src="http://l.yimg.com/g/images/spaceball.gif" /><img src="http://l.yimg.com/g/images/spaceball.gif" /></p>
</p>
<p><img src="http://l.yimg.com/g/images/spaceball.gif" /><img src="http://l.yimg.com/g/images/spaceball.gif" /></p>
</p>
<p><img alt="Brasstown Bald Road by tfdavis." src="http://farm4.static.flickr.com/3115/3159556923_248f4a319f.jpg" /></p>
<p>(credit <a href="http://www.flickr.com/photos/tfdavis/3159556923/">tfdavis on flickr</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/870/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerCLI Tip: Speed up your login</title>
		<link>http://halr9000.com/article/867</link>
		<comments>http://halr9000.com/article/867#comments</comments>
		<pubDate>Sun, 24 Jan 2010 21:32:57 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/867</guid>
		<description><![CDATA[When using PowerCLI, the first thing you have to do is to create a connection and authenticate yourself to your vSphere and/or vCenter servers. This is done with the Connect-VIServer cmdlet. Sometimes, this connection can be slow, taking ten or more seconds just to display a password prompt! That gets old pretty quickly. There is [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'VMware' --><p><a href="http://halr9000.com/wp-content/uploads/2010/01/image.png"><img style="border-bottom: 0px; border-left: 0px; margin: 0px 0px 0px 5px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" align="right" src="http://halr9000.com/wp-content/uploads/2010/01/image_thumb.png" width="244" height="187" /></a> When using <a href="http://vmware.com/go/powercli">PowerCLI</a>, the first thing you have to do is to create a connection and authenticate yourself to your vSphere and/or vCenter servers. This is done with the <a href="http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Connect-VIServer.html">Connect-VIServer</a> cmdlet. Sometimes, this connection can be slow, taking ten or more seconds just to display a password prompt! That gets old pretty quickly.</p>
<p>There is a good reason for the slowness before you are prompted for credentials, and turns out, it’s a feature, not a bug. PowerCLI supports a single-sign-on (SSO) authentication when you attempt a connection to a vCenter server. What happens in the background is that your current Windows credentials are being passed on to the server and that is tried first, before even prompting you for credentials. This is great if you are sitting at the office and have a fast link to the vCenter server, and you happen to be logging into your workstation with a domain accont, and that domain account has vCenter rights. This transparent passing of credentials is definitely a timesaver under those circumstances.</p>
<p>But on the other hand, what if you are connecting from home over a slow link? What if you are on your home PC or a local account? What if, due to security policies at your company, your normal user account doesn’t even HAVE admin privileges? Yup, the authentication attempt fails (or simply takes a while), and you are left twiddling your thumbs, waiting for the “real” login prompt to appear.</p>
<h3>Resolution</h3>
<p>The fix is an easy one. Instead of typing this to connect:</p>
<pre class="csharpcode">Connect-VIServer vcenter.domain.com
<style type="text/css">.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
</style>
</pre>
<p>…type something like this:</p>
<pre class="csharpcode">Connect-VIServer vcenter.domain.com -Credential (Get-Credential)</pre>
<p>or the less-recommended, yet still quite functional:</p>
<pre class="csharpcode">Connect-VIServer vcenter.domain.com -user myuser -password mypass</pre>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>By using one of these methods, you are instructing Connect-VIServer to explicitly use a set of credentials which you specify. This way, it won’t bother attempting to pass along your current credentials, thus saving you a few seconds and perhaps a gray hair or two.</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/867/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Random Letters</title>
		<link>http://halr9000.com/article/859</link>
		<comments>http://halr9000.com/article/859#comments</comments>
		<pubDate>Sun, 24 Jan 2010 05:47:42 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Basics]]></category>
		<category><![CDATA[Get-Random]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/859</guid>
		<description><![CDATA[I needed some source text to test a regular expression pattern, so my goal tonight was to generate some. The regex pattern in question finds email addresses, so I needed to be sure to embed real-looking email addresses inside of gibberish. Step number one: I need some random letters. PowerShell v2’s Get-Random cmdlet comes to [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'Tutorials' --><p>I needed some source text to test a regular expression pattern, so my goal tonight was to generate some. The regex pattern in question finds email addresses, so I needed to be sure to embed real-looking email addresses inside of gibberish. Step number one: I need some random letters. PowerShell v2’s Get-Random cmdlet comes to the rescue!</p>
<p>Get-Random has two modes. The first mode allows you to return random numbers, and you can specify a min and max range. The second mode will return random items from a list, and as an added bonus, you can specify the number of items to return. I plan on using both modes in this exercise.</p>
<p>In order to build gibberish words or email addresses, I need to start with a list of allowable characters. Let’s keep it simple and restrict things to lowercase letters, although adding in numbers would be simple.</p>
<p>You all remember ASCII, right? This is a conversion table that has been used to represent numeric values for letters (and every other character on you keyboard, plus others) for a long, LONG time. You are slowly seeing ASCII encoding supplanted by Unicode as that table has a much larger address space and can handle non-Latin alphabets, but ASCII suits me just fine. We are going to use ASCII values and PowerShell’s range operator (..) to generate the list of allowable characters.</p>
<p>If you have worked with Vbscript, then you might know how to to ASCII conversions with the Chr() function. You give that function a number, and it spits out the ASCII value. The reverse is done with the Asc() function. In PowerShell, it’s not done the same way at all, so just forget that. Instead, what we are going to do is to convert back and forth between a “char” (character) .NET type. Chars are really sort of an in-between data type. They look like strings (i.e., it’s a letter), but they are very easily converted into integers.</p>
<p>So let’s take that knowledge and combine it with a technique called “casting”. To cast in PowerShell means to state that you want a particular value to be a certain data type. For example, if I have a number, and I want to make sure it is treated like a string in my script, I can cast it as a string like so:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">[string]12</pre>
</div>
<p>If you pipe that to Get-Member, you’ll see that the result is a string object, with all of the properties and methods which that type has, as opposed to the much more basic [int] type.</p>
<p>Moving on, let’s take the letter “a”, and the letter “z”, and turn it into a range containing all of the letters in between. PowerShell’s range operator can be used here, but it only works with integers. I could ask a search engine for an ASCII chart to get the numbers I need, but there’s no need, I’ll just convert from the letters directly.</p>
<p>Here’s how to convert a single letter into its ASCII number representation:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [int][char]<span style="color: #006080">'a'</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">97</pre>
</div>
<p>What I am doing here is casting twice. Anything surrounded by single or double quotes is a string. I can convert any single letter (or symbol, or whatever) to a char data type by casting it as you can see. Then I take that char and cast it immediately to an integer, and as I said before, that’s an easy conversion for PowerShell to do because that’s the way chars types are wired.</p>
<p>Now we have our first integer. Just replace the ‘a’ with a ‘z’ and we have the second.</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [int][char]<span style="color: #006080">'z'</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">122</pre>
</div>
<p>These integers are going to be perfect as input to the Get-Random cmdlet. Here’s how to return random letters using Get-Random’s first mode:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; $min = [int][char]<span style="color: #006080">'a'</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; $max = [int][char]<span style="color: #006080">'z'</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; Get-Random -Minimum $min -Maximum $max</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">104</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [char](Get-Random -Minimum $min -Maximum $max)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">l</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [char](Get-Random -Minimum $min -Maximum $max)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">q</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [char](Get-Random -Minimum $min -Maximum $max)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">r</pre>
</div>
<p>As you can see, turning an integer back into a letter is pretty simple, you just cast it to a [char]. (The parentheses are necessary.) And you can also see a new random letter popping up at each execution of Get-Random. Great! So how do we make random words? Well, in the context of this blog post, a word consists of an array of characters. That makes sense, right? There are a few ways to go from here to create the requisite [char] array. I could create a for loop, and run the above command inside the loop.</p>
<p>However, there is an easier way. Let’s go back a step and have a look at Get-Random’s second mode. Here is a table showing the two parameter sets (output created with <a href="http://halr9000.com/article/507">my Get-Parameter script</a>):</p>
<pre class="csharpcode">   ParameterSet: RandomNumberParameterSet

Name    Type       IsMandatory Pipeline
----    ----       ----------- --------
SetSeed Nullable`1       False    False
Maximum Object           False    False
Minimum Object           False    False

   ParameterSet: RandomListItemParameterSet

Name        Type       IsMandatory Pipeline
----        ----       ----------- --------
SetSeed     Nullable`1       False    False
InputObject Object[]          True     True
Count       Int32            False    False</pre>
<p><!--.csharpcode, .csharpcode pre { 	font-size: small; 	color: black; 	font-family: consolas, "Courier New", courier, monospace; 	background-color: #ffffff; 	/*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt  { 	background-color: #f4f4f4; 	width: 100%; 	margin: 0em; } .csharpcode .lnum { color: #606060; } --></p>
<p>We used Minimum and Maximum in the first mode. Now we are going to use InputObject and Count. This mode is really handy because you can supply an array of items (letters in this case) as input, and tell it how many random items to return as output! That means no loop, so the code is going to be much simpler.</p>
<p>First, let’s build an array of all lowercase letters. We already know the numeric values to use in the range, so let’s use those. I’m going to use a little trick to take the integer range and cast it in one step to an array of characters, which is exactly what we want:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; $alpha = [char[]]($min..$max)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; $alpha | Select-Object -First 3</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">a</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">b</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">c</pre>
</div>
<p>We build the range with “$min..$max” and put that in parentheses. Then we cast it, but not as a single [char], but as an array of [char]’s by adding an empty set of brackets []. Now, the variable $alpha contains our input to Get-Random. The next step is easy, just pass this variable to the cmdlet and give it a count:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; $alpha | Get-Random -Count 5</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">t</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">f</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">a</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">b</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">c</pre>
</div>
<p>Presto! A five-letter word! Well…sorta. What we have is a series of characters, one per line. To turn this into adjacent characters we can cast the whole thing as a string.</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [string]( $alpha | Get-Random -Count 5 )</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">i h s p z</pre>
</div>
<p>Almost there, we just have to get rid of those extra spaces. The spaces are generated because of something called the “output format separator”, otherwise known as $OFS. This is a variable predefined by PowerShell to be a single space, but you can change it to whatever you want. Here’s that final step:</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; $ofs = <span style="color: #006080">''</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [string]( $alpha | Get-Random -Count 5 )</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">qfzwg</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">PS &gt; [string]( $alpha | Get-Random -Count 5 )</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">dnhbq</pre>
</div>
<p>Now I am just a hop, skip, and a jump from generating random email addresses, but that’s enough for tonight.</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/859/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Which PowerShell Community (aka PoshComm) logo wins? [PIC]</title>
		<link>http://halr9000.com/article/850</link>
		<comments>http://halr9000.com/article/850#comments</comments>
		<pubDate>Sat, 26 Dec 2009 04:01:40 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[poshcomm;logo]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/850</guid>
		<description><![CDATA[Please comment… Logo1: Logo 2:]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p>Please comment…</p>
<p>Logo1:<br />
<img class="alignnone size-full wp-image-851" title="logo1" src="http://halr9000.com/wp-content/uploads/2009/12/logo11.png" alt="logo1" width="500" height="243" /></p>
<p>Logo 2:<br />
<img class="alignnone size-full wp-image-852" title="logo3" src="http://halr9000.com/wp-content/uploads/2009/12/logo31.png" alt="logo3" width="412" height="130" /></p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/850/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>PowerCLI Script: New-Farm</title>
		<link>http://halr9000.com/article/845</link>
		<comments>http://halr9000.com/article/845#comments</comments>
		<pubDate>Sat, 19 Dec 2009 18:34:47 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/845</guid>
		<description><![CDATA[This is a sample script that I created to show how you might create a relatively complex virtual farm environment. The hypothetical requirements for this farm are: Add 10 ESX servers to a vCenter, one for each customer Create a resource pool for each customer Inside each of these, create a resource pool for each [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'VMware' --><p>This is a sample script that I created to show how you might create a relatively complex virtual farm environment. The hypothetical requirements for this farm are:</p>
<ol>
<li>Add 10 ESX servers to a vCenter, one for each customer</li>
<li>Create a resource pool for each customer</li>
<li>Inside each of these, create a resource pool for each server role, and a specified number of virtual machines, based on previously-created VM templates
<ol>
<li>2 x proxy server</li>
<li>4 x web server</li>
<li>2 x app server</li>
<li>2 x database server</li>
</ol>
</li>
</ol>
<p>I hope you find the script useful!</p>
<p><script type="text/javascript" src="http://PoshCode.org/embed/1547"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/845/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Big Thoughts Need Planning</title>
		<link>http://halr9000.com/article/844</link>
		<comments>http://halr9000.com/article/844#comments</comments>
		<pubDate>Wed, 16 Dec 2009 04:21:33 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/844</guid>
		<description><![CDATA[Just a quick post to get your comments. What do you think about this slide? Am I missing anything that needs mentioning here? &#160; P.S. Office “Smart Art” FTW]]></description>
			<content:encoded><![CDATA[<!-- no icon for 'Scripting' --><p>Just a quick post to get your comments. What do you think about this slide? Am I missing anything that needs mentioning here?</p>
<p><a href="http://halr9000.com/wp-content/uploads/2009/12/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://halr9000.com/wp-content/uploads/2009/12/image_thumb.png" width="486" height="214" /></a>&#160;</p>
<p>P.S. Office “Smart Art” FTW</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/844/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with STDERR in PowerShell</title>
		<link>http://halr9000.com/article/837</link>
		<comments>http://halr9000.com/article/837#comments</comments>
		<pubDate>Tue, 01 Dec 2009 20:38:58 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/837</guid>
		<description><![CDATA[A co-worker today asked me how he could redirect output from an external executable into a variable. Seemed easy enough, you just do this: $var = mycmd.exe He tried it and got back a $null for his trouble. Turned out, the executable was writing to the error stream (STDERR) instead of STDOUT. Now, the question [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p>A co-worker today asked me how he could redirect output from an external executable into a variable. Seemed easy enough, you just do this:</p>
<p>$var = mycmd.exe</p>
<p>He tried it and got back a $null for his trouble. Turned out, the executable was writing to the error stream (STDERR) instead of STDOUT. Now, the question came up of how to capture that information.</p>
<p>We had to get a little old school because this is a DOS convention (well, much older than that but anyway) and has nothing to do with PowerShell. The answer wasn’t hard, but the response wasn’t what we expected. Observe:</p>
<div class="wlWriterEditableSmartContent" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:7ab7858a-1c0e-4e1e-adba-e831507d7191" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="brush: powershell">PS &gt; $a = netstat bob 2&gt;&amp;1 # cause intentional err and redirect
PS &gt; $a.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     Object[]                                 System.Array

PS &gt; $a[0].GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     True     ErrorRecord                              System.Object</pre>
</div>
<p>I used “2&gt;&amp;1” to redirect the STDERR stream to the STDOUT stream. Worked fine, however when we tried to work with the results we found that it wasn’t a string array. Instead, as you see above, it is an array of ErrorRecord objects! In hindsight, that made sense to me. I mean, what else would you expect in the error stream but errors?</p>
<p>Anyway, long story short, the way to access the text inside of these error objects is by accessing the Exception property. But it was slightly more complex, as what you get is TWO errors. One with the “powershelly” NativeCommandError, and the second with the text that we needed. For example:</p>
<div class="wlWriterEditableSmartContent" id="scid:f32c3428-b7e9-4f15-a8ea-c502c7ff2e88:2a4e4f5a-62e3-4460-9909-b4ff59af606a" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">
<pre class="brush: powershell">PS &gt; $a[0]
netstat.exe :
At line:1 char:13
+ $a = netstat &lt;&lt;&lt;&lt;  bob 2&gt;&amp;1 # cause intentional err and redirect
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

PS &gt; $a[1].Exception
Displays protocol statistics and current TCP/IP network connections.

NETSTAT [-a] [-b] [-e] [-n] [-o] [-p proto] [-r] [-s] [-v] [interval]</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/837/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Quick Outlook Automation Examples</title>
		<link>http://halr9000.com/article/836</link>
		<comments>http://halr9000.com/article/836#comments</comments>
		<pubDate>Fri, 20 Nov 2009 14:15:29 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[outlook]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/836</guid>
		<description><![CDATA[PowerShell is so cool… I had no idea how to automate Outlook with COM before today. Took me about 5 minutes to learn how with PowerShell. I knew it could be done with VBS, right? That’s how viruses are made. This won’t be a long blog unfortunately, but wanted to paste real quick a series [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<a href="http://halr9000.com/article/category/software/windows" title="Windows"><img src="/wp-content/icons/topic_windows.gif" align="right" width="54" height="46" alt="Windows" /></a>
<p>PowerShell is so cool…</p>
<p>I had no idea how to automate Outlook with COM before today. Took me about 5 minutes to learn how with PowerShell. I knew it could be done with VBS, right? That’s how viruses are made. <img src='http://halr9000.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>This won’t be a long blog unfortunately, but wanted to paste real quick a series of commands which I basically figured out in a shell interactively. I didn’t have to read any docs, Get-Member told me all I needed to know.</p>
<p>I did go back and add some comments. I hope you find it useful.</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left; max-height: 200px">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$ol = New-Object -com Outlook.Application <span style="color: #008000"># starts outlook</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$ol.Reminders | select caption, nextreminderdate <span style="color: #008000"># show reminders</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$ol | gm -mem method <span style="color: #008000"># show all methods (actions) on the com object</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$n = $ol.CreateItem(<span style="color: #006080">'olNoteItem'</span>) <span style="color: #008000"># creates a note</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$n <span style="color: #008000"># display note object</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$n.Body = <span style="color: #006080">'test'</span> <span style="color: #008000"># set body of note</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$n | gm <span style="color: #008000"># display object members (methods &amp; properties) of note</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$n.Display() <span style="color: #008000"># show note</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$n.Color <span style="color: #008000"># display color value</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$n.Color = 4 <span style="color: #008000"># set color</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">1..5 | ForEach-Object { $n.Color = $_; sleep 1 } <span style="color: #008000"># change color of note 5 times</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$m = $ol.CreateItem(<span style="color: #006080">'olMailItem'</span>) <span style="color: #008000"># create mail object</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$m <span style="color: #008000"># display mail object</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$m | gm -mem property <span style="color: #008000"># show mail properties</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$m.Subject = <span style="color: #006080">'test'</span> <span style="color: #008000"># set subject</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$m.Body = <span style="color: #006080">'test'</span> <span style="color: #008000"># set body</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$m.To = <span style="color: #006080">'email@domain.com'</span> <span style="color: #008000"># set to address</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$m.Display() <span style="color: #008000"># display mail item on screen </span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$m.Send() <span style="color: #008000"># send mail item</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$ol <span style="color: #008000"># display outlook object</span></pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$ol | gm # display outlook methods</pre>
<p><!--CRLF--></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/836/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Fix for PowerShell v2 on XP related crashes in MSCORSVW.DLL</title>
		<link>http://halr9000.com/article/833</link>
		<comments>http://halr9000.com/article/833#comments</comments>
		<pubDate>Fri, 30 Oct 2009 15:35:19 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/833</guid>
		<description><![CDATA[If you are seeing crashes in MSCORSVW.DLL, try this, it may help (and it won’t hurt): Start-Job { &#160;&#160;&#160; Set-Alias ngen (dir (join-path ${env:\windir} &#34;Microsoft.NET\Framework&#34;) ngen.exe -recurse &#124; &#160;&#160;&#160; sort -descending lastwritetime &#160;&#160;&#160; )[0].fullName &#160;&#160;&#160; ngen executequeueditems } For more details, see this Connect bug: Uninstalling KB968380 RC in XP/Srv2003 causes .NET Runtime Optimization Service [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p>If you are seeing crashes in MSCORSVW.DLL, try this, it may help (and it won’t hurt):</p>
<p>Start-Job {   <br />&#160;&#160;&#160; Set-Alias ngen (dir (join-path ${env:\windir} &quot;Microsoft.NET\Framework&quot;) ngen.exe -recurse |    <br />&#160;&#160;&#160; sort -descending lastwritetime    <br />&#160;&#160;&#160; )[0].fullName    <br />&#160;&#160;&#160; ngen executequeueditems     <br />}</p>
<p>For more details, see this Connect bug:</p>
<ul>
<li><a href="https://connect.microsoft.com/windowsmanagement/feedback/ViewFeedback.aspx?FeedbackID=489576">Uninstalling KB968380 RC in XP/Srv2003 causes .NET Runtime Optimization Service to crash</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/833/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A TON of stuff to check out in the new PowerShell Pack!</title>
		<link>http://halr9000.com/article/832</link>
		<comments>http://halr9000.com/article/832#comments</comments>
		<pubDate>Sun, 18 Oct 2009 17:20:56 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[PowerShell Pack]]></category>
		<category><![CDATA[Resource Kit]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/832</guid>
		<description><![CDATA[If you haven’t already, run, do not walk to the MSDN Code Gallery to grab the PowerShell Pack (a part of the upcoming Windows 7 Resource Kit). As announced on the PowerShell team blog, and discussed at great length on Episode 88 of the PowerScripting Podcast, the PowerShell Pack is a set of ten modules, [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p>If you haven’t already, run, do not walk to the MSDN Code Gallery to grab the <a href="http://code.msdn.microsoft.com/PowerShellPack">PowerShell Pack</a> (a part of the upcoming <a href="http://www.microsoft.com/learning/en/us/Books.aspx?Id=13811&amp;locale=en-us">Windows 7 Resource Kit</a>).</p>
<p><a href="http://blogs.msdn.com/powershell/archive/2009/10/15/introducing-the-windows-7-resource-kit-powershell-pack.aspx">As announced</a> on the PowerShell team blog, and discussed at great length on <a href="http://powerscripting.net">Episode 88 of the PowerScripting Podcast</a>, the PowerShell Pack is a set of ten modules, nested into one for ease of installation. There is a ton of great stuff in here. I wrote up a bit of code to list all of the included functions:</p>
<div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">$m = Get-Module PowerShellPack</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">$n = $m.NestedModules | Where-Object { $_.Name <span style="color: #cc6633">-ne</span> <span style="color: #006080">'WPK'</span> } </pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">foreach</span> ( $module <span style="color: #0000ff">in</span> $n ) {</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    Write-Host -ForegroundColor Green <span style="color: #006080">&quot;Module: $( $module.name )&quot;</span> -NoNewline</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">    $module.ExportedCommands.Values | Sort-Object Name | Format-Wide Name</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">}</pre>
<p><!--CRLF--></div>
</div>
<p>As you see in the Where-Object clause there, I am excluding the WPK module. The reason is simply due to the nature of that module, it has hundreds of functions and is really deserving of its own blog post—or book for that matter.</p>
<p>I’m not going to list the full output because I think that’s just cheesy Google gaming, but I will leave you with a teaser:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">PS &gt; Get-Module powershellpack | select -ExpandProperty NestedModules</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">&#160;</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">ModuleType Name                      ExportedCommands</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">---------- ----                      ----------------</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     IsePack                   {Push-CurrentFileLocation, Select-CurrentTextAsVariable, C...</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     TaskScheduler             {Remove-Task, Get-ScheduledTask, Stop-Task, Add-TaskTrigge...</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     WPK                       {Get-DependencyProperty, New-ModelVisual3D, New-DiscreteVe...</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     FileSystem                {Get-FreeDiskSpace, New-Zip, Resolve-ShortcutFile, Mount-S...</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     DotNet                    {Get-CommandWithParameterType, Get-ProgID, Get-Type}</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     PSImageTools              {Add-CropFilter, Add-RotateFlipFilter, Add-OverlayFilter, ...</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     PSRss                     {Read-Article, New-Feed, Remove-Article, Remove-Feed...}</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     PSCodeGen                 {New-Enum, New-ScriptCmdlet, New-PInvoke}</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     PSUserTools               {Start-ProcessAsAdministrator, Get-CurrentUser, Test-IsAdm...</pre>
<p><!--CRLF--></p>
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: &#39;Courier New&#39;, courier, monospace; direction: ltr; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">Script     PSSystemTools             {Test-32Bit, Get-USB, Get-OSVersion, Get-MultiTouchMaximum...</pre>
<p><!--CRLF--></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/832/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell One-Liner: Get-PrimaryIPAddress</title>
		<link>http://halr9000.com/article/829</link>
		<comments>http://halr9000.com/article/829#comments</comments>
		<pubDate>Fri, 09 Oct 2009 19:13:43 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[ip address]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[one-liner]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/829</guid>
		<description><![CDATA[Update @ 3:58 pm: At risk of losing the one-liner nomenclature at a very worthwhile increase in speed, read below. The One-Liner WMI Version One-liner to retrieve the first IP address of the first adapter which has a default gateway set. This is a very reliable, yet not perfect technique for determining the &#34;right&#34; IP [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<p><strong>Update @ 3:58 pm</strong>: At risk of losing the one-liner nomenclature at a very worthwhile increase in speed, read below.</p>
<h2>The One-Liner WMI Version</h2>
<p>One-liner to retrieve the first IP address of the first adapter which has a default gateway set. This is a very reliable, yet not perfect technique for determining the &quot;right&quot; IP address. It will work well in all but the most complex of network configuration scenarios.</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left; max-height: 200px">
<pre id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">@( Get-WmiObject Win32_NetworkAdapterConfiguration | Where-Object { $_.DefaultIpGateway } )[0].IPAddress[0]</pre>
<p></div>
</p>
<p>Note that I have used the @() array notation around the Get-WmiObject call so that I don’t have to worry about how many network adapters come back. If only one comes back, I have an array with one item. If I didn’t do this, then I would have to do an if statement to check whether it’s an array (meaning that the system has multiple NICs with default gateways—which is super-rare but possible).</p>
<h2>The .NET Class Method</h2>
<p>It’s no longer a single line, but honestly, length is not a measure of quality in scripting. I noticed that the above WMI call was noticeably sluggish. Measurements with <a href="http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/measure-command.mspx">Measure-Command</a> cmdlet showed an average execution time of <strong>455 milliseconds</strong>. Here’s a different way using the <a href="http://msdn.microsoft.com/en-us/library/system.net.networkinformation.networkinterface.getallnetworkinterfaces.aspx">Net.NetworkInformation.NetworkInterface</a> .NET class.</p>
<div id="codeSnippetWrapper" style="border-right: silver 1px solid; padding-right: 4px; border-top: silver 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: silver 1px solid; width: 97.5%; cursor: text; direction: ltr; line-height: 12pt; padding-top: 4px; border-bottom: silver 1px solid; font-family: &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4; text-align: left; max-height: 200px">
<div id="codeSnippet" style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$allNIC = [system.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces()</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; text-align: left; border-bottom-style: none">$PrimaryNIC = $allNIC | Where-Object { $_.GetIPProperties().GatewayAddresses }</pre>
<p><!--CRLF--></p>
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; direction: ltr; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: &#39;Courier New&#39;, courier, monospace; border-right-style: none; border-left-style: none; background-color: white; text-align: left; border-bottom-style: none">$PrimaryNIC.GetIPProperties().UnicastAddresses[0].Address.IPAddressToString</pre>
<p><!--CRLF--></div>
</div>
<p>New time averages <strong>13 milliseconds</strong> on my system. That’s a huge difference which I was not surprised to see based on past experience.</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/829/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Adding Port Groups with PowerCLI</title>
		<link>http://halr9000.com/article/828</link>
		<comments>http://halr9000.com/article/828#comments</comments>
		<pubDate>Fri, 02 Oct 2009 12:22:09 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[portgroup]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[virtual networking]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/828</guid>
		<description><![CDATA[David at the Holy VM! blog just put up an article with a script showing you how to create port groups using PowerCLI. He was kind enough to reference my book as inspiration, so the least I can do in return is link to it. Be sure to follow David’s blog, I see several interesting [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'VMware' --><p>David at the <a href="http://www.holy-vm.com/">Holy VM!</a> blog just put up an article with a script showing you how to <a href="http://www.holy-vm.com/2009/10/01/adding-port-groups-with-powercli/">create port groups using PowerCLI</a>. He was kind enough to reference my book as inspiration, so the least I can do in return is link to it. <img src='http://halr9000.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Be sure to follow David’s blog, I see several interesting posts on there recently about his experiences with vSphere.</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/828/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Demos from VMworld</title>
		<link>http://halr9000.com/article/798</link>
		<comments>http://halr9000.com/article/798#comments</comments>
		<pubDate>Thu, 10 Sep 2009 02:00:56 +0000</pubDate>
		<dc:creator>halr9000</dc:creator>
				<category><![CDATA[Powershell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[demos]]></category>
		<category><![CDATA[powercli]]></category>
		<category><![CDATA[scripts]]></category>
		<category><![CDATA[vmworld]]></category>

		<guid isPermaLink="false">http://halr9000.com/article/798</guid>
		<description><![CDATA[If you were waiting for me to post the demo scripts from TA2650: Taking PowerCLI to the Next Level, then you wait is over! My co-presenter Luc Dekens actually buckled under the pressure and started his own blog.&#160; He’s got four posts on it already, and they are: TA2650 scripts – Part 1 – Profiling [...]]]></description>
			<content:encoded><![CDATA[<a href="http://halr9000.com/article/category/programming/scripting/powershell" title="Powershell"><img src="/wp-content/icons/topic_powershell.png" align="right" width="70" height="53" alt="Powershell" /></a>
<!-- no icon for 'VMware' --><p>If you were waiting for me to post the demo scripts from TA2650: Taking PowerCLI to the Next Level, then you wait is over! My co-presenter <a href="http://lucd.info/">Luc Dekens</a> actually buckled under the pressure and started his own blog.&#160; He’s got four posts on it already, and they are:</p>
<ul>
<li><a href="http://lucd.info/?p=7">TA2650 scripts – Part 1 – Profiling your vSphere environment</a></li>
<li><a href="http://lucd.info/?p=106">TA2650 scripts – Part 2 – Using the profile XML file for SDK programming</a></li>
<li><a href="http://lucd.info/?p=162">TA2650 scripts – Part 3 – Checking cluster node configurations</a></li>
<li><a href="http://lucd.info/?p=182">TA2650 scripts – Part 4 – NIC Teaming – “hidden” failure criteria</a></li>
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://halr9000.com/article/798/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
