<?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 &#187; Tutorial</title>
	<atom:link href="http://joelbennett.net/tag/tutorial/feed/" rel="self" type="application/rss+xml" />
	<link>http://joelbennett.net</link>
	<description>The internet home of Joel "Jaykul" Bennett...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='joelbennett.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>ShowUI: the tutorial walkthrough</title>
		<link>http://joelbennett.net/showui-tutorial-walkthrough/</link>
		<comments>http://joelbennett.net/showui-tutorial-walkthrough/#comments</comments>
		<pubDate>Wed, 15 Jun 2011 04:44:07 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerBoots]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ShowUI]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[UserInterface]]></category>
		<category><![CDATA[WalkThrough]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1679</guid>
		<description><![CDATA[Ok, let&#8217;s be clear: you&#8217;ve seen this before, and this isn&#8217;t going to be the last you&#8217;ll see of it, because we&#8217;ve got much more in store in ShowUI, but for the first release of ShowUI, it&#8217;s obviously time to update this simple walkthrough of building simple user interfaces in PowerShell! An introduction to ShowUI [...]]]></description>
			<content:encoded><![CDATA[	<p>Ok, let&#8217;s be clear: you&#8217;ve seen this <a href="/powerboots-tutorial-walkthrough">before</a>, and this isn&#8217;t going to be the last you&#8217;ll see of it, because we&#8217;ve got much more in store in <a href="http://showui.codeplex.com">ShowUI</a>, but for the first release of ShowUI, it&#8217;s obviously time to update this simple walkthrough of building simple user interfaces in PowerShell!</p>

	<h2>An introduction to ShowUI</h2>

	<p>ShowUI is the next generation PowerShell module for building user interfaces in script. It&#8217;s the merger of my previous PowerShell UI project (called PowerBoots) with one by James Brundage, former Microsoft PowerShell team member and founder of <a href="http://start-automating.com">Start-Automating</a> (called <span class="caps">WPK</span>) which shipped in the Windows 7 resource kit.</p>

	<h4>If you want to follow along, you need to:</h4>

	<p>1. Get a copy of the <a href="http://showui.codeplex.com/releases/">ShowUI Module</a> from CodePlex <br />
2. Install it by putting the &#8220;ShowUI&#8221; folder in one of your &#8220;Modules&#8221; folders (list them by typing <code>$Env:PSMODULEPATH</code> in PowerShell v2, and feel free to create the one you want if it doesn&#8217;t exist). You should end up with something like <code>C:\Users\Jaykul\Documents\WindowsPowerShell\Modules\ShowUI\ShowUI.psm1</code><br />
3. Run PowerShell <span class="caps">ISE</span>, or use PowerShell.exe with the -<span class="caps">STA</span> switch (the best way to do this is to add it to the shortcut you use to launch PowerShell: open the properties dialog, and on the Shortcut tab, add &#8220; -STA&#8221; to the Target)<sup class="footnote"><a href="#fn1">1</a></sup>.</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, and again in 4.0), 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 ShowUI program</h2>

	<p><img src="http://huddledmasses.org/images/ShowUI/ShowUI-01.png" class="float-right-block" alt="" width="167" height="85" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Button</span></span> <span style="color: #000066;">-Content</span> <span style="color: #009900;">&quot;Hello World&quot;</span> <span style="color: #000066;">-Show</span><br />
&nbsp;</div>

	<p>This first example is a little bit more verbose than it needs to be, because 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 content parameters: Items, Blocks, and Inlines.</p>

	<p>Additionally, each control is aliased without the New- verb, so you could just call <code>Button</code> instead of <code>New-Button</code> &#8230; and of course, since our button doesn&#8217;t do anything, we could just as easily have used a Label, and written:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Label <span style="color: #009900;">&quot;Hello World&quot;</span> <span style="color: #000066;">-Show</span><br />
&nbsp;</div>

	<p>Note: &#8220;Label&#8221; is also the name of an executable for labelling drives in Windows, make sure ShowUI is imported before you run that command.</p>

	<p>One last point: ShowUI brings a lot of features from <span class="caps">WPK</span> to the table, and one you&#8217;ll use a lot is the ability to skip specifying the window and put the -Show parameter on almost any <span class="caps">WPF</span> element. This is partly because we&#8217;re back to running PowerShell 2.0 with the -<span class="caps">STA</span> switch, but in any case, we can now skip the &#8220;New-BootsWindow&#8221; command, and our examples can be that much simpler.</p>

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

	<p><img src="http://huddledmasses.org/images/ShowUI/ShowUI-02.png" class="float-right-block" alt="" width="165" height="132" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Show-<span style="font-style: normal;">UI</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; StackPanel <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A bed of clams&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Button <span style="color: #009900;">&quot;A coalition of cheetas&quot;</span><br />
&nbsp; &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 (hint: try resizing the window). Actually, try it with a UniformGrid too. <span class="caps">WPF</span> has several other panel containers too: Grid, ToolBarPanel, TabPanel, DockPanel, Canvas &#8230; we&#8217;ll talk about some more of those later.</p>

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

	<p><img src="http://huddledmasses.org/images/ShowUI/ShowUI-03.png" class="float-right-block" alt="" width="256" height="179" /></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. We can also specify the FontFamily, FontSize, FontWeight, and FontStyle, as well as Foreground and Background colors &#8230; </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Show-<span style="font-style: normal;">UI</span></span> <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;">&#123;</span><br />
&nbsp; &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> <span style="color: #000066;">-FontFamily</span> Consolas <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">24</span> <span style="color: #000066;">-FontWeight</span> Bold<br />
&nbsp; &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> <span style="color: #000066;">-FontFamily</span> Arial <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">20</span> <span style="color: #000066;">-FontStyle</span> Italic<br />
&nbsp; &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> <span style="color: #000066;">-FontFamily</span> <span style="color: #009900;">'Segoe UI'</span> <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">18</span> <span style="color: #000066;">-Foreground</span> Crimson<br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>So you see, the pink background is on the StackPanel, which has a (default, 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>

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

	<p>ShowUI doesn&#8217;t need 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 used previously. So, with <span class="caps">WPF</span> we start by selecting a control based on how much text you want to put in it, and how much formatting you want to apply: Label and TextBox are the simplest, TextBlock supports limited text formattings, and FlowDocumentViewer or RichTextBox support full rich content. And of course, Hyperlink supports clicking  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';)' class='wp-smiley' />  </p>

	<p><img src="http://huddledmasses.org/images/ShowUI/ShowUI-07.png" class="float-right-block" alt="" width="507" height="186" /></p>

	<p>For the typography elements, the content model changes a little bit.  There are basically two types of typographical elements: Inline and Block elements (where inline elements can&#8217;t contain block elements). In fact, he <a href="http://msdn.microsoft.com/en-us/library/bb613554.aspx">TextBlock Content Model</a> is similar to that of an inline element. 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 />
<span style="color: #0066cc; font-style: italic;">Show-<span style="font-style: normal;">UI</span></span> <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;">&#123;</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;">&#123;</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;ShowUI?&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>showui<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: #003366;">ToString</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; &nbsp; <span style="color: #333;">&#125;</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;">&#123;</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;">&#125;</span><br />
<span style="color: #333;">&#125;</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>

	<h2>Time for some artwork</h2>

	<p><img src="http://huddledmasses.org/images/ShowUI/ShowUI-04.png" class="float-right-block" alt="" width="179" height="171" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
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: #000066;">-Show</span><br />
&nbsp;</div>

	<p>In <span class="caps">WPF</span>, 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/ShowUI/ShowUI-05.png" class="float-right-block" alt="" width="155" height="160" /></p>

	<div class="posh code posh" style="font-family:monospace;"><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;">&#123;</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> <span style="color: #009900;">&quot;#689945&quot;</span> <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">2</span> <span style="color: #000066;">-Fill</span> <span style="color: #009900;">&quot;#336699&quot;</span><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;">&#125;</span> <span style="color: #000066;">-Show</span><br />
&nbsp;</div>

	<p>When you want to start getting clever and overlapping things, you need to use a Canvas container. The Canvas can contain multiple items which are all absolutely positioned, but unlike most 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, and again, if we don&#8217;t set them, they default to white. Note that you can use named colors, or you can specify a hex value using &#8220;#RRGGBB&#8221; or &#8220;#AARRGGBB&#8221; to set the alpha channel. The StrokeThickness controls the line thickness.  </p>

	<p>One other thing to notice is that we positioned the Rectangle by using the <code>Margin</code>, but we 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 nearly any shape you want 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 />
&nbsp; &nbsp;Image <span style="color: #000066;">-Source</span> http:<span style="color: #66cc66;">//</span>huddledmasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span>images<span style="color: #66cc66;">/</span>PowerBoots<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: #000066;">-AsJob</span><br />
&nbsp;</div>

	<p><img src="http://huddledmasses.org/images/ShowUI/ShowUI-06.png" class="float-right-block" alt="" width="437" height="729" /></p>

	<p><span class="caps">WPF</span> 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>-AsJob</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://joelbennett.net/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>

	<h3>Events</h3>

	<p>If you were paying attention to the typography example, you&#8217;ll have noticed that we introduced event handling without making a big fuss about it. Event handlers in PowerBoots are specified in much the same way that Properties are, except that 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/ShowUI/ShowUI-08.png" class="float-right-block" alt="" width="259" height="86" /></p>

	<div class="posh code posh" style="font-family:monospace;"><br />
WrapPanel <span style="color: #000066;">-ControlName</span> <span style="color: #009900;">'Click Counter'</span> <span style="color: #333;">&#123;</span><br />
&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; $<span style="color: #333;">&#123;</span>Click Counter<span style="color: #333;">&#125;</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> $<span style="color: #333;">&#123;</span>Click Counter<span style="color: #333;">&#125;</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">+</span> <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$CountLabel</span>.<span style="color: #003366;">Content</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;You clicked the button $(${Click Counter}.Tag) times!&quot;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; Label <span style="color: #009900;">&quot;Nothing pushed so far&quot;</span> <span style="color: #000066;">-Name</span> CountLabel<br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Show</span><br />
&nbsp;</div>

	<p>In order to update your user interface when an event triggers, you&#8217;ll need to have variables that point at the control(s) you want to affect.  In ShowUI event handlers, you get a <code>$this</code> variable which points at the object that caused the event, a <code>$_</code> variable which is the event arguments, and a <code>$window</code> variable for the top-level window &#8230; you also get variables for each named control in your window.  </p>

	<p><span class="caps">WPF</span> Elements all have a <code>Tag</code> property which can be used to store any object, so as you can see in the previous example, you can use that to keep track of things &#8230; but more importantly, the value of the <code>Tag</code> on the top-level control will be output. In other words, when the window is closed, this example actually outputs to the PowerShell pipeline how many times you clicked the button.</p>

	<h3>Working with User Input</h3>

	<p>There are helper functions in ShowUI for working with that output value: <code>Set-UIValue</code> and <code>Get-UIValue</code>, and Get-UIValue is particularly helpful because if the control it&#8217;s called on has no value, it collects the values of all the child controls, so you can use it to output a whole form at once:</p>

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

	<p>I&#8217;ve made this example more complicated than it needed to be to demonstrate some best practices.  We could have made it much simpler by using a UniformGrid control instead of a GridControl, thus avoiding needing to set the -Row and -Column special parameters, but I wanted to show those to you anyway, and the form looks a lot better when the two columns can have different sizes:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
Grid <span style="color: #000066;">-ControlName</span> <span style="color: #009900;">'Your Information'</span> <span style="color: #000066;">-Columns</span> Auto,<span style="color: #66cc66;">*</span> <span style="color: #000066;">-Rows</span> <span style="color: #cc66cc;">7</span> <span style="color: #000066;">-MinHeight</span> <span style="color: #cc66cc;">200</span> <span style="color: #000066;">-MinWidth</span> <span style="color: #cc66cc;">250</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; Label <span style="color: #009900;">&quot;First Name&quot;</span><br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TextBox</span></span> <span style="color: #000066;">-Name</span> First <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">1</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; Label <span style="color: #009900;">&quot;Last Name&quot;</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">1</span> <br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TextBox</span></span> <span style="color: #000066;">-Name</span> Last <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">1</span> <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">1</span><br />
<br />
&nbsp; &nbsp; Label <span style="color: #009900;">&quot;Address&quot;</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">2</span><br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TextBox</span></span> <span style="color: #000066;">-Name</span> Address <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">2</span> <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">1</span><br />
<br />
&nbsp; &nbsp; Label <span style="color: #009900;">&quot;City&quot;</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">3</span> <br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TextBox</span></span> <span style="color: #000066;">-Name</span> City <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">3</span> <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">1</span><br />
<br />
&nbsp; &nbsp; Label <span style="color: #009900;">&quot;State&quot;</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">4</span><br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TextBox</span></span> <span style="color: #000066;">-Name</span> State <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">4</span> <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">1</span><br />
<br />
&nbsp; &nbsp; Label <span style="color: #009900;">&quot;Zip&quot;</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">5</span> <br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TextBox</span></span> <span style="color: #000066;">-Name</span> Zip <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">1</span><br />
<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Button</span></span> <span style="color: #009900;">&quot;OK&quot;</span> <span style="color: #000066;">-IsDefault</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ParentControl</span></span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">UIValue</span></span> <span style="color: #000066;">-PassThru</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Close-<span style="font-style: normal;">Control</span></span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">6</span> <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">1</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Show</span> <span style="color: #000066;">-On_Loaded</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$First</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;</div>

	<p>You&#8217;ll notice how easily I specified the width of the columns, but the <span class="caps">COUNT</span> of the rows in the Grid panel. If you provide an array of values, they&#8217;re converted to GridLengths, but if you provide just one, it&#8217;s treated as the count. You can make grid columnds and rows AUTOmatically size to their contents, and you can make them * width to make them take up any extra space.  You can even split the extra space by setting * on more than one column (and specify the proportion by using numbers, like: 1*, 2*).</p>

	<p>I should also point out that if you use MinHeight and MinWidth instead of the Height and Width values, your controls will be able to size up to fill space when the window is resized! Try that script with Width and Height instead and resize the window to see the difference.</p>

	<p>We used the Set-UIValue shortcut in this form, which brings up another point: when creating data forms, you only need to name the controls you want output from. Then you&#8217;ll be able to just call Set-UIValue on the parent to collect all the values from the controls and output them as a hashtable!</p>

	<p>Finally, remember your defaults: set the focus to something so the user doesn&#8217;t <span class="caps">HAVE</span> to click to get started, and set a button to -IsDefault with a On_Click handler so that when the user hits enter they can submit the form.</p>

	<h3>Further directions</h3>

	<p>There&#8217;s a lot more possible with ShowUI: we can use gradients for colors, create data templates and styles, and even make chromeless windows, but you have the basics for getting started already.</p>

	<p>This first release of ShowUI is still missing some features from both <span class="caps">WPK</span> and PowerBoots, but we&#8217;ll get to them as we progress.  For now we&#8217;d like to invite you to come <a href="http://showui.codeplex.com/releases/">download the latest release</a>, and <a href="http://showui.codeplex.com/workitem/list/basic">write up or vote up the features</a> that you want the most in the next version.  Keep an eye on the release page and on the discussions and we&#8217;ll be cranking out new releases on a monthly basis for now.</p>

	<p>I hope you&#8217;ve enjoyed this tour through ShowUI, and will be able to start applying it soon for fun and profit.</p>

	<p id="fn1" class="footnote"><sup>1</sup> The -<span class="caps">STA</span> switch is necessary because the .Net framework requires the <acronym title="Single Threaded Apartment">STA</acronym> threading model in order to do graphical user interfaces. PowerShell <span class="caps">ISE</span> doesn&#8217;t require it because unlike the PowerShell.exe command console (which is a Win32 native &#8220;console&#8221; application that hosts the .Net framework), PowerShell <span class="caps">ISE</span> is a .Net framework &#8220;graphical&#8221; application, and is therefore running in the <span class="caps">STA</span> model already.</p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/showui-tutorial-walkthrough/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>PowerBoots: The tutorial walkthrough</title>
		<link>http://joelbennett.net/powerboots-tutorial-walkthrough/</link>
		<comments>http://joelbennett.net/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[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> <img src='http://joelbennett.net/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  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;">&#123;</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;">&#125;</span><br />
&nbsp;</div>

	<p>I&#8217;ve recently <strong>changed</strong> this first example to pass a script block to the content instead of using parentheses, because although PowerBoots supports running in an <span class="caps">MTA</span> PowerShell host, the only UI-creation command that is MTA-safe is the New-BootsWindow command. All of the &#8220;new&#8221; functions must then be inside of a scriptblock which is passed to the New-BootsWindow cmdlet and executed on that <span class="caps">STA</span> thread. You can use parenthesis ( and ) as a container instead, but that requires the host to be in <span class="caps">STA</span> threading mode (run: PowerShell -<span class="caps">STA</span>) so the controls can be created:</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 />
&nbsp;</div>

	<p>This first example 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: #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>huddledmasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span>images<span style="color: #66cc66;">/</span>PowerBoots<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://joelbennett.net/wordpress/wp-includes/' 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://joelbennett.net/wordpress/wp-includes/' 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://joelbennett.net/wordpress/wp-includes/' 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> System.<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>System.<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://joelbennett.net/powerboots-tutorial-walkthrough/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>A guide to PowerShell&#8217;s Advanced Functions</title>
		<link>http://joelbennett.net/a-guide-to-advanced-functions/</link>
		<comments>http://joelbennett.net/a-guide-to-advanced-functions/#comments</comments>
		<pubDate>Tue, 03 Mar 2009 03:44:03 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Advanced Functions]]></category>
		<category><![CDATA[CTP3]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell 2]]></category>
		<category><![CDATA[PowerShell Functions]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[WalkThrough]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1116</guid>
		<description><![CDATA[Someone asked on the PowerShell Newsgroup about writing Advanced Functions, and specifically: looking for a &#8230; guide to putting together an advanced function that is visible and usable every time I start Powershell. By visible I mean that when I do a &#8216;get-command&#8217; I want my [advanced function]s to be listed alongside all the regular [...]]]></description>
			<content:encoded><![CDATA[	<p>Someone asked on the <a href="news://msnews.microsoft.com:119/microsoft.public.windows.powershell">PowerShell Newsgroup</a> about writing Advanced Functions, and specifically:</p>

	<blockquote>
		<p>looking for a &#8230; guide to putting together an advanced function that is visible and usable every time I start Powershell. By visible I mean that when I do a &#8216;get-command&#8217; I want my [advanced function]s to be listed alongside all the regular cmdlets. What makes that possible? ... what do I need to do to make that happen? Whats the difference between an [advanced function] and a module?</p>
	</blockquote>

	<p>There are lots of articles on the Microsoft <a href="http://blogs.msdn.com/powershell/">PowerShell team blog</a> about both topics, but it seems there&#8217;s not really been any sort of step-by-step written, so I posted this to the newsgroup, and since the person who asked the original question said he found it useful, I figured I&#8217;d share it here&#8230;</p>

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

	<h2>An Aside: Advanced Functions vs. Modules</h2>

	<p>Advanced functions and script modules are unrelated topics. A script module could have nothing but old PowerShell 1 -type functions, hypothetically, it could even not have any functions at all.  Advanced functions can be defined in a plain .ps1 script, in your profile, or by typing them in on the command-line, etc. The two things are essentially unrelated except for both being new features in PowerShell 2.0.</p>

	<h2>How To write an Advanced Function</h2>

	<h3>Step 1: Have something you want to do in a function.</h3>

	<p>I can&#8217;t emphasize enough how important it is that you should have a specific goal here. Writing a script for a specific purpose is much easier, because you don&#8217;t have to think about whether or not specific features are necessary, etc.</p>

	<p>For the purposes of this example, I want a function to start executables and return me the process object (so I can wait for it to finish, or whatever). I will call it Start-Process.</p>

	<h3>Step 2: Write a first step for the logic of your function. </h3>

	<p>Be sure to specify the parameters using the <code>function Name{Param(...)}</code> syntax rather than <code>function Name(...){}</code>, then you will be able to easily convert it to an advanced function by adding <code>[CmdletBinding()]</code> on the line right before the <code>Param</code> like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Process</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 />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$app</span>,<span style="color: #660033; font-weight: bold;">$params</span><span style="color: #333;">&#41;</span><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;">$param</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&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;">$app</span>, <span style="color: #660033; font-weight: bold;">$param</span> <span style="color: #333;">&#41;</span><br />
&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; <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;">$app</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<h3>Step 3: Start writing documentation and auto-help, including your parameters.</h3>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Process</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">################################################################</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Starts an application, with optional command-line parameters.</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter App</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The path to the application you want to start</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter Params</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The string consisting of all the parameters to pass to App</span><br />
<span style="color: #666666; font-style: italic;">################################################################</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 />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$app</span>,<span style="color: #660033; font-weight: bold;">$params</span><span style="color: #333;">&#41;</span><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;">$param</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&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;">$app</span>, <span style="color: #660033; font-weight: bold;">$param</span> <span style="color: #333;">&#41;</span><br />
&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; <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;">$app</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<h3>Step 4: Exploit advanced features by marking up your parameters.</h3>

	<p>In my case, I had a look at the signature of the start method by running <code>[Diagnostics.Process]::Start.OverloadDefinitions</code> and discovered that it can take credentials too.  So I wanted an <em>optional</em> credential parameter. I specified it without a <strong>position</strong>, and made it part of a non-default parameter set.</p>

	<p>I also wanted the <code>params</code> parameter to just take any additional parameters which I pass to the function, and pass them on to the process that I&#8217;m starting. </p>

	<p>Finally, I wanted the &#8220;App&#8221; parameter to be able to come from the pipeline. Specifically, I wanted to be able to pass the output of Get-Command or Get-ChildItem to it. In order to enable that, I defined an alias on it to the relevant properties of the objects which come from those two commands</p>

	<p>Hopefully you&#8217;re getting the idea of what&#8217;s possible here &#8230;</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Process</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666666; font-style: italic;">################################################################</span><br />
<span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Starts an application, with optional command-line parameters.</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter App</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The path to the application you want to start</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter Params</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;The string consisting of all the parameters to pass to App</span><br />
<span style="color: #666666; font-style: italic;">#.Parameter Credential</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;PSCredential containing valid login to &quot;run as&quot; another user.</span><br />
<span style="color: #666666; font-style: italic;">################################################################</span><br />
<span style="color: #333;">&#91;</span>CmdletBinding<span style="color: #333;">&#40;</span>DefaultParameterSetName<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;NoCreds&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><br />
&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>,Mandatory<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValueFromPipelineByPropertyName<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; <span style="color: #333;">&#91;</span>Alias<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;FullName&quot;</span>,<span style="color: #009900;">&quot;Path&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; <span style="color: #660033; font-weight: bold;">$app</span><br />
,<br />
&nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Mandatory<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span>,ParameterSetName<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;RunAs&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; <span style="color: #333;">&#91;</span>Alias<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;PSCredential&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Management</span>.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">PSCredential</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Credential</span><br />
,<br />
&nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">3</span>, Mandatory<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$false</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ValueFromRemainingArguments<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #333;">&#41;</span><br />
&nbsp; <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;">$params</span><br />
<span style="color: #333;">&#41;</span><br />
<br />
&nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$credential</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$cred</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$credential</span>.<span style="color: #003366;">GetNetworkCredential</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><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;">$params</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$app</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$<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: #333399; font-weight: bold; font-style: italic;">join</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot; &quot;</span>,<span style="color: #660033; font-weight: bold;">$params</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$cred</span>.<span style="color: #003366;">UserName</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$credential</span>.<span style="color: #003366;">Password</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$cred</span>.<span style="color: #003366;">Domain</span> <span style="color: #333;">&#41;</span><br />
&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; <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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$app</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$cred</span>.<span style="color: #003366;">UserName</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$credential</span>.<span style="color: #003366;">Password</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$cred</span>.<span style="color: #003366;">Domain</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&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; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$params</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&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><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$app</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;$<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: #333399; font-weight: bold; font-style: italic;">join</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot; &quot;</span>,<span style="color: #660033; font-weight: bold;">$params</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: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&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;">$app</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<h3>Bonus Step: Make the function be automatically defined</h3>

	<p>To be honest, there are a lot of ways to do this, here&#8217;s a few:</p>

	<h4>Option 1. Define it in your Profile.</h4>

	<p>Include the full text of the function in your Profile.ps1 script or Microsoft.PowerShell_profile.ps1 &#8230; just run <code>notepad $Profile</code> and paste the whole function in at the top, then save.</p>

	<h4>Option 2. Dot-source it in your Profile.</h4>

	<p>Save the function into a script file, e.g.: &#8220;StartProcessFunction.ps1&#8221; in your DocumentsWindowsPowerShell folder (next to your profile script) then put the line: <code>. StartProcessFunction.ps1</code> into your profile script to dot-source it. Using the dot causes the script to be loaded into the context as though you had put the contents of the script in, instead of the dot-source line. </p>

	<h4>Option 3. Import this function from a script file.  </h4>

	<p>This is basically the same as Option 2, except instead of &#8220;.&#8221; you can use <code>Import-Module</code>.  The Import-Module cmdlet, when used on a file with the .ps1 extension, is basically the same as dot-sourcing it, so there&#8217;s not a whole lot of benefit over dot-sourcing in this case.</p>

	<h4>Option 4. Put the function in a module.</h4>

	<p>You should <strong>only</strong> do this if you think <em>you might want to add additional functions</em> to the module. For instance, lets say you want to write a few other functions for working with process objects.  If you put them together in the same module (say: &#8220;ProcessUtility&#8221;) they can share script-scoped variables or private functions, and can be identified as being part of the same module using the <code>Get-Command -Module ProcessUtility</code> command. </p>

	<p>If you just have the single function, there&#8217;s really no point in changing it to a Module, but I&#8217;m not aware of any downside, either.</p>

	<h4>Option 4a. Make a module by just saving as a <code>.psm1</code></h4>

	<p>All you do is save the function into a module file, e.g.: &#8220;ProcessUtility.psm1&#8221; in your DocumentsWindowsPowerShell folder and then put the line: <code>Import-Module ProcessUtility.psm1</code> into your profile script.</p>

	<h4>Option 4b. Make a module folder.</h4>

	<p>This is by far the most extensible way to create modules. You paste the function into &#8220;ProcessUtility.psm1&#8221; and then save it into a folder &#8220;ProcessUtility&#8221; which must be created in one of your module folders. You can figure out where the module folders are by checking <code>$Env:PSMODULEPATH</code> &#8212; the normal spot is your DocumentsWindowsPowerShellModules. </p>

	<p>Once that&#8217;s done, you can import with the simpler command <code>Import-Module ProcessUtility</code> without any extension. </p>

	<p>The nice thing about creating the folder is that you can put any additional resources in that folder with it, and get at them using the <code>$PsScriptRoot</code> to define the folder. You can even add additional functions by putting them in separate files (which you can Import-Module from the main file, or you can define using a .psd1, but that&#8217;s <a href="http://huddledmasses.org/powershell-modules-metadata-and-mysteries/">another article</a>).</p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/a-guide-to-advanced-functions/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

