<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Huddled Masses</title>
	<atom:link href="http://huddledmasses.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Mon, 17 Jun 2013 02:26:54 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>A new way to zip and unzip in PowerShell 3 and .Net 4.5</title>
		<link>http://huddledmasses.org/a-new-way-to-zip-and-unzip-in-powershell-3-and-net-4-5/</link>
		<comments>http://huddledmasses.org/a-new-way-to-zip-and-unzip-in-powershell-3-and-net-4-5/#comments</comments>
		<pubDate>Tue, 11 Jun 2013 05:20:27 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Archive]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Zip]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1919</guid>
		<description><![CDATA[I&#8217;ve got an article coming about WPF 4.5 and what&#8217;s new there for ShowUI, but in the meantime I thought I&#8217;d share this little nugget I noticed today: System.IO.Compression.FileSystem.ZipFile. You can use that class and it&#8217;s buddy ZipArchive to do all sorts of zipping and unzipping tasks. In order to use these new classes, you ...<a class="post-readmore" href="http://huddledmasses.org/a-new-way-to-zip-and-unzip-in-powershell-3-and-net-4-5/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>I&#8217;ve got an article coming about <span class="caps">WPF</span> 4.5 and what&#8217;s new there for ShowUI, but in the meantime I thought I&#8217;d share this little nugget I noticed today: <a href="http://msdn.microsoft.com/en-us/library/system.io.compression.zipfile.aspx">System.IO.Compression.FileSystem.ZipFile</a>. You can use that class and it&#8217;s buddy <a href="http://msdn.microsoft.com/en-us/library/system.io.compression.ziparchive.aspx">ZipArchive</a> to do all sorts of zipping and unzipping tasks.</p>

	<p>In order to use these new classes, <strong>you have to use Add-Type to import the System.IO.Compression.FileSystem</strong> assembly. If you don&#8217;t understand that, don&#8217;t worry about it, just copy <em>the first line</em> of the examples below. You only have to do it once, so it might be worth sticking it in your profile (or in a module file with a couple of scripts) if you think you&#8217;ll do a lot of this sort of thing.</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Type</span></span> <span style="color: #000066;">-As</span> System.<span style="color: #003366;">IO</span>.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">FileSystem</span><br />
<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">ZipFile</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">CreateFromDirectory</span><span style="color: #333;">&#40;</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Split-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$Profile</span><span style="color: #333;">&#41;</span>, <span style="color: #009900;">&quot;WindowsPowerShell.zip&quot;</span>, <span style="color: #009900;">&quot;Optimal&quot;</span>, <span style="color: #660033; font-weight: bold;">$true</span> <span style="color: #333;">&#41;</span><br />
&nbsp;</div>

	<p>That&#8217;s basically a one-liner to zip up a folder.  Of course, you should have a one liner to unzip it too:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Type</span></span> <span style="color: #000066;">-As</span> System.<span style="color: #003366;">IO</span>.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">FileSystem</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$ZipFile</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Item</span></span> ~\Downloads\Wasp.<span style="color: #003366;">zip</span><br />
<span style="color: #660033; font-weight: bold;">$ModulePath</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Env</span>:PSModulePath <span style="color: #000066;">-split</span> <span style="color: #009900;">&quot;;&quot;</span> <span style="color: #000066;">-like</span> <span style="color: #009900;">&quot;$Home*&quot;</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> <span style="color: #000066;">-first</span> <span style="color: #cc66cc;">1</span><br />
<br />
<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">ZipFile</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">ExtractToDirectory</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$ZipFile</span>, <span style="color: #660033; font-weight: bold;">$ModulePath</span> <span style="color: #333;">&#41;</span><br />
&nbsp;</div>

	<p>In order for the second example to work the way you want it to, you need a zip file where all the files are in a single folder &#8212; which is why in the first example I used the overload for <code>CreateFromDirectory</code> which takes a boolean for whether or not to include the root directory in the zip as opposed to just it&#8217;s contents.  Otherwise, you would need to create the &#8220;WASP&#8221; folder, first, and then extract to that directory.  Of course, if you do that when there <strong>is</strong> a directory in the zip (as there was, in this case), you&#8217;ll end up with a Modules\WASP\<span class="caps">WASP</span> ... which in PS3 will work (although it shouldn&#8217;t), but is rather frustrating.</p>

	<p>So, to avoid ending up with folders inside folders, we can use the ZipArchive class. </p>

	<p>The easiest way to get an actual ZipArchive is to use the &#8220;Open&#8221; method on the ZipFile class. Once you&#8217;ve done that you can easily check all the files in it: <code>$archive.Entries | Format-Table</code> and you can extract a single entry using <a href="http://msdn.microsoft.com/en-us/library/hh485718.aspx">ExtractToFile</a> or the whole archive using <a href="http://msdn.microsoft.com/en-us/library/system.io.compression.zipfileextensions.extracttodirectory.aspx">ExtractToDirectory</a> &#8230; </p>

	<p>So for a final example, I&#8217;ll use ZipArchive to create a script that will always unzip to a new folder (unless there&#8217;s just one single file in the zip), and will create an &#8220;archive name&#8221; folder if there isn&#8217;t already a single folder root inside the archive.  In fact, as you&#8217;ll see below, I went further and <em>forced</em> the resulting folder to always end up named after the archive.</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;">-As</span> System.<span style="color: #003366;">IO</span>.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">FileSystem</span><br />
<br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">Expand-<span style="font-style: normal;">ZipFile</span></span> <span style="color: #333;">&#123;</span><br />
&nbsp; <span style="color: #666666; font-style: italic;">#.Synopsis</span><br />
&nbsp; <span style="color: #666666; font-style: italic;"># &nbsp;Expand a zip file, ensuring it's contents go to a single folder ...</span><br />
&nbsp; <span style="color: #333;">&#91;</span>CmdletBinding<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; <span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># The path of the zip file that needs to be extracted</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#91;</span>Parameter<span style="color: #333;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span>, Position<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>, Mandatory<span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#91;</span>Alias<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;PSPath&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$FilePath</span>,<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># The path where we want the output folder to end up</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$FolderPath</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Pwd</span>,<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Make sure the resulting folder is always named the same as the archive</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Force</span><br />
&nbsp; <span style="color: #333;">&#41;</span><br />
&nbsp; <span style="color: #666699; font-weight: bold;">process</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ZipFile</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Item</span></span> <span style="color: #660033; font-weight: bold;">$FilePath</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Archive</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">IO</span>.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">ZipFile</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Open</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$ZipFile</span>, <span style="color: #009900;">&quot;Read&quot;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># The place where we expect it to end up</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Destination</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">join-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$FolderPath</span> <span style="color: #660033; font-weight: bold;">$ZipFile</span>.<span style="color: #003366;">BaseName</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># The root folder of the first entry ...</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ArchiveRoot</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Archive</span>.<span style="color: #003366;">Entries</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: #333399; font-weight: bold; font-style: italic;">split</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;/&quot;</span>,<span style="color: #cc66cc;">2</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><br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># If any of the files are not in the same root folder ...</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;">$Archive</span>.<span style="color: #003366;">Entries</span>.<span style="color: #003366;">FullName</span> <span style="color: #66cc66;">|</span> Where<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">split</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;/&quot;</span>,<span style="color: #cc66cc;">2</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: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$ArchiveRoot</span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># extract it into a new folder:</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Item</span></span> <span style="color: #660033; font-weight: bold;">$Destination</span> <span style="color: #000066;">-Type</span> Directory <span style="color: #000066;">-Force</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">IO</span>.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">ZipFileExtensions</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">ExtractToDirectory</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$Archive</span>, <span style="color: #660033; font-weight: bold;">$Destination</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: #666666; font-style: italic;"># otherwise, extract it to the FolderPath </span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">IO</span>.<span style="color: #003366;">Compression</span>.<span style="color: #003366;">ZipFileExtensions</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">ExtractToDirectory</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$Archive</span>, <span style="color: #660033; font-weight: bold;">$FolderPath</span> <span style="color: #333;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># If there was only a single file in the archive, then we'll just output that file...</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;">$Archive</span>.<span style="color: #003366;">Entries</span>.<span style="color: #003366;">Count</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">1</span><span style="color: #333;">&#41;</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;">Item</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Join-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$FolderPath</span> <span style="color: #660033; font-weight: bold;">$Archive</span>.<span style="color: #003366;">Entries</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; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">elseif</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Force</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Otherwise let's make sure that we move it to where we expect it to go, in case the zip's been renamed</span><br />
&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;">$ArchiveRoot</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$ZipFile</span>.<span style="color: #003366;">BaseName</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Move-<span style="font-style: normal;">Item</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">join-<span style="font-style: normal;">path</span></span> <span style="color: #660033; font-weight: bold;">$FolderPath</span> <span style="color: #660033; font-weight: bold;">$ArchiveRoot</span><span style="color: #333;">&#41;</span> <span style="color: #660033; font-weight: bold;">$Destination</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Item</span></span> <span style="color: #660033; font-weight: bold;">$Destination</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #666699; font-weight: bold;">else</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Item</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Join-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$FolderPath</span> <span style="color: #660033; font-weight: bold;">$ArchiveRoot</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 />
<br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Archive</span>.<span style="color: #003366;">Dispose</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<h3>Update and continuation</h3>

	<p>I just posted <a href="http://poshcode.org/4198">a new version of this</a> to PoshCode including a New-ZipFile function, just because I can&#8217;t stop myself, and I&#8217;ve always wanted a zip function that behaved exactly the way I wanted it to. If anyone want&#8217;s to add to that ZipFile module, that would be the place to do it, for now. Here&#8217;s the current version:</p>

	<p><script type="text/javascript" src="http://PoshCode.org/embed/4198"></script></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/a-new-way-to-zip-and-unzip-in-powershell-3-and-net-4-5/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Long-running background tasks in ShowUI GUIs from PowerShell</title>
		<link>http://huddledmasses.org/long-running-background-tasks-in-showui-guis-from-powershell/</link>
		<comments>http://huddledmasses.org/long-running-background-tasks-in-showui-guis-from-powershell/#comments</comments>
		<pubDate>Fri, 07 Jun 2013 05:55:33 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Background Jobs]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ShowUI]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1916</guid>
		<description><![CDATA[A lot of the time when you&#8217;re writing ShowUI user interfaces in PowerShell, you&#8217;re just asking users for inputs, prompting them for choices, or showing them the results of some calculations (whether that be dashboards, graphics, etc). However, sometimes you need to prompt the user for input and then do some work, and you want ...<a class="post-readmore" href="http://huddledmasses.org/long-running-background-tasks-in-showui-guis-from-powershell/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>A lot of the time when you&#8217;re writing ShowUI user interfaces in PowerShell, you&#8217;re just asking users for inputs, prompting them for choices, or showing them the results of some calculations (whether that be dashboards, graphics, etc).  </p>

	<p>However, sometimes you need to prompt the user for input and then do some work, and you want to present the users with output as the work progresses.  With any graphical user interface, when you want to do any significant amount of work, you need to do it on a background thread.  The ShowUI way to do that is to use the Invoke-Background command, which gives you an event-driven way to run a script block (or command) and capture all of it&#8217;s various outputs.</p>

	<p>I&#8217;ll show you an example here which writes output and progress events, and show you how to handle updating the user interface with both (hopefully you&#8217;ll be able to figure out the other output options, including the errors).</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> ShowUI <span style="color: #000066;">-Req</span> <span style="color: #cc66cc;">1.4</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Grid</span></span> <span style="color: #000066;">-Columns</span> <span style="color: #009900;">&quot;*&quot;</span>,<span style="color: #009900;">&quot;5&quot;</span>,<span style="color: #009900;">&quot;70&quot;</span> <span style="color: #000066;">-Rows</span> <span style="color: #009900;">&quot;21&quot;</span>,<span style="color: #009900;">&quot;Auto&quot;</span>,<span style="color: #009900;">&quot;5&quot;</span>,<span style="color: #009900;">&quot;*&quot;</span> <span style="color: #000066;">-Margin</span> <span style="color: #cc66cc;">5</span> <span style="color: #333;">&#123;</span><br />
&nbsp; ProgressBar <span style="color: #000066;">-Name</span> ProgressBar <span style="color: #000066;">-ColumnSpan</span> <span style="color: #cc66cc;">3</span> <span style="color: #000066;">-Maximum</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">&quot;0,0,0,5&quot;</span><br />
<br />
&nbsp; TextBox <span style="color: #000066;">-Name</span> count <span style="color: #000066;">-Text</span> <span style="color: #cc66cc;">12</span> <span style="color: #000066;">-MinWidth</span> <span style="color: #cc66cc;">150</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">1</span><br />
<br />
&nbsp; TextBox <span style="color: #000066;">-Name</span> output <span style="color: #000066;">-MinHeight</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-ColumnSpan</span> <span style="color: #cc66cc;">3</span> <span style="color: #000066;">-IsReadOnly</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">3</span><br />
<br />
&nbsp; Button <span style="color: #009900;">&quot;Start&quot;</span> <span style="color: #000066;">-Name</span> StartButton <span style="color: #000066;">-Column</span> <span style="color: #cc66cc;">2</span> <span style="color: #000066;">-Row</span> <span style="color: #cc66cc;">1</span> <span style="color: #000066;">-On_Click</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># If you need to pass values from your form to the background function</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># They need to be serializable, and go through the -Parameter hashtable:</span><br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">Background</span></span> <span style="color: #000066;">-Parameter</span> @<span style="color: #333;">&#123;</span> work <span style="color: #66cc66;">=</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;">$count</span>.<span style="color: #003366;">Text</span> <span style="color: #333;">&#125;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$work</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">10</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># You would do real work here, but I'll just fake it</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$item</span> <span style="color: #666699; font-weight: bold;">in</span> 1..<span style="color: #660033; font-weight: bold;">$work</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Anything that goes to Output triggers the OutputChanged</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Output</span></span> <span style="color: #009900;">&quot;Processing item $item of $work&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Start-<span style="font-style: normal;">Sleep</span></span> <span style="color: #000066;">-milli</span> <span style="color: #cc66cc;">500</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># And of course, progress triggers the ProgressChanged</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$progress</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</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;">double</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$item</span> <span style="color: #66cc66;">/</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;">$work</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">*</span> <span style="color: #cc66cc;">100</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Progress</span></span> <span style="color: #009900;">&quot;Processing&quot;</span> <span style="color: #000066;">-PercentComplete</span> <span style="color: #660033; font-weight: bold;">$progress</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_OutputChanged</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># The actual event is on the DataContext object</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$output</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</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;">DataContext</span>.<span style="color: #003366;">Output</span> <span style="color: #000066;">-join</span> <span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">`n</span>&quot;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">String</span></span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_ProgressChanged</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ProgressBar</span>.<span style="color: #003366;">Value</span> <span style="color: #66cc66;">=</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;">DataContext</span>.<span style="color: #003366;">LastProgress</span>.<span style="color: #003366;">PercentComplete</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> <span style="color: #000066;">-Show</span><br />
&nbsp;</div>

	<p>The first key, of course, is knowing that Invoke-Background sets a <code>DataContext</code> on the object (either the object specified to the <code>-Control</code> parameter, or the parent who&#8217;s event handler calls it). That DataContext is a ShowUI.PowerShellDataSource (it&#8217;s code is in the C# folder in the ShowUI module), and it has events and properties for each of the streams: Output, Error, Warning, Verbose, Debug, and Progress.  It also has a property for the &#8220;Last&#8221; item from each of those streams, and a TimeStampedOutput property which collects <strong>all</strong> of the output, in order, with a NoteProperty for the Stream and the TimeStamp.  More importantly, it has events which fire on every output.</p>

	<p>The second key is knowing that the properties like &#8220;Output&#8221; contain all the output, and properties like &#8220;LastOutput&#8221; contain only the very last thing output. Since in the case of the progress we only care about the very last value, we&#8217;re able to use the &#8220;LastProgress&#8221; property. Since we want to show all of the output, rather than try to collect the &#8220;last&#8221; one each time, we can just overwrite the textbox&#8217;s text with the output array.  </p>

	<p>It&#8217;s also very important to remember that the properties are arrays, and in particular to remember that the Output is an array of PSObject, and the others are arrays of ProgressRecords, DebugRecords, ErrorRecords, etc&#8230; so we use <code>Out-String</code> to make sure that we convert them to a string before we set the Text of our output pane.</p>

	<p>Hopefully this function will help you out &#8212; I&#8217;ll try to improve it&#8217;s help and examples in the next release of ShowUI.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/long-running-background-tasks-in-showui-guis-from-powershell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get-Help for Modules you don&#8217;t have installed</title>
		<link>http://huddledmasses.org/get-help-for-modules-you-dont-have-installed/</link>
		<comments>http://huddledmasses.org/get-help-for-modules-you-dont-have-installed/#comments</comments>
		<pubDate>Fri, 01 Feb 2013 23:43:00 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[Help]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1870</guid>
		<description><![CDATA[If you have you ever wished you could get-help on commands for modules you don&#8217;t have installed locally, or are having problems using Save-Help to get module help onto servers that don&#8217;t have an internet connection because your clients don&#8217;t have those modules &#8212; I have a solution. With the new Update-Help command, the PowerShell ...<a class="post-readmore" href="http://huddledmasses.org/get-help-for-modules-you-dont-have-installed/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>If you have you ever wished you could get-help on commands for modules you don&#8217;t have installed locally, or are having problems using Save-Help to get module help onto servers that don&#8217;t have an internet connection because your clients don&#8217;t have those modules &#8212; I have a solution.</p>

	<p>With the new Update-Help command, the PowerShell team has made it possible to Save-Help to disk, and then move that help and update servers that are offline or behind strict firewalls.  However, there&#8217;s no built-in way to download help for a module that&#8217;s not installed on your local client &#8230; and you can&#8217;t use the output of Save-Help to read the help on your development box if you don&#8217;t have the module installed there.</p>

	<p>My new module <a href="http://poshcode.org/3930">HelpModules</a> aims to solve both those problems with two commands:</p>

	<h2>New-HelpModule</h2>

	<p>New-HelpModule will let you generate a simple module stub that contains just enough information to convince Update-Help and Save-Help to do their jobs. What&#8217;s more, it works on the pipeline so you can use Invoke-Command to get the module information from remote servers and pipe it straight into New-HelpModule:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">Command</span></span> <span style="color: #000066;">-ComputerName</span> Server1 <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span> <span style="color: #000066;">-ListAvailable</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Where</span> HelpInfoUri <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">HelpModule</span></span><br />
&nbsp;</div>

	<p>This example would actually list all the modules from a server named &#8220;Server1&#8221; that have updatable help, generate stubs for them in your local $PSModuleHelpRoot (more about that later), and update the help files (locally).</p>

	<p>You can also generate a stub by hand, given the information about the module. In other words, call your mate up on the phone, have them run <code>Get-Module Hyper-V -List | Format-List *</code> and then read you the <span class="caps">GUID</span>, Version, and HelpInfoUri &#8230; then, you just run:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">HelpModule</span></span> Hyper<span style="color: #66cc66;">-</span>V <span style="color: #009900;">'1.0'</span> <span style="color: #009900;">'af4bddd0-8583-4ff2-84b2-a33f5c8de8a7'</span> <span style="color: #009900;">'http://go.microsoft.com/fwlink/?LinkId=206726'</span><br />
&nbsp;</div>

	<h3>StubFunctions</h3>

	<p>The second problem we have is that we can&#8217;t run Get-Help on commands that don&#8217;t exist on our system.  There are two ways around that, using this module.  The simplest is to just pass the <code>-StubFunctions</code> switch when you&#8217;re calling New-HelpModule. This will generate empty function stubs for each command that&#8217;s in the original module &#8212; they have no parameters, no code, nothing. </p>

	<p>StubFunctions are be enough to let <code>Get-Help</code> work on those commands, but you&#8217;ll have to add the <code>$PSModuleHelpRoot</code> to your <code>$Env:PSModulePath</code> in order to take advantage of it.  The problem with that is that you&#8217;ll pollute your session with modules and commands that don&#8217;t really exist (or at least, don&#8217;t do anything).  Incidentally, I promised more information about PSModuleHelpRoot:</p>

	<h3>PSModuleHelpRoot</h3>

	<p>This variable is exported by the HelpModules module, and it&#8217;s the path to where <code>New-HelpModule</code> will generate modules (and where <code>Get-ModuleHelp</code> will read from: more on that next).  The path defaults to a &#8220;WindowsPowerShellHelpModules&#8221; folder in your Documents directory, but you can set it to anything you like after importing the module.</p>

	<h2>Get-ModuleHelp</h2>

	<p>Get-ModuleHelp is basically a simplified version of Get-Help that works straight on the <span class="caps">XML</span> files in your <code>$PSModuleHelpRoot</code> modules.  Instead of searching for commands, it searches for help.</p>

	<p>It basically works the same as Get-Help, so I&#8217;m not going to bother with documentation here &#8212; the point is, unlike Get-Help, this doesn&#8217;t require you to add <code>$PSModuleHelpRoot</code> to your <code>$Env:PSModulePath</code>, and thus doesn&#8217;t add empty modules and commands to your session.  It&#8217;s a little harder to work with, since you have to know what help you have available, and you have to type the full command name (no wildcard support) but that seemed worth it to me.</p>

	<p>Get <a href="http://poshcode.org/3930">HelpModules</a> from PoshCode.org (you&#8217;ll want to save it as &#8220;HelpModules.psm1&#8221; to a path in your PSModulePath like: ~\Documents\WindowsPowerShell\Modules\HelpModules\HelpModules.psm1</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/get-help-for-modules-you-dont-have-installed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why I&#8217;m not excited about Windows 8 Certified Store Apps</title>
		<link>http://huddledmasses.org/why-you-wont-see-windows-8-certified-appstore-apps-from-me/</link>
		<comments>http://huddledmasses.org/why-you-wont-see-windows-8-certified-appstore-apps-from-me/#comments</comments>
		<pubDate>Wed, 19 Dec 2012 21:03:15 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1844</guid>
		<description><![CDATA[It&#8217;s come up a few times recently, and I&#8217;m frustrated enough that I thought I&#8217;d just post this here for reference. The Windows 8 App Certification requirements has one particular requirement that makes me (as a life-long scripter) very unhappy: 3.9 All app logic must originate from, and reside in, your app package Your app ...<a class="post-readmore" href="http://huddledmasses.org/why-you-wont-see-windows-8-certified-appstore-apps-from-me/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>It&#8217;s come up a few times recently, and I&#8217;m frustrated enough that I thought I&#8217;d just post this here for reference.</p>

	<p>The <a href="http://msdn.microsoft.com/library/windows/apps/hh694083">Windows 8 App Certification requirements</a> has one particular requirement that makes me (as a life-long scripter) very unhappy:  </p>

	<blockquote>
		<p><strong>3.9 All app logic must originate from, and reside in, your app package</strong></p>
	</blockquote>

	<blockquote>
		<p>Your app must not attempt to change <em>or extend</em> the packaged content through any form of dynamic inclusion of code or data that changes how the application interacts with the Windows Runtime, or behaves with regard to Store policy. It is not permissible, for example, to download a remote script and subsequently execute that script in the local context of your app package</p>
	</blockquote>

	<p>Bottom line: you cannot write extensible apps for the Windows Store.  In fact, although Windows PowerShell is shipped even on Windows RT, you can&#8217;t use it from a certified Windows 8 Store app.</p>

	<p>I don&#8217;t know about you, but the <em>apps that I use on a regular basis are almost all extensible</em>, and most of them have both plugins <em>and</em> scripting:</p>

	<ul>
		<li>Visual Studio (Thank goodness for NuGet, ReSharper, StyleCop, GhostDoc, NCrunch etc) </li>
		<li>Notepad++ and Sublime Text 2 and PyCharm</li>
		<li>PowerShell and ConEmu</li>
		<li>Microsoft Office: Word, Excel</li>
		<li>KeePass</li>
		<li>Firefox, and even Chrome and IE</li>
	</ul>
	<ul>
		<li>XChat and even Trillian</li>
	</ul>

	<p>I&#8217;ve been using Windows 8 for months now, but every app pinned on my taskbar is extensible, and leaving aside video games, I can only see three apps I&#8217;ve used in the last month which aren&#8217;t readily extensible: PeaZip (which does have some scripting capabilities, but I don&#8217;t use them since I script from PowerShell), Zune, and Trillian (which is technically extensible, but all the plugins I use ship in the box).</p>

	<h4>Even Windows File Manager has shell extensions. </h4>

	<p>Now, I&#8217;m not saying I won&#8217;t use an app that&#8217;s not extensible &#8230; but without even thinking about it, most of the apps I use are scriptable and/or extensible, and I bet that&#8217;s true of most of the apps you use too.  As a side note, one of the coolest new phone apps from Microsoft is <a href="https://www.onx.ms/">on{x}</a>, an automation app which is only <a href="https://play.google.com/store/apps/details?id=com.microsoft.onx.app">available on Android</a> (and can&#8217;t ever pass validation on the Windows Store because of this policy).</p>

	<p>So yeah.  Most of the stuff I do with computers is about automation, scripting, robotics&#8230; or gaming.  I can&#8217;t see myself getting really fired up about that App Store stuff. </p>

	<h3>Let me know when 3.9 is revoked.</h3>

	<p>Now, I have faith in Microsoft. I&#8217;m sure they&#8217;re not trying to kill off running multiple windows on a desktop, but I don&#8217;t understand why they would write terms in their certification requirements that would prevent an app like Sublime Text 2, KeePass, or Firefox from being written. I certainly hope that they can be convinced to rewrite that constraint to allow for <em>users who choose</em> to install modules and scripts.</p>

	<p>As a side note, there&#8217;s another point in there that I&#8217;m not too happy with either:</p>

	<blockquote>
		<p><strong>4.4 Your app must not be designed or marketed to perform, instruct, or encourage tasks that could cause physical harm to a customer or any other person</strong></p>
	</blockquote>

	<blockquote>
		<p>We would consider an app that allows for control of a device without human manipulation, or that is marketed for use to resolve emergency or lifesaving situations to violate this requirement.</p>
	</blockquote>

	<p>At first, that one seemed fine.  But when you read the detail, it&#8217;s clear that any app that is for robotics/AI and wants to interface with external devices is basically going to be refused. Your <a href="http://http://mindstorms.lego.com">Lego Mindstorms</a> apps are only allowed if they&#8217;re remote controls which require human manipulation, because they &#8230; might cause harm?</p>

	<p>As long as we&#8217;ve got desktop mode and sideloading of non-certified apps, we&#8217;re ok (I guess), but <strong>Microsoft needs to stop limiting certified apps before they alienate the hackers and tinkerers.</strong>  I&#8217;m a big fan (and author) of Open Source software, but I don&#8217;t want a world where all the commercial software companies lock out the geeks and our only option is Open Source.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/why-you-wont-see-windows-8-certified-appstore-apps-from-me/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell PowerUser Tips: The Hash TabExpansion</title>
		<link>http://huddledmasses.org/powershell-poweruser-tips-the-hash-tabexpansion/</link>
		<comments>http://huddledmasses.org/powershell-poweruser-tips-the-hash-tabexpansion/#comments</comments>
		<pubDate>Sat, 20 Oct 2012 05:29:21 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerTips]]></category>
		<category><![CDATA[TabComplete]]></category>
		<category><![CDATA[TabExpansion]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1837</guid>
		<description><![CDATA[One of my favorite features in the built-in TabExpansion in PowerShell is one that many (if not most) users are unaware of: the &#8220;#&#8221; hash mark. In order to test this tip, you&#8217;re going to need a command console that you&#8217;ve used and typed several commands into, so that Get-History will return more than a ...<a class="post-readmore" href="http://huddledmasses.org/powershell-poweruser-tips-the-hash-tabexpansion/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>One of my favorite features in the built-in TabExpansion in PowerShell is one that many (if not most) users are unaware of: the &#8220;#&#8221; hash mark.</p>

	<p>In order to test this tip, you&#8217;re going to need a command console that you&#8217;ve used and typed several commands into, so that Get-History will return more than a few <em>different</em> commands. Now, actually run the Get-History command so you can see the list of your last few commands.</p>

	<p>The basic tip is pretty simple: if you type &#8220;#&#8221; and then hit the Tab key, PowerShell completes the full previous command-line.</p>

	<p>You can also hit tab <em>again</em> to complete the next oldest command-line, and so on, right back to the beginning (it actually wraps around). You can even hit Shift-Tab to reverse direction if you go past the command-line you wanted.  Additionally, this works on your history, so it even completes multi-line items. The one weird thing is that if you tab-complete past an item with multiple lines, the TabExpansion function doesn&#8217;t realize the cursor&#8217;s not on the prompt line anymore, so it doesn&#8217;t quite redraw right, but it&#8217;s mostly ok: the commands still work.</p>

	<p>Of course, if that&#8217;s all there was to this, I&#8217;d just have tweeted and gone back to preparing for my presentation at the <a href="http://itproguru.com/expert/2012/10/windows-server-2012-launch-event-in-rochester-ny-oct-23rd/">Windows Server 2012 Launch Event in Rochester</a> &#8230;</p>

	<p>The <em>really</em> cool thing is that you can filter the feature. That is: if you type # and then the first few characters of some command-line in your history, when you hit tab you will get the most recent command-line that starts with those characters, and as before, you can hit tab repeatedly to cycle through all the commands in your history that match.</p>

	<p>There&#8217;s one more part to the hash-tab feature: numbers.  If you know the history id of the command you want to type, you can type, for instance,  #20{Tab} to complete the 20th command from your PowerShell session. It&#8217;s basically the same as using &#8220;r&#8221; shortcut for invoke-history, except you hit tab after the number instead of space before, and you get to see the command (and edit it) before you press Enter.</p>

	<p>So to sum up:</p>

	<ul>
		<li>hash-tab &#8211; completes command-lines from your history</li>
		<li>hash-txt-tab &#8211; filters your history like get-history | where { $_.Commandline -Like txt* }</li>
	</ul>
	<ul>
		<li>hash-id-tab &#8211; completes the command from history with the matching id</li>
	</ul>

]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-poweruser-tips-the-hash-tabexpansion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adventures getting MSBuild, TFS and SQL Server Data Tools to work together</title>
		<link>http://huddledmasses.org/adventures-getting-msbuild-tfs-and-sql-server-data-tools-to-work-together/</link>
		<comments>http://huddledmasses.org/adventures-getting-msbuild-tfs-and-sql-server-data-tools-to-work-together/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 05:42:40 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Deploy]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[Publish]]></category>
		<category><![CDATA[SSDT]]></category>
		<category><![CDATA[TFSBuild]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1830</guid>
		<description><![CDATA[We recently found that our database project at work goes from a 40-minute build and compile to about 20 minutes when we upgrade from the VS2010 (SQL 2008) database projects (with the old .dbproj files) to the new SQL Server Data Tools (SSDT) projects with the .sqlproj files, even though we&#8217;re still deploying to SQL ...<a class="post-readmore" href="http://huddledmasses.org/adventures-getting-msbuild-tfs-and-sql-server-data-tools-to-work-together/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>We recently found that our database project at work goes from a 40-minute build and compile to about 20 minutes when we upgrade from the VS2010 (<span class="caps">SQL</span> 2008) database projects (with the old .dbproj files) to the new <span class="caps">SQL</span> Server Data Tools (<span class="caps">SSDT</span>) projects with the .sqlproj files, even though we&#8217;re still deploying to <span class="caps">SQL</span> Server 2008 R2. So our goal immediately became:</p>

	<h3>Get the <span class="caps">SSDT</span> projects to compile with parameters from MSBuild</h3>

	<p>The problem is that with the new .sqlproj and the <code>SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets</code> there&#8217;s no built-in way to pass the database name or even a connection string when building the project via MSBuild &#8212; which is a critical part of our continuous integration builds.  The project I&#8217;m working on these days has 7 or 8 teams working in up to twice that many branches, and all those branches need CI builds, every one of which deploys the database project and validates it.  Since the branches change at least once a week, it&#8217;s way too much work to run around modifying publish.xml files to change database names every time we create a new branch (which we need to do to avoid the builds deploying over the top of each other).  </p>

	<p>With the old .dbproj format, there was a SQLDeploy task called in the <code>TeamData\Microsoft.Data.Schema.SqlTasks.targets</code> build target file which included a whole bunch of variables that could be overridden on the command line, so we could pass <code>TargetDatabase</code> and <code>TargetConnectionString</code> as MSBuild arguments, and then, to be able to compile the whole solution and still call the <strong>Deploy</strong> target, we added this to the project file:</p>

	<div class="xml code xml" style="font-family:monospace;"><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DBDeployOnBuild</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(DBDeployOnBuild)' == ''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>False<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DBDeployOnBuild<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;AfterBuild&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CallTarget</span> <span style="color: #000066;">Targets</span>=<span style="color: #ff0000;">&quot;Deploy&quot;</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(DBDeployOnBuild)'=='True'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp;</div>

	<p>In our workflow, we redefine MSBuildArguments in the workflow, and now we can msbuild the whole solution and the database will be deployed:</p>

	<div class="vb code vb" style="font-family:monospace;"><br />
MSBuildArguments &amp; &quot; /p:DBDeployOnBuild=<span style="color: #000080;">True</span>;TargetDatabase=&quot;&quot;&quot; &amp; BuildDetail.BuildDefinition.Name &amp; &quot;&quot;&quot;;TargetConnectionString=...&quot;<br />
&nbsp;</div>

	<h3>But that doesn&#8217;t work with the new <span class="caps">SSDT</span> project type.</h3>

	<p>First of all, they don&#8217;t deploy with all their dependencies, instead, they have to be published.  It&#8217;s basically the same thing, with a different name.  But the SqlPublish task <strong>requires all the parameters to be in an xml file,</strong> and there&#8217;s no build properties we can override, because the properties are hiding in that publish.xml file that doesn&#8217;t get tokenized</p>

	<p>I&#8217;ve spent the last couple of days figuring out a work around, so I figured I should blog it up here and help the next guy.  The process is not simple.  The bottom line is that I haven&#8217;t found a way to get the SQLPublish task to take it&#8217;s values from anywhere except a publish xml file, so the solution I came up with was to rewrite the publish file using the <span class="caps">XDT</span> transform tasks defined for Web.config transforms.</p>

	<h3>Web.Config Transforms, on random <span class="caps">XML</span> files</h3>

	<p>The cool thing is, there&#8217;s actually a <code>ParameterizeTransformXml</code> task which allows you to define your transform as a string in the build file. </p>

	<div class="xml code xml" style="font-family:monospace;"><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UsingTask</span> <span style="color: #000066;">TaskName</span>=<span style="color: #ff0000;">&quot;ParameterizeTransformXml&quot;</span> <span style="color: #000066;">AssemblyFile</span>=<span style="color: #ff0000;">&quot;$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp;</div>

	<p>In web projects, that task is used to replace connection strings (to hide them in web packages), but we can use it to replace the database name in our publish.xml.  In fact, I can actually add the same properties to the build that we used to have with the old project format (and which we&#8217;ll define on the command-line, <em>exactly</em> the way we did before). We put some default properties for TargetDatabaseName and TargetConnectionString in our Debug.publish.xml and our CI.publish.xml and then we just replace them during the build.  </p>

	<p>It&#8217;s a lot more complicated than what we had to do previously, partly because we need to define the <code>SqlPublishProfilePath</code> for the Publish task, but we have to use <code>CallTarget</code> to call the Publish target (not Deploy this time), which doesn&#8217;t support passing properties, nor does the target you call inherit properties that are defined in your scope.  This means we need to define the <code>SqlPublishProfilePath</code> property in the <code>BeforePublish</code> target which the publish target depends on (the &#8220;dependson&#8221; relationship inherits defined properties).</p>

	<div class="xml code xml" style="font-family:monospace;"><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;AfterBuild&quot;</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(DBDeployOnBuild)'=='True'&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;CallTarget</span> <span style="color: #000066;">Targets</span>=<span style="color: #ff0000;">&quot;Publish&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;BeforePublish&quot;</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;('$(TargetDatabase)' != '' Or '$(TargetConnectionString)' != '') And Exists($(TransformOutputFile))&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;SqlPublishProfilePath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>$(TransformOutputFile)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/SqlPublishProfilePath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp;</div>

	<p>But the real work is actually setting up the <strong>TransformPublishXml</strong> property with the right <span class="caps">XML</span> to replace the nodes with the properties from the command-line arguments, and then actually calling the task.  Since we imported the task before, we just need a property group to define our variables with default values, and then a <code>BeforeBuild</code> target to actually call the ParameterizeTransformXml:</p>

	<div class="xml code xml" style="font-family:monospace;"><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PropertyGroup</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(TargetDatabase)' != '' Or '$(TargetConnectionString)' != ''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DBDeployOnBuild</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(DBDeployOnBuild)' == ''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>False<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DBDeployOnBuild<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TargetConnectionStringXml</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(TargetConnectionString)' != ''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #ddbb00;">&amp;lt;</span>TargetConnectionString xdt:Transform=&quot;Replace&quot;<span style="color: #ddbb00;">&amp;gt;</span>$(TargetConnectionString)<span style="color: #ddbb00;">&amp;lt;</span>/TargetConnectionString<span style="color: #ddbb00;">&amp;gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TargetConnectionStringXml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TargetDatabaseXml</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(TargetDatabase)' != ''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #ddbb00;">&amp;lt;</span>TargetDatabaseName xdt:Transform=&quot;Replace&quot;<span style="color: #ddbb00;">&amp;gt;</span>$(TargetDatabase)<span style="color: #ddbb00;">&amp;lt;</span>/TargetDatabaseName<span style="color: #ddbb00;">&amp;gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TargetDatabaseXml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformPublishXml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><span style="color: #ddbb00;">&amp;lt;</span>?xml version=&quot;1.0&quot;?<span style="color: #ddbb00;">&amp;gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ddbb00;">&amp;lt;</span>Project xmlns:xdt=&quot;http://schemas.microsoft.com/XML-Document-Transform&quot; xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;<span style="color: #ddbb00;">&amp;gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ddbb00;">&amp;lt;</span>PropertyGroup<span style="color: #ddbb00;">&amp;gt;</span>$(TargetConnectionString)$(TargetDatabaseXml)<span style="color: #ddbb00;">&amp;lt;</span>/PropertyGroup<span style="color: #ddbb00;">&amp;gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ddbb00;">&amp;lt;</span>/Project<span style="color: #ddbb00;">&amp;gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformPublishXml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformFile</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(SqlPublishProfilePath)' != ''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>$(SqlPublishProfilePath)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformFile</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(SqlPublishProfilePath)' == ''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>$(Configuration).publish.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformFile</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$([System.IO.Path]::IsPathRooted($(TransformFile)))' == 'False'&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>$(MSBuildProjectDirectory)$(TransformFile)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- In order to do a transform, we HAVE to change the SqlPublishProfilePath--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;BuildDefinitionName</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(BuildDefinitionName)' ==''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>VSBuild<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/BuildDefinitionName<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformOutputFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>$(MSBuildProjectDirectory)$(BuildDefinitionName)_$(Configuration).publish.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformOutputFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformScope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>$([System.IO.Path]::GetFullPath($(MSBuildProjectDirectory)))<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformScope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TransformStackTraceEnabled</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;'$(TransformStackTraceEnabled)'==''&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>False<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/TransformStackTraceEnabled<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;UsingTask</span> <span style="color: #000066;">TaskName</span>=<span style="color: #ff0000;">&quot;ParameterizeTransformXml&quot;</span> <span style="color: #000066;">AssemblyFile</span>=<span style="color: #ff0000;">&quot;$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;BeforeBuild&quot;</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;('$(TargetDatabase)' != '' Or '$(TargetConnectionString)' != '')&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;The Target Database: '$(TargetDatabase)' and Connection String: '$(TargetConnectionString)'&quot;</span> <span style="color: #000066;">Importance</span>=<span style="color: #ff0000;">&quot;high&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">&lt;!-- If TargetDatabase or TargetConnectionString is passed in</span><br />
<span style="color: #808080; font-style: italic;"> &nbsp; &nbsp; &nbsp; &nbsp; Then we use the tokenize transform to create a parameterized sql publish file--&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Error</span> <span style="color: #000066;">Condition</span>=<span style="color: #ff0000;">&quot;!Exists($(TransformFile))&quot;</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;The SqlPublish Profile '$(TransformFile)' does not exist, please specify a valid file using msbuild /p:SqlPublishProfilePath='Path'&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ParameterizeTransformXml</span> <span style="color: #000066;">Source</span>=<span style="color: #ff0000;">&quot;$(TransformFile)&quot;</span> <span style="color: #000066;">IsSourceAFile</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">Transform</span>=<span style="color: #ff0000;">&quot;$(TransformPublishXml)&quot;</span> <span style="color: #000066;">IsTransformAFile</span>=<span style="color: #ff0000;">&quot;False&quot;</span> <span style="color: #000066;">Destination</span>=<span style="color: #ff0000;">&quot;$(TransformOutputFile)&quot;</span> <span style="color: #000066;">IsDestinationAFile</span>=<span style="color: #ff0000;">&quot;True&quot;</span> <span style="color: #000066;">Scope</span>=<span style="color: #ff0000;">&quot;$(TransformScope)&quot;</span> <span style="color: #000066;">StackTrace</span>=<span style="color: #ff0000;">&quot;$(TransformStackTraceEnabled)&quot;</span> <span style="color: #000066;">SourceRootPath</span>=<span style="color: #ff0000;">&quot;$(MSBuildProjectDirectory)&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ParameterizeTransformXml<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp;</div>

	<p>So all you have to do is put those three blocks of <span class="caps">XML</span> at the bottom of your .sqlproj file, and then call <code>msbuild</code> with <code>/p:TargetDatabase=DBName;TargetConnectionString=&#34;Data Source=DBServer;User ID=sa;Password=password&#34;;DBDeployOnbuild=True</code> to get the database project to build <em>and deploy</em> to the database you want.</p>

	<p>If you&#8217;ve got questions, post &#8216;em &#8212; I&#8217;m writing this at 1:30 in the morning so I&#8217;m not at my most lucid  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':-)' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/adventures-getting-msbuild-tfs-and-sql-server-data-tools-to-work-together/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Get-Command in PowerShell 3 (NOTE: CTP2 Bug causes module loading)</title>
		<link>http://huddledmasses.org/get-command-in-powershell-3/</link>
		<comments>http://huddledmasses.org/get-command-in-powershell-3/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 06:16:29 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Bugs]]></category>
		<category><![CDATA[Get-Command]]></category>
		<category><![CDATA[Import-Module]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1813</guid>
		<description><![CDATA[I don&#8217;t normally blog about the bugs I find in beta software, but I posted this bug to PowerShell&#8217;s Connect and I feel like it got ignored and not voted, so I&#8217;m going to try to explain myself better here &#8230; The bug is on Connect, but let me talk to you first about how ...<a class="post-readmore" href="http://huddledmasses.org/get-command-in-powershell-3/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>I don&#8217;t normally blog about the bugs I find in beta software, but I posted this bug to PowerShell&#8217;s Connect and I feel like it got ignored and not voted, so I&#8217;m going to try to explain myself better here &#8230; The <a href="https://connect.microsoft.com/PowerShell/feedback/details/724659/passing-a-module-array-to-get-command-imports-modules">bug is on Connect</a>, but let me talk to you first about how <code>Get-Command</code> is supposed to work.</p>

	<p>In PowerShell, <code>Get-Command</code> is a command that serves two purposes: first it lets you search for commands using verb, noun, wildcards, module names etc. and then it also returns metadata about commands.  In PowerShell 2, it could only search commands that were in modules (or snapins) you had already imported, or executables &#038; scripts that were in your <span class="caps">PATH</span>. </p>

	<p>So here&#8217;s the deal: <code>Get-Command</code> has always behaved differently when it thinks you&#8217;re searching.  The only way it can tell that you&#8217;re searching is that you don&#8217;t provide a full command name. So, if you use a wildcard (e.g.: <code>Get-Command Get-Acl*</code> or even <code>Get-Command Get-Ac[l]</code>), or search using a Noun or Verb (e.g.: <code>Get-Command -Verb Get</code> or <code>Get-Command -Noun Acl</code> or even <code>Get-Command -Verb Get -Noun Acl</code>), then PowerShell assumes you&#8217;re searching (and won&#8217;t throw an error when no command is found).  </p>

	<p>In PowerShell 3, because modules can be loaded automatically when you try to run a command from them, <code>Get-Command</code> had to be modified to be able to return commands that aren&#8217;t already loaded.  The problem the PowerShell team faced is that in order to get the metadata about a command, they needed to actually import the module. What they came up with is that if you&#8217;re searching &#8230; then Get-Command will <em>not</em> load modules which aren&#8217;t already loaded.  If you specify a full command name with no wildcards, then PowerShell will load any module(s) where it finds a matching command in order to get the metadata (parameter sets, assembly info, help, etc). And of course, if you specify a full command that doesn&#8217;t exist, you&#8217;ll get an error!</p>

	<p>Perhaps a few examples will help:</p>

	<p>Launch <strong>PowerShell 3</strong> using: </p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">powershell</span> <span style="color: #000066;">-noprofile</span> <span style="color: #000066;">-noexit</span> <span style="color: #000066;">-command</span> <span style="color: #009900;">&quot;function prompt {'[$($myinvocation.historyID)]: '}&quot;</span><br />
&nbsp;</div>

	<p>And then try this, noticing how much more information you get when you specify a specific full name:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #000066;">-Verb</span> Get <span style="color: #000066;">-Noun</span> Acl <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Format-<span style="font-style: normal;">List</span></span><br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span><br />
Capability &nbsp; &nbsp; &nbsp; : Cmdlet<br />
Definition &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span><br />
Path &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :<br />
AssemblyInfo &nbsp; &nbsp; :<br />
DLL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;:<br />
HelpFile &nbsp; &nbsp; &nbsp; &nbsp; :<br />
ParameterSets &nbsp; &nbsp;: <span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
ImplementingType :<br />
Verb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Get<br />
Noun &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Acl<br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Format-<span style="font-style: normal;">List</span></span><br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span><br />
Capability &nbsp; &nbsp; &nbsp; : Cmdlet<br />
Definition &nbsp; &nbsp; &nbsp; : <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Path<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-InputObject</span> <span style="color: #66cc66;">&lt;</span>psobject<span style="color: #66cc66;">&gt;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>LiteralPath<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
Path &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :<br />
AssemblyInfo &nbsp; &nbsp; :<br />
DLL &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: C:\Windows\Microsoft.<span style="color: #003366;">Net</span>\assembly\GAC_MSIL\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span>\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;v4.0_3.0.0.0__31bf3856ad364e35\<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span>.<span style="color: #003366;">dll</span><br />
HelpFile &nbsp; &nbsp; &nbsp; &nbsp; : Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span>.<span style="color: #003366;">dll</span><span style="color: #66cc66;">-</span><span style="color: #660033;">Help</span>.<span style="color: #003366; font-weight: bold;">xml</span><br />
ParameterSets &nbsp; &nbsp;: <span style="color: #333;">&#123;</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Path<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000066;">-InputObject</span> <span style="color: #66cc66;">&lt;</span>psobject<span style="color: #66cc66;">&gt;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>LiteralPath<span style="color: #333;">&#93;</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Audit<span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>AllCentralAccessPolicies<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span><span style="color: #666699; font-weight: bold;">Filter</span> <span style="color: #66cc66;">&lt;</span>string<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Include <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>Exclude <span style="color: #66cc66;">&lt;</span>string<span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#91;</span><span style="color: #66cc66;">-</span>UseTransaction<span style="color: #333;">&#93;</span> <span style="color: #333;">&#91;</span><span style="color: #66cc66;">&lt;</span>CommonParameters<span style="color: #66cc66;">&gt;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#125;</span><br />
ImplementingType : Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Commands</span>.<span style="color: #003366;">GetAclCommand</span><br />
Verb &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Get<br />
Noun &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : Acl<br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">ConvertFrom-<span style="font-style: normal;">Sec</span></span>...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<h3>But there are several problems:</h3>

	<p><code>Get-Command</code> has another parameter: <code>-Module</code>, which allows you to specify which modules should be searched, and in PowerShell 3, it changes the behavior in weird (buggy) ways:</p>

	<ol>
		<li>If you specify a single module, then that module is imported (to search it more thoroughly?), <em>even if you specify a <strong>specific</strong> command that&#8217;s <strong>not</strong> in that module</em>.</li>
		<li>If you specify a single module that does <strong>not</strong> have a command that matches, then Microsoft.PowerShell.Management is loaded <em>also</em>. I don&#8217;t know why yet.</li>
		<li>If you specify more than one module, <em>and you&#8217;re searching</em>, and none of them have a command that matches &#8230; it&#8217;s just as though you hadn&#8217;t specified modules, and nothing unexpected happens.
		<li>If you specify more than one module, <em>and a specific command</em>, then it gets <strong>really wierd</strong>:
	<ul>
		<li>If the command <em>is</em> in one (or more) of the specified modules,  the first module (in <span class="caps">PATH</span> order, not the order you specified) which you listed that has the command is imported.</li>
	</ul></li>
	<ul>
		<li>If it&#8217;s a valid command in a different module, the first module with the command is loaded &#8230; and so is Microsoft.PowerShell.Management. I don&#8217;t know why! Oh, and you still get the error because it can&#8217;t find the command where you told it to look.</li>
	</ul></li>
	</ol>
	<ol>
		<li></li>
	</ol>

	<p>I <a href="https://connect.microsoft.com/PowerShell/feedback/details/724659/passing-a-module-array-to-get-command-imports-modules">filed a bug on Connect</a> to cover that last scenario where the module containing the command is loaded even though you gave Get-Command a list of modules to look in, here&#8217;s another example, and notice that even though all I do here is run the same command over and over (I added some Get-Module to show you <span class="caps">WHY</span> you get these results, but it&#8217;s the same without them), but I get different results:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-module</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># Passes one module</span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> : The term <span style="color: #009900;">'get-acl'</span> <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> <span style="color: #333399; font-weight: bold; font-style: italic;">not</span> recognized <span style="color: #333399; font-weight: bold; font-style: italic;">as</span> the name of a <br />
cmdlet, <span style="color: #666699; font-weight: bold;">function</span>, script file, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> operable program. <span style="color: #003366;">Check</span> the <br />
spelling of the name, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> <span style="color: #666699; font-weight: bold;">if</span> a path was included, verify that the <br />
path <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> correct <span style="color: #333399; font-weight: bold; font-style: italic;">and</span> <span style="color: #666699; font-weight: bold;">try</span> again.<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Management</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Computer</span></span>, ...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-module</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><span style="color: #333;">&#41;</span> <span style="color: #666666; font-style: italic;"># Passes two modules </span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> : The term <span style="color: #009900;">'get-acl'</span> <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> <span style="color: #333399; font-weight: bold; font-style: italic;">not</span> recognized <span style="color: #333399; font-weight: bold; font-style: italic;">as</span> the name of a <br />
cmdlet, <span style="color: #666699; font-weight: bold;">function</span>, script file, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> operable program. <span style="color: #003366;">Check</span> the <br />
spelling of the name, <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> <span style="color: #666699; font-weight: bold;">if</span> a path was included, verify that the <br />
path <span style="color: #333399; font-weight: bold; font-style: italic;">is</span> correct <span style="color: #333399; font-weight: bold; font-style: italic;">and</span> <span style="color: #666699; font-weight: bold;">try</span> again.<br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><br />
<br />
ModuleType Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ExportedCommands<br />
<span style="color: #66cc66;">----------</span> <span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------------</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Management</span> &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Computer</span></span>, ...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span> &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">ConvertFrom-<span style="font-style: normal;">Sec</span></span>...<span style="color: #333;">&#125;</span><br />
Manifest &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Utility</span> &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span><span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span>, ...<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #333;">&#93;</span>: <span style="color: #666666; font-style: italic;"># This time it will include Microsoft.PowerShell.Security!</span><br />
<span style="color: #333;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #333;">&#93;</span>: <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> <span style="color: #000066;">-module</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Module</span></span><span style="color: #333;">&#41;</span> <br />
<br />
Capability &nbsp; &nbsp; &nbsp;Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ModuleName<br />
<span style="color: #66cc66;">----------</span> &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #66cc66;">----------</span><br />
Cmdlet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Acl</span></span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Microsoft.<span style="color: #003366; font-weight: bold;">PowerShell</span>.<span style="color: #003366;">Security</span><br />
&nbsp;</div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/get-command-in-powershell-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rich formatting for PowerShell help</title>
		<link>http://huddledmasses.org/rich-formatting-for-powershell-help/</link>
		<comments>http://huddledmasses.org/rich-formatting-for-powershell-help/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 03:54:33 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Help]]></category>
		<category><![CDATA[Html]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[ShowUI]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1802</guid>
		<description><![CDATA[[updated] Ok, I just updated this with a new post on PoshCode. I posted the HtmlHelp module to PoshCode for generating HTML web pages based on the help for functions or cmdlets. It basically has one command: Get-HtmlHelp, which takes a couple of parameters now. The only mandatory parameter is the name of the command ...<a class="post-readmore" href="http://huddledmasses.org/rich-formatting-for-powershell-help/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p><strong>[updated]</strong> Ok, I just updated this with a new post on PoshCode.  I posted the <a href="http://poshcode.org/3197">HtmlHelp</a> module to PoshCode for <em>generating <span class="caps">HTML</span> web pages based on the help for functions or cmdlets</em>. It basically has one command: Get-HtmlHelp, which takes a couple of parameters now.  The only mandatory parameter is the name of the command you want help for, in this case the html is output on the pipeline and can be redirected into a file.</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">HtmlHelp</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">HtmlHelp</span></span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Content</span></span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">HtmlHelp</span></span>.<span style="color: #003366;">html</span><br />
&nbsp;</div>

	<p>The markup generated is (I hope) reasonable and lightweight, with some simple css rules pre-applied.  Feel free to customize the script to generate help however you like.  </p>

	<h2><strong> <img src='http://huddledmasses.org/wordpress/wp-includes/' alt='[new]' class='wp-smiley' /> </strong> Generating many at once</h2>

	<p>I forgot to mention the other parameters on Get-HtmlHelp. They&#8217;re pretty cool, because if you want to upload your help you can do so with this. Say you created a module, and you wanted to generate all the help into files for uploading.  You want to set the <code>-BaseUrl</code> to the location you will upload them to, and then use the <code>-OutputFolder</code> parameter to generate an html file for each command into the specified folder:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Command</span></span> <span style="color: #000066;">-Module</span> ModuleName <span style="color: #66cc66;">|</span> <br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">HtmlHelp</span></span> <span style="color: #000066;">-BaseUrl</span> http:<span style="color: #66cc66;">//</span>HuddledMasses.<span style="color: #003366;">org</span><span style="color: #66cc66;">/</span>HtmlHelp<span style="color: #66cc66;">/</span> <span style="color: #000066;">-OutputFolder</span> ~\sites\HuddledMasses\HtmlHelp\<br />
&nbsp;</div>

	<p>Now you can just take those files and upload them to the right spot on your website. I actually have some scripts which I can wrap around this to post the help to a wiki, but you&#8217;re just going to have to wait for that until the next time I get inspired to work on help &#8230;</p>

	<h3>Show-Help</h3>

	<p>I did include a little function in the comments and in the help for Get-HtmlHelp which uses <a href="http://ShowUI.CodePlex.com">ShowUI</a> to display the rich formatted help in a popup window:</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;">Show-<span style="font-style: normal;">Help</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: #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;">$Name</span><span style="color: #333;">&#41;</span> &nbsp;<br />
&nbsp; &nbsp;Window <span style="color: #333;">&#123;</span> WebBrowser <span style="color: #000066;">-Name</span> wb <span style="color: #333;">&#125;</span> <span style="color: #000066;">-On_Loaded</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$wb</span>.<span style="color: #003366;">NavigateToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">HtmlHelp</span></span> <span style="color: #660033; font-weight: bold;">$Name</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Title</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Get-Help $Name&quot;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Show</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>So anyway, enough of that. When you run it, it looks like this (click for the full screenshot):</p>

	<p><a href="http://joelbennett.net/wordpress/wp-content/uploads/2012/01/Show-Help.png"><img src="http://joelbennett.net/wordpress/wp-content/uploads/2012/01/Show-Help-Mini.png" alt="Click to see full screen-shot" title="Show-Help" width="630" height="486" class="alignright size-full wp-image-1804" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/rich-formatting-for-powershell-help/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Did you know PowerShell can use Selenium?</title>
		<link>http://huddledmasses.org/did-you-know-powershell-can-use-selenium/</link>
		<comments>http://huddledmasses.org/did-you-know-powershell-can-use-selenium/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 05:46:42 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Automation]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[WatiN]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1789</guid>
		<description><![CDATA[This is sort-of a place-holder for a full-length post that I really ought to write about driving web testing from PowerShell using Selenium. I actually have a little module around for doing that with WaTiN, but honestly the Selenium project seems to be a lot more active, and has quite a bit of muscle behind ...<a class="post-readmore" href="http://huddledmasses.org/did-you-know-powershell-can-use-selenium/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p>This is sort-of a place-holder for a full-length post that I really ought to write about driving web testing from PowerShell using Selenium.  I actually have a little module around for doing that with WaTiN, but honestly the Selenium project seems to be a lot more active, and has quite a bit of muscle behind it since they&#8217;ve merged with WebDriver&#8230;</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;">-path</span> ~\Downloads\selenium<span style="color: #66cc66;">-</span>dotnet<span style="color: #66cc66;">-</span>2.16.0\net40\WebDriver.<span style="color: #003366;">dll</span> <br />
<br />
<span style="color: #666666; font-style: italic;"># Navigate to google in IE (or Firefox, Chrome, Opera, etc)</span><br />
<span style="color: #660033; font-weight: bold;">$driver</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> OpenQA.<span style="color: #003366;">Selenium</span>.<span style="color: #003366;">IE</span>.<span style="color: #003366;">InternetExplorerDriver</span> <br />
<span style="color: #660033; font-weight: bold;">$driver</span>.<span style="color: #003366;">Url</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;http://google.com&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Type PowerShell into the query box, the page will update via AJAX</span><br />
<span style="color: #666666; font-style: italic;"># Note we won't hit enter or anything</span><br />
<span style="color: #660033; font-weight: bold;">$q</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$driver</span>.<span style="color: #003366;">FindElementByname</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;q&quot;</span><span style="color: #333;">&#41;</span> <br />
<span style="color: #660033; font-weight: bold;">$q</span>.<span style="color: #003366;">SendKeys</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;PowerShell&quot;</span><span style="color: #333;">&#41;</span> <br />
<br />
<span style="color: #666666; font-style: italic;"># Use a CSS selector to find the first result link and click it</span><br />
<span style="color: #660033; font-weight: bold;">$driver</span>.<span style="color: #003366;">FindElementByCssSelector</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;li.g h3.r a&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Click</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp;</div>

	<h3>One Catch</h3>

	<p><a href="http://joelbennett.net/wordpress/wp-content/uploads/2012/01/ProtectedMode.png" style="float:right; padding-left: 1em; "><img src="http://joelbennett.net/wordpress/wp-content/uploads/2012/01/ProtectedMode.png" alt="The Security tab of the Internet Options dialog" title="ProtectedMode" width="423" height="541" class="size-full wp-image-1796" /></a>If you try this with IE and you get the error <em>Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones</em> ... it means exactly what it says.  You need to open &#8220;Internet Options&#8221; from your start menu (or from IE), and go through each &#8220;zone&#8221; and set the &#8220;Enabled Protected Mode&#8221; check box to the same value for each zone (either all checked, obviously the most secure, or all unchecked).  I&#8217;m not going to debate whether setting them all <em>unprotected</em> is a good idea &#8230; I set mine to all protected, but I don&#8217;t generally use IE anyway. </p>

	<p>If you want more help, Selenium&#8217;s documentation is great, and there&#8217;s a section on <a href="http://seleniumhq.org/docs/03_webdriver.html#getting-started-with-selenium-webdriver">Getting Started with Selenium WebDriver</a> which I found quite helpful (make sure your examples are in &#8220;csharp&#8221; and you can almost just copy and paste &#8212; someone should offer to do them in PowerShell).  </p>

	<p>If you want more information about the Internet Explorer driver and this problem in particular, the short answer is that &#8220;Protected Mode&#8221; is a security boundry, so if you cross over it the <span class="caps">COM</span> automation object doesn&#8217;t work &#8212; thus, you need to make sure you always stay on the same side. There&#8217;s a good discussion <a href="http://code.google.com/p/selenium/issues/detail?id=1795">on the mailing list archive</a> about how it works and why, as well a weird alternative <a href="http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/ie/InternetExplorerDriver.html#INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS">documented on the Selenium JavaDocs</a></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/did-you-know-powershell-can-use-selenium/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>PowerShell 3 &#8211; Finally on the DLR!</title>
		<link>http://huddledmasses.org/powershell-3-finally-on-the-dlr/</link>
		<comments>http://huddledmasses.org/powershell-3-finally-on-the-dlr/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 05:38:21 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[CTP]]></category>
		<category><![CDATA[DLR]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PS3]]></category>
		<category><![CDATA[Windows 8]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1780</guid>
		<description><![CDATA[For those of you living in a cave: PowerShell 3 will be released in Windows 8, and we got a CTP at roughly the same time as the Windows 8 Developer Preview was released (at Microsoft&#8217;s new //Build/ conference in September 2011). A second CTP was released just in time for Christmas. I&#8217;ve been playing ...<a class="post-readmore" href="http://huddledmasses.org/powershell-3-finally-on-the-dlr/">read more</a>]]></description>
				<content:encoded><![CDATA[	<p class="highlight">For those of you living in a cave: PowerShell 3 will be released in Windows 8, and we got a <acronym title="Community Technology Preview">CTP</acronym> at roughly the same time as the Windows 8 Developer Preview was released (at Microsoft&#8217;s new <a href="https://www.microsoft.com/presspass/events/build/">//Build/</a> conference in September 2011).  A <a href="http://www.microsoft.com/download/en/details.aspx?id=27548">second CTP</a> was released just in time for Christmas.</p>

	<p>I&#8217;ve been playing with PowerShell 3 for a few months now, and I guess it&#8217;s long past time I started blogging about it.</p>

	<p>There are a <strong>lot</strong> of new things coming in this release, but for me, the biggest change is the fact that PowerShell is now based on the <a href="http://dlr.codeplex.com/">Dynamic Language Runtime</a>, a runtime environment that adds a set of services for dynamic languages to the Common Language Runtime (<span class="caps">CLR</span>), which is the core of the .<span class="caps">NET</span> Framework. The <span class="caps">DLR</span> makes it easier to develop dynamic languages to run on the .<span class="caps">NET</span> Framework.  Of course, PowerShell is a dynamic language that runs on the .<span class="caps">NET</span> framework, but it was originally begun before the <span class="caps">DLR</span> had been released, so it&#8217;s only now that it&#8217;s finally been adapted to the <span class="caps">DLR</span>.  </p>

	<p>However, although PowerShell 3 is implemented using the <span class="caps">DLR</span>, it&#8217;s not a <span class="caps">DLR</span> language in every way that IronPython or IronRuby are.  Let me borrow a couple of graphics from the <span class="caps">DLR</span> overview documentation. </p>

	<h3>The <span class="caps">DLR</span> Overview</h3>

	<p><img src="http://joelbennett.net/wordpress/wp-content/uploads/2011/12/DLR.png" title="DLR Overview" alt="DLR Overview" width="628" height="387" /></p>

	<p>You can see there&#8217;s three major sections to the <span class="caps">DLR</span> as it&#8217;s <a href="http://dlr.codeplex.com">available on CodePlex</a>: hosting, runtime, and language.  However, not all of the <span class="caps">DLR</span> actually shipped in the .<span class="caps">NET</span> Framework 4.0 <span class="caps">CLR</span>.</p>

	<h3>The <span class="caps">DLR</span> shipped in <span class="caps">CLR</span> 4</h3>

	<p><img src="http://joelbennett.net/wordpress/wp-content/uploads/2011/12/DLRonCLR4.png" title="DLR Shipped in CLR4" alt="DLR Shipped in CLR4" width="586" height="367" /></p>

	<p>PowerShell 3 takes advantage of all (or most) of what shipped in the <span class="caps">CLR</span>, but since the PowerShell team wasn&#8217;t willing to be responsible for shipping the rest of the <span class="caps">DLR</span> in the operating system, they didn&#8217;t implement the rest of it. Which is to say, PowerShell 3 is using the <span class="caps">DLR</span> Language Implementation code, with Shared <span class="caps">AST</span> and Expression trees, as well as the DynamicObject and Call Site Caching portions of the runtime, but none of the Common Hosting pieces like ScriptRuntime, ScriptScope, ScriptSource, or CompiledCode &#8230;</p>

	<p>This means that you cannot use the same hosting APIs for PowerShell that you use for IronPython or IronRuby.  However, even though you&#8217;re stuck using the same hosting APIs that you used with PowerShell 2 &#8230; you <strong>do</strong> get to use <strong>dynamic</strong> instead of PSObject when you&#8217;re working with the output in C#.</p>

	<h3>This really is a big deal</h3>

	<p>I wouldn&#8217;t care to speculate how many of the changes you&#8217;ll see in PowerShell 3 are directly due to the conversion to the <span class="caps">DLR</span>, but there are a few changes that you ought to be aware of. The first thing that you&#8217;ll probably notice is the difference in execution and performance. Anything you&#8217;ve learned about the relative performance of Scripts vs. Functions vs. Cmdlets and the load time of binary vs. script modules is going to go right out the window with PowerShell 3, as scripts and functions are now no longer (re)interpreted each time they&#8217;re run, but are <em>compiled</em>, executed, and (sometimes) cached.  The result is that initial runs of scripts and imports of script modules are sometimes slower than they used to be, but subsequent runs of the same script or execution of functions from script modules run much faster, and this applies in particular to actual scripts in files and pre-defined functions in modules.  Running a function repeatedly is now <em>much faster</em> than pasting the same code repeatedly into the console.</p>

	<h4>A more subtle, but significant difference is the change to PSObject.  </h4>

	<p>In PowerShell 3, PSObject is a true dynamic object, and thus the output of cmdlets or scripts called in C# can be used with the dynamic keyword in C# instead of with the pseduo-reflection methods which are required for working with PSObject.  However, this is just the tip of the iceberg, so to speak.  </p>

	<p>In PowerShell 2, all of PowerShell&#8217;s Extended Type System (<span class="caps">ETS</span>) was based on PSObject. New members were always added to a PSObject which is wrapped around the actual &#8220;BaseObject&#8221; &#8212; regardless of whether they came from a types.ps1xml file, or from calling Add-Member on an object.  If you use Add-Member on strongly objects that are not already wrapped in a PSObject, you have to specify the <code>-Passthru</code> parameter and capture the output in order to have your object wrapped into a PSObject that the new member can be added to. In addition, when you cast an object to a specific type, those <span class="caps">ETS</span> members are mostly lost. Take this script for example:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$psObject</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span><br />
<span style="color: #660033; font-weight: bold;">$psObject</span>.<span style="color: #003366;">Count</span><br />
<span style="color: #660033; font-weight: bold;">$Count1</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$psObject</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">where</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">PSIsContainer</span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Count</span><br />
<br />
<span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">FileSystemInfo</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;">$ioObject</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span><br />
<span style="color: #660033; font-weight: bold;">$ioObject</span>.<span style="color: #003366;">Count</span><br />
<span style="color: #660033; font-weight: bold;">$Count2</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$ioObject</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">where</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">PSIsContainer</span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Count</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$Count3</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$ioObject</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">where</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #000066;">-is</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">DirectoryInfo</span><span style="color: #333;">&#93;</span></span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">Count</span><br />
&nbsp;</div>

	<p>In PowerShell 2, <code>$Count1</code> and <code>$Count3</code> will be the number of folders in the current directory, but <code>$Count2</code> will always be <span class="caps">ZERO</span>, because the PSIsContainer property is actually an <span class="caps">ETS</span> property that&#8217;s lost when you cast the object to <code>FileSystemInfo</code> (and therefore it always evaluates as null and </p>

	<p>However, in PowerShell 3 that&#8217;s no longer true.  PowerShell now works with everything as dynamic objects, and Add-Member no longer needs the PSObject to keep track of these <span class="caps">ETS</span> members. This script will now get <code>$Count1</code>, <code>$Count2</code>, and <code>$Count3</code> equal, as expected. Obviously the <code>-Passthru</code> switch on <code>Add-Member</code> is only needed when you&#8217;re trying to pipeline things, and not for simple assignments.  However, there may also be other implications on when things get wrapped into a PSObject, and when it matters.  </p>

	<p>I think you&#8217;ll agree that having PowerShell on the <span class="caps">DLR</span> is awesome! But be aware that there are a few inconsequential <em>breaking changes</em> hiding in this kind of stuff.  For example, after running that script above, try these three lines on PowerShell 2 and PowerShell 3 CTP2:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$Count1</span> <span style="color: #000066;">-eq</span> <span style="color: #660033; font-weight: bold;">$Count2</span><br />
<span style="color: #660033; font-weight: bold;">$e</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$ioObject</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span> NoteProperty Note <span style="color: #009900;">&quot;This is a note&quot;</span> <span style="color: #000066;">-Passthru</span><br />
<span style="color: #660033; font-weight: bold;">$f</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$ioObject</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Member</span></span> NoteProperty Note <span style="color: #009900;">&quot;This is a note&quot;</span> <span style="color: #000066;">-Passthru</span><br />
&nbsp;</div>

	<p>In PowerShell 2, you&#8217;ll get <code>False</code>, and then the next two lines will work fine.  In PowerShell 3 the first line will return <code>True</code>, and since Add-Member actually affects the underlying object even when it&#8217;s not wrapped in a PSObject, the third line will actually <strong>cause an error</strong>, because &#8220;Add-Member : Cannot add a member with the name &#8220;Note&#8221; because a member with that name already exists.&#8221;</p>

	<p>Anyway, I&#8217;m sure I&#8217;ll have more to write about the <span class="caps">DLR</span> and the changes it&#8217;s bringing to PowerShell, but for now, I hope that&#8217;s enough to get you thinking  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';-)' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-3-finally-on-the-dlr/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
