<?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>Huddled Masses</title>
	<atom:link href="http://huddledmasses.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Mon, 29 Jun 2009 15:04:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Control your PC with your voice &#8230; and PowerShell</title>
		<link>http://huddledmasses.org/control-your-pc-with-your-voice-and-powershell/</link>
		<comments>http://huddledmasses.org/control-your-pc-with-your-voice-and-powershell/#comments</comments>
		<pubDate>Thu, 25 Jun 2009 06:57:54 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Remote Control]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Speech recognition]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1188</guid>
		<description><![CDATA[	
		Have you ever wanted to be able to ask your computer questions and have it answer you out loud? 
		Have you ever wondered if your computer could be more like the ones running the Star Trek Enterprise, responding to voice queries and commands?
	
	
		Have you played with ZWave or X10 home automation and thought that voice [...]]]></description>
			<content:encoded><![CDATA[	<ul>
		<li>Have you ever wanted to be able to ask your computer questions and have it answer you out loud? </li>
		<li>Have you ever wondered if your computer could be more like the ones running the Star Trek Enterprise, responding to voice queries and commands?</li>
	</ul>
	<ul>
		<li>Have you played with <a href="http://www.z-wave.com/">ZWave</a> or X10 home automation and thought that voice control of your devices would be an obvious next step?</li>
	</ul>

	<p>Well, ok &#8230; I&#8217;m not going to show you how to turn on lights or work with home automation &#8212; but that&#8217;s the main thing that keeps me thinking about this voice-recognition stuff. What geek doesn&#8217;t want to walk into the living room and say &#8220;Computer: Lights On&#8221; and have it work?</p>

	<p>Instead, as a first step to all of that, let me show you how to use PowerShell to do simple voice command recognition scripts &#8230; which can fire off any PowerShell script you care to write! <span id="more-1188"></span> The code which follows is really a module, although you can just dot-source it as a script, and it really requires PowerShell 2.0 for the events, although it would be trivial to refactor it to work on PowerShell 1.0 using Oisin&#8217;s <a href="http://pseventing.codeplex.com/">PSEventing library</a>.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$null</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Reflection.<span style="color: #003366;">Assembly</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">LoadWithPartialName</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;System.Speech&quot;</span><span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Create the two main objects we need for speech recognition and synthesis</span><br />
<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener<span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span> <span style="color: #666666; font-style: italic;">## For XP's sake, don't create them twice...</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleSpeaker <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Speech</span>.<span style="color: #003366;">Synthesis</span>.<span style="color: #003366;">SpeechSynthesizer</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Speech</span>.<span style="color: #003366;">Recognition</span>.<span style="color: #003366;">SpeechRecognizer</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">## Add a way to turn it off</span><br />
<span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;Stop Listening&quot;</span>, <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$script</span>:listen <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span>; <span style="color: #0066cc; font-style: italic;">Suspend-<span style="font-style: normal;">Listening</span></span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleComputerName <span style="color: #66cc66;">=</span> $<span style="color: #333;">&#123;</span>Env:ComputerName<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Update-<span style="font-style: normal;">SpeechCommands</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Recreate the speech recognition grammar</span><br />
<span style="color: #666666; font-style: italic;">#.Description</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;This parses out the speech module macros, </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;and recreates the speech recognition grammar and semantic results, </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;and then updates the SpeechRecognizer with the new grammar, </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;and makes sure that the ObjectEvent is registered.</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$choices</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Speech</span>.<span style="color: #003366;">Recognition</span>.<span style="color: #003366;">Choices</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$choice</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros.<span style="color: #003366;">GetEnumerator</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Speech</span>.<span style="color: #003366;">Recognition</span>.<span style="color: #003366;">SemanticResultValue</span> <span style="color: #660033; font-weight: bold;">$choice</span>.<span style="color: #003366;">Key</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$choice</span>.<span style="color: #003366;">Value</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">ForEach-<span style="font-style: normal;">Object</span></span><span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$choices</span>.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">ToGrammarBuilder</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$VerbosePreference</span> <span style="color: #000066;">-ne</span> <span style="color: #009900;">&quot;SilentlyContinue&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros.<span style="color: #003366;">Keys</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">ForEach-<span style="font-style: normal;">Object</span></span> <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$Computer, $_&quot;</span> <span style="color: #000066;">-Fore</span> Cyan <span style="color: #333;">&#125;</span> <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$builder</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Speech</span>.<span style="color: #003366;">Recognition</span>.<span style="color: #003366;">GrammarBuilder</span> <span style="color: #009900;">&quot;$Computer, &quot;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$builder</span>.<span style="color: #003366;">Append</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Speech</span>.<span style="color: #003366;">Recognition</span>.<span style="color: #003366;">SemanticResultKey</span> <span style="color: #009900;">&quot;Commands&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$choices</span>.<span style="color: #003366;">ToGrammarBuilder</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$grammar</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Speech</span>.<span style="color: #003366;">Recognition</span>.<span style="color: #003366;">Grammar</span> <span style="color: #660033; font-weight: bold;">$builder</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$grammar</span>.<span style="color: #003366;">Name</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Power VoiceMacros&quot;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Take note of the events, but only once (make sure to remove the old one)</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Unregister-<span style="font-style: normal;">Event</span></span> <span style="color: #009900;">&quot;SpeechModuleCommandRecognized&quot;</span> <span style="color: #000066;">-ErrorAction</span> SilentlyContinue<br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$null</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Register-<span style="font-style: normal;">ObjectEvent</span></span> <span style="color: #660033; font-weight: bold;">$grammar</span> SpeechRecognized `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-SourceIdentifier</span> <span style="color: #009900;">&quot;SpeechModuleCommandRecognized&quot;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-Action</span> <span style="color: #333;">&#123;</span> <span style="color: #660033;">iex</span> <span style="color: #660033; font-weight: bold;">$event</span>.<span style="color: #003366;">SourceEventArgs</span>.<span style="color: #003366;">Result</span>.<span style="color: #003366;">Semantics</span>.<span style="color: #003366;">Item</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;Commands&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Value</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener.<span style="color: #003366;">UnloadAllGrammars</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener.<span style="color: #003366;">LoadGrammarAsync</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$grammar</span> <span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">SpeechCommands</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Add one or more commands to the speech-recognition macros, and update the recognition</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter CommandText</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The string key for the command to remove</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#91;</span>CmdletBinding<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">Param</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">hashtable</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$VoiceMacros</span>,<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Computer</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleComputerName<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Add the new macros</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros <span style="color: #66cc66;">+=</span> <span style="color: #660033; font-weight: bold;">$VoiceMacros</span> <br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Update the default if they change it, so they only have to do that once.</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleComputerName <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Computer</span> <br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Update-<span style="font-style: normal;">SpeechCommands</span></span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Remove-<span style="font-style: normal;">SpeechCommands</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Remove one or more command from the speech-recognition macros, and update the recognition</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter CommandText</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The string key for the command to remove</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">Param</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$CommandText</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$command</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$CommandText</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros.<span style="color: #003366;">Remove</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Command</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Update-<span style="font-style: normal;">SpeechCommands</span></span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Clear-<span style="font-style: normal;">SpeechCommands</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Removes all commands from the speech-recognition macros, and update the recognition</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter CommandText</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The string key for the command to remove</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Default value: A way to turn it off</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Script</span>:SpeechModuleMacros.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;Stop Listening&quot;</span>, <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Suspend-<span style="font-style: normal;">Listening</span></span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Update-<span style="font-style: normal;">SpeechCommands</span></span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Listening</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Sets the SpeechRecognizer to Enabled</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener.<span style="color: #003366;">Enabled</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp;<span style="color: #660033;">Say</span> <span style="color: #009900;">&quot;Speech Macros are $($Global:SpeechModuleListener.State)&quot;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Speech Macros are $($Global:SpeechModuleListener.State)&quot;</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Suspend-<span style="font-style: normal;">Listening</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Sets the SpeechRecognizer to Disabled</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener.<span style="color: #003366;">Enabled</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
&nbsp; &nbsp;<span style="color: #660033;">Say</span> <span style="color: #009900;">&quot;Speech Macros are disabled&quot;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Speech Macros are disabled&quot;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">Speech</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Speaks the input object</span><br />
<span style="color: #666666; font-style: italic;">#.Description</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Uses the default SpeechSynthesizer settings to speak the string representation of the InputObject</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter InputObject</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The object to speak </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;NOTE: this should almost always be a pre-formatted string,</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp;most objects don't render to very speakable text.</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">Param</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>ValueFromPipeline<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#91;</span>Alias<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;IO&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #660033; font-weight: bold;">$InputObject</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$null</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleSpeaker.<span style="color: #003366;">SpeakAsync</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #66cc66;">|</span><span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">String</span></span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Remove-<span style="font-style: normal;">SpeechXP</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">#.Synopis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Dispose of the SpeechModuleListener and SpeechModuleSpeaker</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener.<span style="color: #003366;">Dispose</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>; <span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleListener <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$null</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleSpeaker.<span style="color: #003366;">Dispose</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>; <span style="color: #660033; font-weight: bold;">$Global</span>:SpeechModuleSpeaker <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$null</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">set-<span style="font-style: normal;">alias</span></span> asc <span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">SpeechCommands</span></span><br />
<span style="color: #0066cc; font-style: italic;">set-<span style="font-style: normal;">alias</span></span> rsc <span style="color: #0066cc; font-style: italic;">Remove-<span style="font-style: normal;">SpeechCommands</span></span><br />
<span style="color: #0066cc; font-style: italic;">set-<span style="font-style: normal;">alias</span></span> csc <span style="color: #0066cc; font-style: italic;">Clear-<span style="font-style: normal;">SpeechCommands</span></span><br />
<span style="color: #0066cc; font-style: italic;">set-<span style="font-style: normal;">alias</span></span> <span style="color: #660033;">say</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">Speech</span></span><br />
<span style="color: #0066cc; font-style: italic;">set-<span style="font-style: normal;">alias</span></span> listen <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Listener</span></span><br />
<span style="color: #0066cc; font-style: italic;">Export-<span style="font-style: normal;">ModuleMember</span></span> <span style="color: #000066;">-Function</span> <span style="color: #66cc66;">*</span> <span style="color: #000066;">-Alias</span> <span style="color: #66cc66;">*</span> <span style="color: #000066;">-Variable</span> SpeechModuleListener, SpeechModuleSpeaker</div>

	<p>There&#8217;s basically just one function you need to worry about here: <code>New-VoiceCommands</code>.  You pass it a hashtable which maps strings to scriptblocks, and if you use the <code>-Listen</code> switch that&#8217;s all there is to it.  You can also call <code>Start-Listening</code> manually, and of course, I&#8217;ve provided the <code>Say</code> function to make it easier to have the computer speak&#8230;</p>

	<p>Once the computer is &#8220;listening&#8221; ... you just say it&#8217;s name, followed by one of your commands. I like that because it ensures that I don&#8217;t run the scripts by accident, but you can remove the <code>&#34;${Env:ComputerName}, &#34;</code> string from the beginning of the GrammarBuilder if you think it&#8217;s not necessary, or you can hard code it to something other than your computer&#8217;s name, like say &#8220;Hal, please, I beg you &#8230; &#8220; or &#8220;Computer, please &#8220; or whatever. <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

	<p>You can do a lot of things with this &#8230; anything, really &#8230; but to give you an example that you can easily understand, I&#8217;m going to do something very simple, and have my computer just answer a few basic questions by talking back to me, and then add a few commands to have it start an app or a web page.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">SpeechCommands</span></span> @<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&quot;What time is it?&quot;</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033;">Say</span> <span style="color: #009900;">&quot;It is $(Get-Date -f &quot;</span><span style="color: #660033;">h</span>:mm tt<span style="color: #009900;">&quot;)&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&quot;What day is it?&quot;</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033;">Say</span> $<span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span> <span style="color: #000066;">-f</span> <span style="color: #009900;">&quot;dddd, MMMM dd&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #009900;">&quot;What's running?&quot;</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$proc</span> <span style="color: #66cc66;">=</span> <span style="color: #660033;">ps</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">sort</span> ws <span style="color: #000066;">-desc</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033;">Say</span> $<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;$($proc.Count) processes, including $($proc[0].name), which is using &quot;</span> <span style="color: #66cc66;">+</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&quot;$([int]($proc[0].ws/1mb)) megabytes of memory&quot;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Computer</span> <span style="color: #009900;">&quot;Laptop&quot;</span> <span style="color: #000066;">-Verbose</span> <br />
<br />
<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">SpeechCommands</span></span> @<span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;Run Notepad&quot;</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #66cc66;">&amp;</span>amp; <span style="color: #009900;">&quot;C:\Programs\DevTools\Notepad++\notepad++.exe&quot;</span> <span style="color: #333;">&#125;</span> <span style="color: #333;">&#125;</span><br />
<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">SpeechCommands</span></span> @<span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;Check Gee Mail&quot;</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Process</span></span> <span style="color: #009900;">&quot;https://mail.google.com&quot;</span> <span style="color: #333;">&#125;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>You see how easy that is? You can use &#8220;Say&#8221; to speak any text (although sometext will get better results than others), and you can invoke any other powershell commands, including HttpRest commands to fetch web data, or <span class="caps">WASP</span> commands for windows automation, or PowerBoots commands to display output in large text, or cmdlets to control X10 or ZWave devices &#8230; you know, anything <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/d6e29bc6-dd76-464f-8040-7c8d8e90b08f/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=d6e29bc6-dd76-464f-8040-7c8d8e90b08f" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/control-your-pc-with-your-voice-and-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WPF in PowerShell: PowerBoots 0.2</title>
		<link>http://huddledmasses.org/wpf-in-powershell-powerboots-02/</link>
		<comments>http://huddledmasses.org/wpf-in-powershell-powerboots-02/#comments</comments>
		<pubDate>Thu, 18 Jun 2009 04:14:54 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1183</guid>
		<description><![CDATA[	I&#8217;ve finally given over trying to improve PowerBoots for this iteration of development, and in between setting up the ScriptingGames.PoshCode site and releasing the PoshCode software on the main PoshCode.org site (it&#8217;s coming, I promise), I decided to take a few minutes and release this lates PowerBoots, and it&#8217;s a ground-breaking release, if I do [...]]]></description>
			<content:encoded><![CDATA[	<p>I&#8217;ve finally given over trying to improve PowerBoots for this iteration of development, and in between setting up the <a href="http://scriptinggames.poshcode.org">ScriptingGames.PoshCode</a> site and releasing the PoshCode software on the main PoshCode.org site (it&#8217;s coming, I promise), I decided to take a few minutes and release this lates PowerBoots, and it&#8217;s a <a href="http://powerboots.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=28954">ground-breaking release</a>, if I do say so myself!</p>

	<h3>PowerShell 1.0 Compatibility</h3>

	<p>There are three huge changes in this release, actually. But the biggest one is that <em>most</em> of the functionality works in the released version of PowerShell 1.0!  There are still a few glitches and bugs when it&#8217;s running in 1.0, but I&#8217;ve decided it&#8217;s past time I just release it and let you start using it!  If you use it on 1.0, please let me know if you run into anything weird, or problems you can&#8217;t figure out workarounds for.</p>

	<h3>Cached Script Functions!</h3>

	<p>The second biggest change is that all of the functions are now cached. The first time it&#8217;s loaded, PowerBoots actually writes out a few hundred scripts files into a &#8220;Functions&#8221; subfolder, and from then on, they&#8217;re only loaded when they&#8217;re used &#8212; saving you <em>a lot</em> of time at startup, and <em>a lot</em> of memory.  Additionally, when you load in additional controls, such as the <a href="http://www.visifire.com/">Visifire <span class="caps">WPF</span> chart controls</a>, those functions are cached permanently too, so you never even have to manually load the assembly again!</p>

	<h3>Dependency Properties</h3>

	<p>A few people have asked over the last few months about how to <a href="http://huddledmasses.org/powerboots-and-attached-properties/">set attached properties and dependency properties in <span class="caps">WPF</span> from PowerShell</a>, so in this release I&#8217;ve included full support for these in a way that will, I hope, simply work so well it will boggle your mind <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  All you have to do to tell a control, for instance, to be in the 3rd column of a grid is to just pass <code>Button &#34;Click Me&#34; -&#34;Grid:Column&#34; 2</code> &#8230; it&#8217;s <span class="caps">THAT</span> simple. In fact, for properties that have unique names, you don&#8217;t even have to specify the type, just the name, like <code>-Row 3</code> to specify the grid row.</p>

	<h3>Regression and Backwards Compatibility </h3>

	<p>Of course, the downside of these changes is that some of the syntax has changed a little bit. All scripts and event handlers (ie: click handlers for <span class="caps">WPF</span> Buttons) are run from the <strong>dll</strong> module scope in PowerShell 2 (the global scope in PowerShell 1), which means that they can&#8217;t access &#8220;script&#8221; scope variables from your scripts (which ends up meaning you have to declare a lot of things global that you could leave in script scope before).  Just to be clear on the quality of this release: once we have ironed out the minor problems we&#8217;re having with PowerShell 1.0 in a way that I&#8217;m comfortable with, I expect to push the version number up and release an 1.0 Release Candidate, barring any major issues.</p>

	<p>In order to help with the transition, I&#8217;ve included a Samples.ps1 script which has 28 sample scripts in it (mostly from the original <a href="http://huddledmasses.org/powerboots-tutorial-walkthrough/">Tutorial Walk-through</a>, which I will update soon).  I&#8217;ve updated each of them to work with this release, in both PowerShell 1 and PowerShell 2 (which means they&#8217;re almost all written in PowerShell 1 syntax), so you can use them as good examples of how to get things done!</p>

	<p>Please use the Discussions Forum and Issue Tracker on <a href="http://boots.CodePlex.org">the CodePlex site</a> to post any problems you have, and I&#8217;ll try to write up a few more posts describing changes and differences in the next couple of weeks.</p>

<h6 class="zemanta-related-title">Related articles by Zemanta</h6><ul class="zemanta-article-ul"><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/powerboots-loading-xaml-windows-in-powershell-10-or-20/">PowerBoots: Loading <span class="caps">XAML</span> Windows in PowerShell 1.0 or 2.0</a> (huddledmasses.org)</li><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/powerboots-now-multi-threaded/">PowerBoots: PowerShell GUIs are now multi-threading</a> (huddledmasses.org)</li><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/pingmonitor-interactive-wpf-uis-from-powershell-10-or-20/">PingMonitor: interactive <span class="caps">WPF</span> UIs from PowerShell (1.0 or 2.0)</a> (huddledmasses.org)</li></ul>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/3373c251-af5f-4875-a3fa-7f0c2581d019/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=3373c251-af5f-4875-a3fa-7f0c2581d019" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/wpf-in-powershell-powerboots-02/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PoshCode Poll: How do you want Search to work?</title>
		<link>http://huddledmasses.org/poshcode-poll-how-do-you-want-search-to-work/</link>
		<comments>http://huddledmasses.org/poshcode-poll-how-do-you-want-search-to-work/#comments</comments>
		<pubDate>Sun, 31 May 2009 02:07:39 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1181</guid>
		<description><![CDATA[	
If you can only have ONE of these, how would you like to search our PoshCode.org script/module repository?(opinion poll)
]]></description>
			<content:encoded><![CDATA[	<p><script type="text/javascript" language="javascript" charset="utf-8" src="http://static.polldaddy.com/p/1665040.js"></script><noscript><br />
<a href="http://answers.polldaddy.com/poll/1665040/">If you can only have <span class="caps">ONE</span> of these, how would you like to search our PoshCode.org script/module repository?</a><span style="font-size:9px;">(<a href="http://answers.polldaddy.com">opinion poll</a>)</span><br />
</noscript></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/poshcode-poll-how-do-you-want-search-to-work/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Huddled Masses on the move</title>
		<link>http://huddledmasses.org/huddled-masses-on-the-move/</link>
		<comments>http://huddledmasses.org/huddled-masses-on-the-move/#comments</comments>
		<pubDate>Wed, 20 May 2009 03:53:52 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>

		<guid isPermaLink="false">http://joelbennett.net/?p=1174</guid>
		<description><![CDATA[	Please excuse the dust while I shuffle a few bytes around, I&#8217;m moving my site to a new server &#8230; just for fun &#8230; and I haven&#8217;t copied over the old theme or anything yet.  Here&#8217;s something pretty to look at to make up for the simplicity of the site  

Image by alexdecarvalho [...]]]></description>
			<content:encoded><![CDATA[	<p>Please excuse the dust while I shuffle a few bytes around, I&#8217;m moving my site to a new server &#8230; just for fun &#8230; and I haven&#8217;t copied over the old theme or anything yet.  Here&#8217;s something pretty to look at to make up for the simplicity of the site <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<div class="zemanta-img"><div><dl class="wp-caption alignright"><dt class="wp-caption-dt"><a href="http://www.flickr.com/photos/51035823282@N01/413604899"><img src="http://farm1.static.flickr.com/153/413604899_6f208098f0_d.jpg" alt="moving on" title="moving on" /></a></dt><dd class="wp-caption-dd zemanta-img-attribution">Image by <a href="http://www.flickr.com/photos/51035823282@N01/413604899">alexdecarvalho</a> via Flickr</dd></dl></div></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/huddled-masses-on-the-move/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Convert Twitter users into FriendFeed Imaginary Friends!</title>
		<link>http://huddledmasses.org/convert-twitter-users-into-friendfeed-imaginary-friends/</link>
		<comments>http://huddledmasses.org/convert-twitter-users-into-friendfeed-imaginary-friends/#comments</comments>
		<pubDate>Sat, 16 May 2009 20:15:47 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>

		<guid isPermaLink="false">http://joelbennett.net/?p=1170</guid>
		<description><![CDATA[	So a lot of people seem to be taking the latest missteps by Twitter&#8217;s management (and the accompanying admission of bad design) as an opportunity to try out some alternatives. Many of them seem to be coming over to FriendFeed (which has been better than Twitter for a long time, but nevermind that) ... so [...]]]></description>
			<content:encoded><![CDATA[	<p>So a lot of people seem to be taking the <a href="http://blog.twitter.com/2009/05/whoa-feedback.html">latest missteps</a> by Twitter&#8217;s management (and <a href="http://blog.twitter.com/2009/05/replies-kerfuffle.html">the accompanying admission of bad design</a>) as an opportunity to try out some alternatives. Many of them seem to be coming over to FriendFeed (which has been better than Twitter for a long time, but nevermind that) ... so I thought I&#8217;d update and release a PowerShell 2.0 script I wrote to create <a href="http://friendfeed.com/settings/imaginary">imaginary friends</a> out of your friends that stay on Twitter.</p>

	<p>The first part of it is a WatiN script (that automates your browser) called <code>New-ImaginaryFriend</code> which takes three parameters: a name for the imaginary friend, a url for an avatar for the friend, and a HashTable&#8230;  Of course, we sort-of cheat by using the HashTable &#8230; it&#8217;s basically a bunch of key-value pairs of remote services and user names. You can use it to add twitter ID&#8217;s like <code>twitter=&#34;jsnover&#34;</code> or blogs like <code>blog=&#34;http://HuddledMasses.org/&#34;</code> etc.  You can even add multiple sources (eg: twitter + diigo, two blogs, etc) to a single new imaginary friend 8)...</p>

	<p>This script is done using WatiN because the FriendFeed <span class="caps">API</span> doesn&#8217;t support creating imaginary friends yet, and as a result it&#8217;s slow, and requires IE (and doesn&#8217;t seem to work very well with IE8 &#8212; at least, I couldn&#8217;t get it to set the avatars using IE 8 on Windows 7, so I commented out the avatar part of the next-to-last line).</p>

	<p>The other part of the script is a pair of functions: the first is <code>Get-FriendFeedFriends</code> which retrieves profile information for all your friends in a slick format that includes all their services and such &#8230; you may find other uses for this later <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> , the second is <code>Get-TwitterFriends</code> &#8230; Both have an <code>-Exclude</code> parameter so you can pass it a list of people to ignore.</p>

	<p>When you put these three functions together, you can just import the FriendFeed module, and start creating friends (don&#8217;t forget <em>this</em> version of the scripts only works with IE6 or IE7 for the purpose of avatars, as WatiN can&#8217;t seem to set the file upload value in IE8 yet).</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> FriendFeed<br />
<span style="color: #666666; font-style: italic;">## Get any twitter friends who aren't on friendfeed</span><br />
<span style="color: #666666; font-style: italic;">## Make sure you use FriendFeed's built in &quot;add all your twitter friends&quot; first</span><br />
<span style="color: #660033; font-weight: bold;">$twits</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">TwitterFriends</span></span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-Nickname</span> jaykul<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-Exclude</span> $<span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">FriendFeedFriends</span></span> jaykul <span style="color: #66cc66;">|</span> <span style="color: #660033;">select</span> <span style="color: #000066;">-expand</span> twitter<span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Add them to friend feed</span><br />
<span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$twit</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$twits</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">ImaginaryFriend</span></span> <span style="color: #660033; font-weight: bold;">$twit</span>.<span style="color: #003366;">name</span> @<span style="color: #333;">&#123;</span>twitter<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$twit</span>.<span style="color: #003366;">screen_name</span><span style="color: #333;">&#125;</span> <span style="color: #660033; font-weight: bold;">$twit</span>.<span style="color: #003366;">profile_image_url</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>You can <a href="/downloads/FriendFeedModule+Dependencies.zip">download all of the required modules at once</a> (<a href="/downloads/FriendFeedModule+Dependencies.7z">7z</a>), or grab the latest versions of them from PoshCode: <a href="http://poshcode.org/1110">FriendFeed</a>, <a href="http://poshcode.org/1107">HttpRest</a>, and  <a href="http://poshcode.org/1108">WatiN</a> &#8230; but if you do that, you&#8217;ll still need to get the binaries separately :-/</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/convert-twitter-users-into-friendfeed-imaginary-friends/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Where to go for PowerShell help&#8230;</title>
		<link>http://huddledmasses.org/where-to-go-for-powershell-help/</link>
		<comments>http://huddledmasses.org/where-to-go-for-powershell-help/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 17:51:17 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1162</guid>
		<description><![CDATA[	Here it is. According to my observations, this is the list of places where I recommend you seek help for PowerShell related quandaries, in order of the speed of response.  The first two are practically a tie, but I have put them in this order because the first is just a much better place [...]]]></description>
			<content:encoded><![CDATA[	<p>Here it is. According to my observations, this is the list of places where I recommend you seek help for PowerShell related quandaries, <strong>in order of the <em>speed of response</em></strong>.  The first two are practically a tie, but I have put them in this order because the first is just a much better place to get questions answered, with no limits on length of posts. In almost every case, you&#8217;ll get faster responses during US daytime, due to sheer volume of users&#8230;</p>

	<ol>
		<li><span class="caps">IRC</span> <a href="irc://irc.freenode.net/powershell">#PowerShell on <span class="caps">IRC</span>.Freenode.net</a>. </li>
		<li>Twitter. Use a the word &#8220;PowerShell&#8221; in a tweet with a question.</li>
		<li>Usenet. <a href="news://msnews.microsoft.com:119/microsoft.public.windows.powershell">Microsoft.public.Windows.PowerShell</a> (or via <a href="http://groups.google.com/group/microsoft.public.windows.powershell/">Google Groups</a>).</li>
	</ol>
	<ol>
		<li>Web Forum. <a href="http://powershellcommunity.org/Forums.aspx">On PowerShellCommunity.org</a></li>
	</ol>

	<p>The funny thing is, Twitter <em>can</em> be fast, but it&#8217;s not a very effective way of getting answers to anything but trivial questions.  Usenet <em>can</em> be fast, but it can also ignore you completely.  <span class="caps">IRC</span> can be astonishingly fast &#8230; <em>if</em> you happen to come in while several high level geeks are having a conversation and thus, paying attention &#8230; but at other times (especially in the middle of the <span class="caps">USA</span> sleep hours) you might not get an answer at all, depending on who&#8217;s paying attention that day.  Hypothetically, the WebForum would be the best place to ask &#8212; since unanswered questions there still stay in an &#8220;unanswered&#8221; list that MVPs and others can check &#8212; but for some reason it&#8217;s never built up the critical mass of users that would allow it to be fast around the clock, or even to answer every single question&#8230;</p>

	<p>I&#8217;m secretly hoping someone will develop a piece of web software which will function as a web forum with an option to email subscribe (like CodePlex&#8217;s forums).  But in addition, will also function as a web interface to Usenet a-la Google Groups, so that we could set up a web forum which posted questions to an existing Usenet group. It would also need a web-service feed &#8230; so we could write a bot that could post new questions to <span class="caps">IRC</span> (or a Jabber conference room) and Twitter.  It wouldn&#8217;t necessarily have to accept answers via IRC/Jabber/Twitter, since those users are usually willing to click through if they think they can help answer a question &#8230; this would be the ultimate web forum software. Why can&#8217;t I find it already written?</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/where-to-go-for-powershell-help/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A WPF Countdown Timer in PowerShell 2.0</title>
		<link>http://huddledmasses.org/a-wpf-countdown-timer-in-powerboots/</link>
		<comments>http://huddledmasses.org/a-wpf-countdown-timer-in-powerboots/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 03:35:20 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1156</guid>
		<description><![CDATA[	Well, it&#8217;s been awhile since I posted anything, and this causes me angst. I&#8217;ve been spending all of my time lately on PoshCode.org &#8212; not writing content, but working on a new Asp.Net MVC-based back-end (on codeplex) &#8212; but in the meantime, this month PoshCode.org finally passed this site&#8217;s raw pageview count, and it made [...]]]></description>
			<content:encoded><![CDATA[	<p>Well, it&#8217;s been awhile since I posted anything, and this causes me angst. I&#8217;ve been spending all of my time lately on <a href="http://PoshCode.org">PoshCode.org</a> &#8212; not writing content, but working on a new Asp.Net MVC-based back-end (<a href="http://PoshCode.CodePlex.com">on codeplex</a>) &#8212; but in the meantime, this month PoshCode.org finally passed this site&#8217;s raw pageview count, and it made me realized I hadn&#8217;t posted anything in a long time.</p>

	<p>I have a whole stack of <a href="http://huddledmasses.org/powerboots-tutorial-walkthrough/">PowerBoots</a> demos that I&#8217;ve been promising various people that I would post, so I figure I really ought to start putting them up, even if I don&#8217;t feel like I have time to properly explain them.</p>

	<p>A few in particular don&#8217;t need much explaining, so lets start with a couple of those. A while back I wrote <a href="http://poshcode.org/161">a kitchen timer function</a> in response to <a href="http://powerscripting.wordpress.com/2008/03/16/one-liner-countdown-timer-in-powershell/">Hal Rottenberg&#8217;s one liner</a>  and recently I had cause to pull that out to help my kids take turns playing computer games on <a href="http://UpToTen.com">Up to Ten</a> &#8230; but I needed something a little more visible for their sake.</p>

	<p>So I converted my old script to a new PowerBoots-based version with large numbers and a gradient brush that slides across and turns the whole thing to red text as the end of the time get&#8217;s closer and closer:</p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/Start-BootsTimer.png" alt="" width="644" height="338" /></p>

<script type="text/javascript" src="http://PoshCode.org/embed/1046"></script>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/a-wpf-countdown-timer-in-powerboots/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Using Script Functions in the PowerShell Pipeline ( Take Two )</title>
		<link>http://huddledmasses.org/using-script-functions-in-the-powershell-pipeline-take-two/</link>
		<comments>http://huddledmasses.org/using-script-functions-in-the-powershell-pipeline-take-two/#comments</comments>
		<pubDate>Mon, 13 Apr 2009 13:07:27 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Advanced Functions]]></category>
		<category><![CDATA[Pipeline]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Functions]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/using-script-functions-in-the-powershell-pipeline-take-two/</guid>
		<description><![CDATA[	One of the consistent questions about PowerShell is: what&#8217;s the best way to write a script or a  function to process pipeline objects and be able to take it&#8217;s parameters as a normal function?

	Of scripts and functions

	The first thing to know is that in PowerShell, there&#8217;s really no difference between a script (just a [...]]]></description>
			<content:encoded><![CDATA[	<p>One of the consistent questions about PowerShell is: what&#8217;s the best way to write a script or a  function to process pipeline objects <em>and</em> be able to take it&#8217;s parameters as a normal function?</p>

	<h3>Of scripts and functions</h3>

	<p class="em1">The first thing to know is that in PowerShell, there&#8217;s really no difference between a script (just a file with a .ps1 ending) and a function as you&#8217;ll see written below. If you take a function Get-Square, and remove the first and last lines (<code> Function Get-Square { </code> &#8230; <code> } </code>) you could put them in a file called &#8220;Get-Square.ps1&#8221; in your <span class="caps">PATH</span>, you use them exactly the way you would the function that was pre-loaded into memory by dot-sourcing or pasting it on the command line.  Of course, doing that easily requires writing the function parameters on their own line using <code>PARAM(...)</code> syntax, which is why I recommend doing that.</p>

	<h3>Of functions and the pipeline</h3>

	<p>When your script or function is used on the pipeline its <code>begin</code> block is called <em>once</em> when the pipeline starts up, and then the <code>process</code> block is called repeatedly: once to <em>process</em> each pipeline object, and finally, the <code>end</code> block is called after all the objects have been processed through the whole pipeline.  If you don&#8217;t understand that, you should play with this function, try calling it by passing a series of numbers through multiple instances of it:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquarePipe</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PARAM</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$label</span>, <span style="color: #660033; font-weight: bold;">$color</span><span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;White&quot;</span> <span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">BEGIN</span> &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Begin $Label&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$Label <span style="color: #000099; font-weight: bold;">`t</span> $_&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #66cc66;">*</span> <span style="color: #660033; font-weight: bold;">$_</span> <br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">END</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;End $Label&quot;</span> &nbsp; <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># for example ...</span><br />
1..5 <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquarePipe</span></span> one cyan <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquarePipe</span></span> two yellow <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquarePipe</span></span> three green<br />
&nbsp;</div>

	<p style="padding-left:2em;">Incidentally, if you don&#8217;t specify the <code>begin</code>, <code>process</code>, or <code>end</code> blocks, the body of your function is treated as the <code>end</code> block. This is so that you can use the special <code>$Input</code> variable, which collects all the things passed in on the pipeline, and thus only works in the <code>end</code> block.  That would allow the following function to behave the same way regardless of whether it was invoked on the pipeline or by passing an <code>$InputObject</code>. Notice, however, the difference between this, and the function above.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">Function</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquareEnd</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">PARAM</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$label</span>, <span style="color: #660033; font-weight: bold;">$color</span><span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;White&quot;</span>, <span style="color: #660033; font-weight: bold;">$InputObject</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">BEGIN</span> &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Begin $Label&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$Label <span style="color: #000099; font-weight: bold;">`t</span> $_&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">END</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## because one of $Input or $InputObject must be null:</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">Foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$item</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$Input</span> <span style="color: #66cc66;">+</span> <span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$Label <span style="color: #000099; font-weight: bold;">`t</span> $item&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$item</span> <span style="color: #66cc66;">*</span> <span style="color: #660033; font-weight: bold;">$item</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># and test it like this</span><br />
1..5 <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquareEnd</span></span> one cyan <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquareEnd</span></span> two yellow <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquareEnd</span></span> three green<br />
<br />
<span style="color: #666666; font-style: italic;"># Or like this</span><br />
1..5 <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquarePipe</span></span> one cyan <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquareEnd</span></span> two yellow <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">SquareEnd</span></span> three green<br />
&nbsp;</div>

	<h3>Our challenge </h3>

	<p>The basic idea here is to rewrite that function such that it can be used to process a set of numbers from <em>either</em> the pipeline or an argument, without interfering with the processing of other parameters. We require that the function process items as they come in, rather than waiting until it&#8217;s received all input before processing them the way <code>Test-SquareEnd</code> does.</p>

	<h4>In PowerShell 2.0 this would be easy </h4>

	<p>In the current <span class="caps">CTP</span> 3 of PowerShell 2, you just specify <code>ValueFromPipeline=$true</code> for the parameter you want to set from the pipeline, and the function will work the same way whether you pass the numbers as a parameter or along the pipeline &#8212; you can even control which attribute of the objects on the pipeline will be used, but that&#8217;s <a href="a-guide-to-advanced-functions">a whole other article</a>.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">Function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">PARAM</span><span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$label</span><br />
, &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>ConsoleColor<span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;White&quot;</span><br />
, &nbsp;<span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>ValueFromPipeline<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$InputObject</span> <br />
<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">BEGIN</span> &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Begin $Label&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">END</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;End $Label&quot;</span> &nbsp; <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">ForEach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$Label $i&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #66cc66;">*</span> <span style="color: #660033; font-weight: bold;">$i</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Either way we call these, they have the same output</span><br />
<span style="color: #666666; font-style: italic;">## Unlike what Get-SquarePipe or Get-SquareEnd </span><br />
<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">4</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> one green <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> two cyan<br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> one green <span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span>,<span style="color: #cc66cc;">4</span> &nbsp; <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> two cyan<br />
&nbsp;</div>

	<p>Of course, PowerShell 2.0 is still in beta status, and even after it&#8217;s released you may need to write scripts that are backwards compatible to PowerShell 1.0, and the excercise of doing so may  help you to understand more about how PowerShell functions work, and particularly how they behave in the pipeline.</p>

	<h3>Our solution</h3>

	<p>Since in a PowerShell 1.0 function it&#8217;s not really supported directly, we need to do some extra work:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PARAM</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$label</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;&quot;</span><br />
&nbsp; &nbsp;, &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>ConsoleColor<span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$color</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;White&quot;</span><br />
&nbsp; &nbsp;, &nbsp;<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$InputObject</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$null</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">BEGIN</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## If you accepted additional params, you'd need to pass those in</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$InputObject</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">&amp;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$MyInvocation</span>.<span style="color: #003366;">InvocationName</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-Label</span> <span style="color: #660033; font-weight: bold;">$label</span> <span style="color: #000066;">-Color</span> <span style="color: #660033; font-weight: bold;">$color</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## break</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;Begin $Label&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## If you specify a type for $InputObject, test for that here</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #000066;">-is</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#93;</span></span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$Label $_&quot;</span> <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #66cc66;">*</span> <span style="color: #660033; font-weight: bold;">$_</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">elseif</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">throw</span> <span style="color: #009900;">&quot;$_ is not a System.Int32&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">END</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;End $Label&quot;</span> &nbsp; <span style="color: #000066;">-Foreground</span> <span style="color: #660033; font-weight: bold;">$color</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
&nbsp;</div>

	<h3>An explanation</h3>

	<p>Of course, this is just an example method, squaring things isn&#8217;t that exciting &#8212; but what&#8217;s special about it is that the output is almost exactly the same whether you call it with parameters <code>Get-Square 1,2,3,4</code> or on the pipeline: <code>1,2,3,4 | Get-Square</code>.    </p>

	<p>The trick is that it actually executes the same way in either case:</p>

	<ol>
		<li>If you call it by passing the int (or array of ints) as an argument (<code>$InputObject</code>), it calls itself and passes those values on the pipeline.</li>
		<li>When the integers are passed on the pipeline, the special pipeline iterator variable <code>$_</code> is set, and the process block is executed.</li>
	</ol>
	<ol>
		<li>When it has to (re)invoke itself, it passes any other parameters as parameters, which means you need to have default values for them.</li>
	</ol>

	<p>There is <em>one</em> tiny difference in the processing, which in real-world use is practically never noticeable (you can see it in our example if you call it like this): </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> one green <span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> two cyan<br />
<span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">2</span>,<span style="color: #cc66cc;">3</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> one green <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Square</span></span> two cyan<br />
&nbsp;</div>

	<p>You&#8217;ll see that unlike the PowerShell 2.0 pipeline function, when you pass the numbers as a parameter, the first one of them actually gets passed through the <code>process</code> block before the <code>begin</code> block of the second function on the pipeline is called. This usually doesn&#8217;t have any effect, but it&#8217;s something to keep in the back of your head.</p>

	<h3>A few precautions: </h3>

	<ul>
		<li>You have to default values for parameters, because you&#8217;ll be passing them all as named parameters, in the re-invoke step, and <code>$null</code> can cause problems.</li>
		<li>If you need to do additional processing in the <code>begin</code> block, you should only do so in an <code>ELSE</code> case: when $InputObject is null.  That way, the code will only execute <em>once</em> each time you call the function. </li>
		<li>The same goes for the <code>end</code> block: you have to keep your code in an <code>If(!$InputObject)</code> block to avoid executing it twice (when you pass the values as an argument, and it re-invokes itself). </li>
	</ul>
	<ul>
		<li>The test cases in the <code>process</code> block <em>must</em> wrap all of your process block code, so that you don&#8217;t process the arguments twice, and you shouldn&#8217;t refer to $InputObject, but instead should use the automatic <code>$_</code> variable which is the value passed when the function is (re)invoked via the pipeline.</li>
	</ul>

	<p>Here&#8217;s some sample output, in case you&#8217;re wondering:</p>

	<div class="text code text" style="font-family:monospace;"><br />
PS&gt; Get-Square test cyan 2,3,4<br />
Begin test<br />
test 2<br />
4<br />
test 3<br />
9<br />
test 4<br />
16<br />
End test<br />
<br />
PS&gt; 2,3,4|Get-Square test cyan<br />
Begin test<br />
test 2<br />
4<br />
test 3<br />
9<br />
test 4<br />
16<br />
End test<br />
&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/using-script-functions-in-the-powershell-pipeline-take-two/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerBoots: The tutorial walkthrough</title>
		<link>http://huddledmasses.org/powerboots-tutorial-walkthrough/</link>
		<comments>http://huddledmasses.org/powerboots-tutorial-walkthrough/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 16:21:13 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerTips]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WalkThrough]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=963</guid>
		<description><![CDATA[	[new] Updated to PowerBoots 0.1

	An introduction to PowerBoots

	Please excuse me if I start by just copying the basic ideas of the Shoes Tutorial, but I figured that since PowerBoots is inspired by Shoes, that was as good a place as any to start.  PowerBoots (or just &#8220;Boots&#8221;) is a PowerShell 2.0 module with functions [...]]]></description>
			<content:encoded><![CDATA[	<h3>[new] Updated to PowerBoots 0.1</h3>

	<h2>An introduction to PowerBoots</h2>

	<p>Please excuse me if I start by just copying the basic ideas of the <a href="http://shoooes.net/tutorial/">Shoes Tutorial</a>, but I figured that since PowerBoots is inspired by Shoes, that was as good a place as any to start.  PowerBoots (or just &#8220;Boots&#8221;) is a PowerShell 2.0 module with functions for writing Windows Presentation Framework (<span class="caps">WPF</span>) applications in the PowerShell scripting language.  You should get <a href="http://boots.CodePlex.com">the latest version of PowerBoots</a> before continuing, and install it by putting the &#8220;PowerBoots&#8221; folder in one of your &#8220;Modules&#8221; folders (list them by typing <code>$Env:PSMODULEPATH</code> in PowerShell v2). </p>

	<p><del>Don&#8217;t forget to start PowerShell.exe with the <span class="caps">STA</span> parameter</del> (This is no longer required in PowerBoots 0.1).</p>

	<p>Did I hear someone ask <strong>what <em>is</em> WPF?</strong> It was introduced as part of .Net 3.0 (and vastly improved in .Net 3.5), so you can expect to find it preinstalled on computers from Vista on, and of course you can download and install it on XP if it&#8217;s not already installed.  The only thing you really need to know about <span class="caps">WPF</span> for the purposes of this tutorial is that it is <strong>the</strong> new <span class="caps">GUI</span> toolkit for .Net, and that it is container based &#8212; you put elements into other elements to control the layout, rather like <span class="caps">HTML</span> and Java Swing&#8230; you can <strong>pick up the rest as we go along</strong>.</p>

	<h2>A simple Boots program</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots1.png" class="float-right-block" alt="" width="144" height="86" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #000066;">-SizeToContent</span> WidthAndHeight <span style="color: #000066;">-Content</span> <span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp;Button <span style="color: #000066;">-Content</span> <span style="color: #009900;">&quot;Push Me&quot;</span> <br />
<span style="color: #333;">&#41;</span><br />
<br />
&nbsp;</div>

	<p>The parenthesis ( and ) are a container, so the button is &#8220;in&#8221; the Window.  You can also pass a ScriptBlock instead, which works basically the same way. Of course, this is a bit uglier than the Shoes syntax, so lets see if we can&#8217;t clean it up some. The <code>-Content</code> parameter is positional, so the first non-named argument you pass will be used for that. The same is true for the -Children parameter of panels, and in fact, each of the other similar parameters: Items, Blocks, and Inlines.</p>

	<p>We have used a function <code>New-BootsWindow</code> which has an alias <code>Boots</code>. Boots takes all the same parameters as the <code>Window</code> function mentioned previously, but it uses slightly more useful defaults, and has a few other major benefits as well, the first of which is that it automatically &#8220;shows&#8221; the window, and the second is that it supports an <code>-Async</code> parameter which allows the window to come out in a new thread so that you can continue using PowerShell while the window remains alive and responsive.  There is one catch: New-BootsWindow <em>cannot</em> take it&#8217;s content on the pipeline (the <em>old function</em>, now renamed &#8220;Out-BootsWindow&#8221; can take pipeline content, but is a script function, and requires -<span class="caps">STA</span> mode) &#8212; you have to specify it as a ScriptBlock. So now that we know this, we can rewrite our first example like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> Button <span style="color: #000066;">-Content</span> <span style="color: #009900;">&quot;Push Me&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Just for the record, the simplest Boots program would just be a simple popup dialog to put some text in a Window, like:  <code>Boots { $msg }</code> &#8230;</p>

	<h2>We can put controls in a stack</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots2.png" class="float-right-block" alt="" width="156" height="128" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A bed of clams&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A gulp of swallows&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>StackPanels are awesome. So are WrapPanels.  Try that code with a WrapPanel instead of a StackPanel and see what the difference is.  This brings up another point: those positional parameters we mentioned earlier: Content, Children, Items, Blocks, and Inlines, are also set to accept the value from the pipeline.  Not only that, but they are intelligent about whether or not the content model accepts multiple items! So we can actually rewrite that script like this, and get the same results:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span>, <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span>, <span style="color: #009900;">&quot;A gulp of swallows&quot;</span> <span style="color: #66cc66;">|</span> Button <span style="color: #66cc66;">|</span> StackPanel <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Now we&#8217;re really onto something! <span id="more-963"></span> For most of the rest of these examples, I&#8217;m going to stick with the former syntax, because with the indenting and parenthesis, it&#8217;s much easier for you to follow, especially if you&#8217;re not already familiar with <span class="caps">WPF</span>.  For instance, check out what this does:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span>, <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span>, <span style="color: #009900;">&quot;A gulp of swallows&quot;</span> <span style="color: #66cc66;">|</span> StackPanel <span style="color: #66cc66;">|</span> Button <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<h2>Ok, lets see some formatting</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots3.png" class="float-right-block" alt="" width="174" height="152" /></p>

	<p>To scoot the buttons out from the edge we can use margins or padding: margins go on the outside of containers, padding goes on the inside.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Background</span> Pink $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&quot;A gulp of swallows&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Or, on one line:</span><br />
<br />
Boots <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;A bed of clams&quot;</span>, <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span>, <span style="color: #009900;">&quot;A gulp of swallows&quot;</span> <span style="color: #66cc66;">|</span><br />
&nbsp; &nbsp;Button <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">2</span> <span style="color: #66cc66;">|</span> StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Background</span> Pink <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>So you see, the pink background is on the StackPanel, which has a (white) margin around it.  If you wanted the whole background of the window to be pink, you would need to set the background of the Window instead of the StackPanel.</p>

	<h2>Time for some artwork</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots4.png" class="float-right-block" alt="" width="176" height="164" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> Ellipse <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">60</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">80</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">&quot;20,10,60,20&quot;</span> <span style="color: #000066;">-Fill</span> Black <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>In Boots, everything always starts out white, and you must position things based on the container. You can see that the Margin can be specified as a single value as in the previous example, or as separate values for Left, Top, Right, Bottom.  Oddly, to satisfy PowerShell&#8217;s type-casting, you have to quote them so they&#8217;re a single comma-separated string, instead of four separate values.</p>

	<h2>Some more advanced drawing</h2>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots5.png" class="float-right-block" alt="" width="148" height="158" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
Canvas <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-Children</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;Rectangle <span style="color: #000066;">-Margin</span> <span style="color: #009900;">&quot;10,10,0,0&quot;</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">45</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">45</span> <span style="color: #000066;">-Stroke</span> Purple <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">2</span> <span style="color: #000066;">-Fill</span> Red<br />
&nbsp; &nbsp;Polygon <span style="color: #000066;">-Stroke</span> Pink <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">2</span> <span style="color: #000066;">-Fill</span> DarkRed <span style="color: #000066;">-Points</span> <span style="color: #009900;">&quot;10,60&quot;</span>, <span style="color: #009900;">&quot;50,60&quot;</span>, <span style="color: #009900;">&quot;50,50&quot;</span>, <span style="color: #009900;">&quot;65,65&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;50,80&quot;</span>, <span style="color: #009900;">&quot;50,70&quot;</span>, <span style="color: #009900;">&quot;10,70&quot;</span>, <span style="color: #009900;">&quot;10,60&quot;</span> <br />
<span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>We use a Canvas for this because it can contain multiple items which are all absolutely positioned.  Unlike other containers, it doesn&#8217;t automatically expand to contain it&#8217;s children, so you typically have to set it&#8217;s size.</p>

	<p>We also have to set the Stroke and Fill.  These are the two colors that make up every object, if we don&#8217;t set them, they default to white. The StrokeThickness controls the line thickness.  Notice that we positioned the Rectangle by using the <code>Margin</code>, and positioned the arrow, which we built using a Polygon, based purely on the x,y coordinates of the points.  The available shapes are Ellipse, Line, Path, Polygon, Polyline, and Rectangle.  You can, of course, make any shape you want to with the Polygon.</p>

	<p>There are other more advanced shapes available in external libraries, and we can even do 3D, use gradient or image fills&#8230;</p>

	<h3>We can even get images straight off the web</h3>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;Image <span style="color: #000066;">-Source</span> http:<span style="color: #66cc66;">//</span>www.<span style="color: #003366;">powerisers</span>.<span style="color: #003366;">de</span><span style="color: #66cc66;">/</span>download<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">855</span><span style="color: #66cc66;">/</span>IMG_3298.<span style="color: #003366;">jpg</span> <span style="color: #000066;">-MaxWidth</span> <span style="color: #cc66cc;">400</span> <span style="color: #66cc66;">|</span> <br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Title</span> <span style="color: #009900;">&quot;Now those are some powerful boots!&quot;</span> <span style="color: #000066;">-Async</span><br />
&nbsp;</div>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots6.png" class="float-right-block" alt="" width="436" height="730" /></p>

	<p>Boots loads the image on a background thread, and caches it in memory, so the window will show up and be responsive while you&#8217;re waiting for the image, and because we&#8217;ve specified <code>-Async</code>, you can actually continue using PowerShell while the image loads. Note: it will load much faster the second time you run that script. <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<h3 style="clear: both;">Typography</h3>

	<p>PowerBoots doesn&#8217;t try to create a full set of typography-specific top-level elements the way Shoes does, because we are based on <span class="caps">WPF</span>, which has a far more powerful typography system available than any we&#8217;ve ever used.  So instead of having a bunch of named elements like banner, and title, and caption, and para and whatnot, we have controls based on how much text you want to put in them, and how much formatting you want to apply: Label is simplest, TextBlock supports limited text formattings, and FlowDocument supports full rich content. And of course, Hyperlink supports clicking <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots7.png" class="float-right-block" alt="" width="466" height="202" /></p>

	<p>For the typography elements, the content model changes a bit.  There are basically two types: Inline and Block elements. The <a href="http://msdn.microsoft.com/en-us/library/bb613554.aspx">TextBlock Content Model</a> is similar to that of a FlowDocument, it is actually a type-restricted &#8220;Items&#8221; container.  Instead of being able to have <em>anything</em> as content, it can only contain <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.inline.aspx">Inline</a> flow content elements such as <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.anchoredblock.aspx">AnchoredBlock</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.bold.aspx">Bold</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.hyperlink.aspx">Hyperlink</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.inlineuicontainer.aspx">InlineUIContainer</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.italic.aspx">Italic</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.linebreak.aspx">LineBreak</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.run.aspx">Run</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.span.aspx">Span</a>, and <a href="http://msdn.microsoft.com/en-us/library/system.windows.documents.underline.aspx">Underline</a>, and it will create a run automatically if you just put a text string in it. </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">10</span> <span style="color: #000066;">-Children</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #009900;">&quot;A Question&quot;</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">42</span> <span style="color: #000066;">-FontWeight</span> Bold <span style="color: #000066;">-Foreground</span> <span style="color: #009900;">&quot;#FF0088&quot;</span> <br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-Inlines</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Bold <span style="color: #009900;">&quot;Q. &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;Are you starting to dig &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Hyperlink <span style="color: #009900;">&quot;PowerBoots?&quot;</span> <span style="color: #000066;">-NavigateUri</span> http:<span style="color: #66cc66;">//</span>huddledmasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span>tag<span style="color: #66cc66;">/</span>powerboots<span style="color: #66cc66;">/</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-On_RequestNavigate</span> <span style="color: #333;">&#123;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Diagnostics.<span style="color: #666699; font-weight: bold;">Process</span><span style="color: #333;">&#93;</span></span>::<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">NavigateUri</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">16</span> <span style="color: #000066;">-Inlines</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Span <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-FontWeight</span> Bold <span style="color: #000066;">-Inlines</span> <span style="color: #009900;">&quot;A. &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;Leave me alone, I'm hacking here!&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Note: If you want support for the full <a href="http://msdn.microsoft.com/en-us/library/aa970909.aspx">document model</a> (which allows Paragraphs and Lists), you need to use a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentreader.aspx">FlowDocumentReader</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentpageviewer.aspx">FlowDocumentPageViewer</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.richtextbox.aspx">RichTextBox</a>, or a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.flowdocumentscrollviewer.aspx">FlowDocumentScrollViewer</a> ... there&#8217;s lots more information about those <a href="http://msdn.microsoft.com/en-us/library/aa970909.aspx">on msdn</a>.</p>

	<h3>Events</h3>

	<p>If you were paying attention to that previous example, you&#8217;ll notice we just introduced event handling. Event handlers in PowerBoots are specified in much the same way that Properties are.  Their parameter names always start with &#8220;On_&#8221; and they take a script block.  The Hyperlink element in a <span class="caps">WPF</span> window doesn&#8217;t automatically open a browser (because you can use it to change &#8220;pages&#8221; in a <span class="caps">WPF</span> application), so to make simple web links work, you have to handle the &#8220;RequestNavigate&#8221; event as shown above.</p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots8.png" class="float-right-block" alt="" width="202" height="76" /></p>

	<p>In order to update your user interface when an event triggers, you&#8217;ll need to have a variable that points at the control(s) you want to affect.  You get a <code>$this</code> variable for free which points at the object that caused the event (eg: the Hyperlink in our previous example), but otherwise you need to handle this yourself. You can do that one of two ways: you can set a variable the way you normally would, and then use the variable in the form, or you can specify the variable name using the <code>-OutVariable</code> parameter.  Personally I prefer the latter, as it messes up the flow of code less, but it has the downside that the output variable is always an array, even when there&#8217;s only one item.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$global</span>:Count <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span><br />
&nbsp; &nbsp;WrapPanel &nbsp;$<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;Push Me&quot;</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$global</span>:Count<span style="color: #66cc66;">++</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$label</span>.<span style="color: #003366;">Content</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;You clicked the button ${global:Count} times!&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$script</span>:label <span style="color: #66cc66;">=</span> Label <span style="color: #009900;">&quot;Nothing pushed so far&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$label</span> <span style="color: #666666; font-style: italic;"># You have to actually write-output the label</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Title</span> <span style="color: #009900;">&quot;Test App&quot;</span> <span style="color: #000066;">-On_Closing</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$global</span>:BootsOutput <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$global</span>:Count; <span style="color: #660033;">rm</span> variable:Count <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>I&#8217;ve made these examples slightly more complicated than they had to be to demonstrate some best practices.  When the Window is closed, the Out-Boots function returns the $BootsOutput variable &#8212; so if you want to <strong>output</strong> something from your gui, you need to set that variable.  You can, of course, access global scope variables using the scope prefix <code>$global:variableName</code>, so you can set many different variables which you read later in your script.  The catch is, sometimes the variables <em>have</em> to be explicitly set to script or even global scope in order to refer to the same variable in all of the event handlers&#8230;</p>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots9.png" class="float-right-block" alt="" width="260" height="84" /></p>

	<p>However, if you want to have this block of code actually <strong>output</strong> something into the pipeline, you&#8217;ll always want to use the <code>$BootsOutput</code> variable.  You can do that directly, the way the example above does, or you can simply use Write-Output! Inside the Out-Boots function, he Write-Output cmdlet just appends to the $BootsOutput variable &#8230; so it works pretty much exactly the way you would expect it to.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;WrapPanel <span style="color: #000066;">-On_Load</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Count</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">0</span> <span style="color: #333;">&#125;</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;Push Me&quot;</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #333;">&#40;</span><span style="color: #66cc66;">++</span><span style="color: #660033; font-weight: bold;">$count</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># You have to use array notation ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$block</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Inlines</span>.<span style="color: #660033;">Clear</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$block</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Inlines</span>.<span style="color: #003366;">Add</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;You clicked the button $count times!&quot;</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; TextBlock <span style="color: #009900;">&quot;Nothing pushed so far&quot;</span> <span style="color: #000066;">-OutVariable</span> script:block <span style="color: #000066;">-VerticalAlignment</span> Center<br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>The first example outputs <strong>just</strong> the count of how many times you clicked.  The second outputs a series of numbers from 1 to however many times you click.  It&#8217;s your choice of how to work with it.</p>

	<h3>We can have fun with colors</h3>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots10.png" class="float-right-block" alt="" width="318" height="286" /></p>

	<p>Boots gives you access to all the capabilities of the Windows Presentation Framework, but in some cases that comes at a cost, because we haven&#8217;t simplified their composability.  So we have RadialGradientBrush and LinearGradientBrush, but you have to specify the GradientStops etc &#8230;</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #000066;">-Background</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp;RadialGradientBrush $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; GradientStop <span style="color: #000066;">-Offset</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Color</span> <span style="color: #009900;">&quot;#F00&quot;</span><br />
&nbsp; &nbsp; &nbsp; GradientStop <span style="color: #000066;">-Offset</span> <span style="color: #cc66cc;">1</span> <span style="color: #000066;">-Color</span> <span style="color: #009900;">&quot;#F90&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;Label <span style="color: #009900;">&quot;Boots&quot;</span> <span style="color: #000066;">-HorizontalAlignment</span> Center `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-VerticalAlignment</span> Center `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-Foreground</span> White <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">80</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-FontWeight</span> Bold &nbsp;<span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">40</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>We also have</p>

	<h3>So what does an InputBox look like?</h3>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots11.png" class="float-right-block" title="PowerBoots11.png" alt="PowerBoots11.png" width="260" height="86" /></p>

	<p>Well, the simplest possible input box is just a TextBox, with the Width set (if you don&#8217;t set the Width, a TextBox will adjust to fit it&#8217;s contents, which can be really distracting).  All you need to do is this:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;TextBox <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">220</span> <br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Title</span> <span style="color: #009900;">&quot;Enter your name&quot;</span> <span style="color: #000066;">-On_Close</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Content</span>.<span style="color: #003366;">Text</span> <br />
<span style="color: #333;">&#125;</span> <br />
&nbsp;</div>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots12.png" class="float-right-block" title="PowerBoots12.png" alt="PowerBoots12.png" width="200" height="76" /></p>

	<p>Of course, the problem with that is that it pops up this rather confusing window, when what we really wanted was a prompt, and an &#8220;Ok&#8221; button, and some event handling to make the thing behave the way we expect it to.  So lets try our first complicated form. </p>

	<p>I&#8217;ll warn you ahead of time of one thing I&#8217;m going to do here. I&#8217;m using the &#8220;Border&#8221; element to apply a colored border to the StackPanel (because it doesn&#8217;t have it&#8217;s own border parameters), but then I&#8217;m also using the WindowStyle and AllowsTransparency properties to remove the normal window chrome, creating the bare little popup you see in the screenshot. I handle the mouse down event on the main window to allow the user to drag the window around by clicking anywhere on it (except in the TextBox or on the Button, of course). Now it looks slick, and &#8212;you know&#8212; it works!</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">BootsInput</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">Param</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Prompt</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Please enter your name:&quot;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Remove-<span style="font-style: normal;">Variable</span></span> textBox <span style="color: #000066;">-ErrorAction</span> SilentlyContinue<br />
&nbsp; &nbsp;Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; Border <span style="color: #000066;">-BorderThickness</span> <span style="color: #cc66cc;">4</span> <span style="color: #000066;">-BorderBrush</span> <span style="color: #009900;">&quot;#BE8&quot;</span> <span style="color: #000066;">-Background</span> <span style="color: #009900;">&quot;#EFC&quot;</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;StackPanel <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">10</span> &nbsp;$<span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Label <span style="color: #660033; font-weight: bold;">$Prompt</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StackPanel <span style="color: #000066;">-Orientation</span> Horizontal $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;TextBox <span style="color: #000066;">-OutVariable</span> global:textbox <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">150</span> <span style="color: #000066;">-On_KeyDown</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Key</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;Return&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Button <span style="color: #009900;">&quot;Ok&quot;</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">Close</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_Load</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$textbox</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Focus</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span> `<br />
&nbsp; &nbsp;<span style="color: #000066;">-WindowStyle</span> None <span style="color: #000066;">-AllowsTransparency</span> <span style="color: #660033; font-weight: bold;">$true</span> `<br />
&nbsp; &nbsp;<span style="color: #000066;">-On_PreviewMouseLeftButtonDown</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Source</span> <span style="color: #000066;">-notmatch</span> <span style="color: #009900;">&quot;.*\.(TextBox|Button)&quot;</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$BootsWindow</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Hopefully you can follow that, although it&#8217;s obviously over the top <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . We handle the KeyDown event on the TextBox (if the Key is the Return key), and we also handle the click on the Button.  In both cases, we&#8217;ll write out the text that was entered, and use the special $BootsWindow variable to close the window.  We also handle the Load event for the window, to make sure the focus is on the TextBox, so you can just start typing.</p>

	<h3>A final example</h3>

	<p><img src="http://huddledmasses.org/images/PowerBoots/PowerBoots13.png" class="float-right-block" title="PowerBoots13.png" alt="PowerBoots13.png" width="248" height="740" /></p>

	<p>I&#8217;ve got quite a few more examples I want to show off in part two of this tutorial, but to get you thinking about ways to integrate this with your routine tasks, and give you some ideas of what you can do with what you know already, let me give you this example of browsing photos, with a visual indication of how big the image file is. Of course, the point is that you could be visualizing, you know &#8230; anything.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">add-<span style="font-style: normal;">type</span></span> <span style="color: #000066;">-Assembly</span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Forms</span> &nbsp;<span style="color: #666666; font-style: italic;"># To get the Double-Click time</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">GraphLabel</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #333;">&#91;</span>CmdletBinding<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PARAM</span> <span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">String</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Label</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Name&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">String</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Value</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Length&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">2</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$DoubleClickAction</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$null</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$max</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$null</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$width</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">200</span>, <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">double</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$margin</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">2</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">Int</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$DoubleClickTime</span> <span style="color: #66cc66;">=</span> $<span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Forms</span>.<span style="color: #003366;">SystemInformation</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">DoubleClickTime</span><span style="color: #333;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>ValueFromPipeline<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#91;</span>Alias<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;IO&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">PSObject</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$InputObject</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">BEGIN</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$maxx</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$max</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$maxx</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$maxx</span><span style="color: #66cc66;">=</span>@<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #660033; font-weight: bold;">$Value</span> <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$io</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #660033; font-weight: bold;">$InputObject</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## This is the core part of the script ...</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## For each input, generate a grid panel with a label and a rectangle in the background</span><br />
&nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GridPanel <span style="color: #000066;">-tag</span> @<span style="color: #333;">&#123;</span>item<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$io</span>; action<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$DoubleClickAction</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-width</span> <span style="color: #660033; font-weight: bold;">$Width</span> <span style="color: #000066;">-margin</span> <span style="color: #660033; font-weight: bold;">$margin</span> $<span style="color: #333;">&#40;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Label <span style="color: #660033; font-weight: bold;">$io</span>.<span style="color: #660033; font-weight: bold;">$Label</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Rectangle <span style="color: #000066;">-HorizontalAlignment</span> Left <span style="color: #000066;">-Fill</span> <span style="color: #009900;">&quot;#9F00&quot;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Width</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Width</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$io</span>.<span style="color: #009900;">&quot;$Value&quot;</span> <span style="color: #66cc66;">/</span> <span style="color: #660033; font-weight: bold;">$maxx</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#41;</span> <span style="color: #000066;">-On_MouseLeftButtonDown</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">Action</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <span style="color: #666666; font-style: italic;"># They passed in a doubleclick action, so lets handle it</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$global</span>:ClickTime <span style="color: #000066;">-and</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>DateTime<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Now</span> <span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$ClickTime</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">TotalMilliseconds</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$global</span>:DoubleClickTime<span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># We invoke the scriptblock </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># and pass it the original input object </span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># and the grid panel object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&amp;</span><span style="color: #660033; font-weight: bold;">$This</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">Action</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">Item</span> <span style="color: #660033; font-weight: bold;">$this</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$global</span>:ClickTime <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>DateTime<span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Now</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Alias</span></span> GraphLabel <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">GraphLabel</span></span><br />
<br />
<span style="color: #666666; font-style: italic;">## Example 1: list of processes with most RAM usage</span><br />
<span style="color: #666666; font-style: italic;">## DoubleClickAction is `kill`</span><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033;">ps</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">sort</span> PM <span style="color: #000066;">-Desc</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> <span style="color: #000066;">-First</span> <span style="color: #cc66cc;">20</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; &nbsp; GraphLabel ProcessName PM <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033;">Kill</span> <span style="color: #660033; font-weight: bold;">$Args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Id</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$global</span>:panel<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Children</span>.<span style="color: #003366;">Remove</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;StackPanel <span style="color: #000066;">-ov</span> global:panel<br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #666666; font-style: italic;">## Example 2: list of images, with file size indicated</span><br />
<span style="color: #666666; font-style: italic;">## DoubleClickAction is `open`</span><br />
Boots <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033;">ls</span> ~<span style="color: #66cc66;">/</span>Pictures<span style="color: #66cc66;">/</span> <span style="color: #000066;">-recurse</span> <span style="color: #000066;">-Include</span> <span style="color: #66cc66;">*</span>.<span style="color: #003366;">jpg</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Sort</span> Length <span style="color: #000066;">-Desc</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #66cc66;">!</span><span style="color: #660033; font-weight: bold;">$Max</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$Max</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Length</span><span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; StackPanel <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">200</span> <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">5</span> $<span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Image <span style="color: #000066;">-Source</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">FullName</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GraphLabel Name Length <span style="color: #000066;">-Max</span> <span style="color: #660033; font-weight: bold;">$Max</span> <span style="color: #000066;">-IO</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Diagnostics.<span style="color: #666699; font-weight: bold;">Process</span><span style="color: #333;">&#93;</span></span>::<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$args</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">FullName</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#41;</span> <br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> WrapPanel <br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">800</span><br />
&nbsp;</div>

	<p>Notice that I had to manually handle the concept of a double click, because StackPanels don&#8217;t have a Click or DoubleClick event, just MouseDown and MouseUp.  I could have stuck the stackpanel into something that does, but there&#8217;s really no need.  Also, the <code>[Diagnostics.Process]::Start</code> is the equivalent of typing the name into the run dialog.  I&#8217;m just <em>executing</em> the jpg, which makes it open in the default editor.  It&#8217;s just a sample, after all.</p>

	<h3>End note</h3>

	<p>The current version of Boots does not add threading support, which means that when you run something through Boots, execution of your script stops until the window is closed.  You can get around this somewhat in <a href="http://huddledmasses.org/wpf-from-powershell-updating-windows/">various different ways</a>, but future releases <em>will</em> support running the <span class="caps">WPF</span> window in a separate thread, and even communicating to it &#8230; at the expense of a slightly different syntax. If you need that functionality, feel free to let me know &#8230; I could use some motivation.</p>

	<p>I hope you&#8217;ve enjoyed this tour through PowerBoots, and will be able to start applying it for fun and profit.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powerboots-tutorial-walkthrough/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>PowerShell April Fools Pranks</title>
		<link>http://huddledmasses.org/powershell-april-fools-pranks/</link>
		<comments>http://huddledmasses.org/powershell-april-fools-pranks/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 14:37:39 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1152</guid>
		<description><![CDATA[	Harmless

	1..100&#124;%&#123;&#34;`a&#34;&#125;

	Awesome, and mostly harmless (2.0 only)

	$SWA = Add-Type -M '
[DllImport(&#34;user32&#34;,EntryPoint=&#34;ShowWindowAsync&#34;)]
public static extern bool S(IntPtr h, int i);' -name SWA -pass
ps &#124; ?&#123; $pid -eq $_.Id &#125; &#124; % &#123; $SWA::S&#40;$_.MainWindowHandle,0&#41; &#125;

while &#40;$true&#41; &#123;
&#160; &#160;$handles = ps &#124; %&#123; if&#40;&#91;int&#93;$_.MainWindowHandle&#41;&#123;$_.MainWindowHandle&#125; &#125;
&#160; &#160;$handles &#124; %&#123; $SWA::S&#40;$_,0&#41; &#125; &#160;# hide all windows
&#160; &#160;Sleep 5 &#160; &#160; &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[	<h3>Harmless</h3>

	<div class="posh code posh" style="font-family:monospace;">1..100<span style="color: #66cc66;">|%</span><span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">`a</span>&quot;</span><span style="color: #333;">&#125;</span></div>

	<h3>Awesome, and mostly harmless (2.0 only)</h3>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #660033; font-weight: bold;">$SWA</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Type</span></span> <span style="color: #000066;">-M</span> <span style="color: #009900;">'<br />
[DllImport(&quot;user32&quot;,EntryPoint=&quot;ShowWindowAsync&quot;)]<br />
public static extern bool S(IntPtr h, int i);'</span> <span style="color: #000066;">-name</span> SWA <span style="color: #000066;">-pass</span><br />
<span style="color: #660033;">ps</span> <span style="color: #66cc66;">|</span> ?<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$pid</span> <span style="color: #000066;">-eq</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Id</span> <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$SWA</span>::<span style="color: #003366;">S</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">MainWindowHandle</span>,<span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666699; font-weight: bold;">while</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$handles</span> <span style="color: #66cc66;">=</span> <span style="color: #660033;">ps</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span><span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">int</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">MainWindowHandle</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">MainWindowHandle</span><span style="color: #333;">&#125;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$handles</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span><span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$SWA</span>::<span style="color: #003366;">S</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>,<span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span> &nbsp;<span style="color: #666666; font-style: italic;"># hide all windows</span><br />
&nbsp; &nbsp;<span style="color: #660033;">Sleep</span> <span style="color: #cc66cc;">5</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># for five seconds</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$handles</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span><span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$SWA</span>::<span style="color: #003366;">S</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>,<span style="color: #cc66cc;">5</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span> &nbsp;<span style="color: #666666; font-style: italic;"># and unhide them</span><br />
&nbsp; &nbsp;<span style="color: #660033;">Sleep</span> <span style="color: #333;">&#40;</span><span style="color: #cc66cc;">60</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">5</span><span style="color: #333;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># every five minutes</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div><br />
<div class="posh code posh" style="font-family:monospace;">&nbsp;</div>

	<h3>Very Annoying</h3>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666699; font-weight: bold;">while</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><span style="color: #660033;">ps</span> <span style="color: #66cc66;">|</span> ?<span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">ID</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$PID</span><span style="color: #333;">&#125;</span><span style="color: #66cc66;">|%</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">CloseMainWindow</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span></div>

	<h3>Cute. Harmless. Requires PoshWpf (PowerBoots 0.1)</h3>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">## Preload PowerBoots:</span><br />
<span style="color: #666666; font-style: italic;">#imo PowerBoots</span><br />
<span style="color: #666666; font-style: italic;">## OR</span><br />
<span style="color: #666666; font-style: italic;">#Add-PsSnapin PoshWpf</span><br />
<span style="color: #666666; font-style: italic;">## And THEN:</span><br />
<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Reflection.<span style="color: #003366;">Assembly</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">LoadWithPartialName</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;System.Windows.Forms&quot;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">BootsWindow</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Window</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$W</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">ActualWidth</span> &nbsp;<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$H</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">ActualHeight</span> <span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$tickover</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$X</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Left</span> <span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">ActualWidth</span> &nbsp;<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> <span style="color: #666666; font-style: italic;">#$W</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Y</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Top</span> &nbsp;<span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">ActualHeight</span> <span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span> <span style="color: #666666; font-style: italic;">#$H</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$dX</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Forms</span>.<span style="color: #003366;">Cursor</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Position</span>.<span style="color: #003366;">X</span> <span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$X</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$dY</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Forms</span>.<span style="color: #003366;">Cursor</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Position</span>.<span style="color: #003366;">Y</span> <span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$Y</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">/</span> <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Left</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Left</span> <span style="color: #66cc66;">+</span> <span style="color: #660033; font-weight: bold;">$dX</span> <span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">ActualWidth</span> &nbsp;<span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Top</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Top</span> &nbsp;<span style="color: #66cc66;">+</span> <span style="color: #660033; font-weight: bold;">$dY</span> <span style="color: #66cc66;">-</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">ActualHeight</span> <span style="color: #66cc66;">/</span><span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Make a timer</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Threading</span>.<span style="color: #003366;">DispatcherTimer</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;00:00:00.1&quot;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">tag</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Window</span>,<span style="color: #660033; font-weight: bold;">$image</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Stick the timer into the window....</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$window</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$timer</span>, <span style="color: #660033; font-weight: bold;">$tickover</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">Add_Tick</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$tickover</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Make an image</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$image</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> <span style="color: #003366; font-weight: bold;">System</span>.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Controls</span>.<span style="color: #003366;">Image</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$image</span>.<span style="color: #003366;">Source</span> &nbsp; <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;http://www.clker.com/cliparts/c/1/b/6/1216306562167833124lemmling_Cartoon_ghost.svg.med.png&quot;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$image</span>.<span style="color: #003366;">Width</span> &nbsp; &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">75</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #003366;">tag</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Window</span>,<span style="color: #660033; font-weight: bold;">$image</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$timer</span>.<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">return</span> <span style="color: #660033; font-weight: bold;">$image</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_ContentRendered</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Debug</span></span> <span style="color: #009900;">&quot;Content Rendered. Tag: $($this.tag[0])&quot;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_Closing</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Debug</span></span> <span style="color: #009900;">&quot;Window Closing. Tag: $($this.tag[0])&quot;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Remove_Tick</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">Stop</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-WindowStyle</span> <span style="color: #009900;">&quot;none&quot;</span> <span style="color: #000066;">-AllowsTransparency</span> <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #000066;">-background</span> Transparent <span style="color: #000066;">-Async</span> <span style="color: #000066;">-TopMost</span> <span style="color: #660033; font-weight: bold;">$True</span></div>

	<h3>Harmless. Awesome. Requires PowerBoots and HttpRest</h3>

	<div class="posh code posh" style="font-family:monospace;">563..1<span style="color: #66cc66;">|%</span><span style="color: #333;">&#123;</span>boots<span style="color: #333;">&#123;</span>image<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">invoke-<span style="font-style: normal;">http</span></span> get http:<span style="color: #66cc66;">//</span>xkcd.<span style="color: #003366;">com</span><span style="color: #66cc66;">/</span><span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #66cc66;">|</span><span style="color: #0066cc; font-style: italic;">receive-<span style="font-style: normal;">http</span></span> text <span style="color: #66cc66;">//*</span><span style="color: #333;">&#91;</span>@title<span style="color: #333;">&#93;</span><span style="color: #66cc66;">/</span>@src<span style="color: #333;">&#125;</span> <span style="color: #000066;">-MaxWidth</span> <span style="color: #cc66cc;">800</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-async</span><span style="color: #333;">&#125;</span></div>

	<p>Dig that. I even put the xkcd comics in order for you. So as you go through and close all 563 <span class="caps">WPF</span> windows, you get to read all the xckd comics, and you can tell your boss it was someone&#8217;s idea of an April Fool&#8217;s prank.</p>

	<h3>Surprisingly Deceptive</h3>

	<h4>@Jaykul Wahoo! I made MVP!</h4>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-april-fools-pranks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
