<?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>Fri, 27 Apr 2012 05:42:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<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 [...]]]></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 [...]]]></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 [...]]]></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[Browser]]></category>
		<category><![CDATA[GUI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[WatiN]]></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 [...]]]></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 [...]]]></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>
		<item>
		<title>Arrange &#8211; Act &#8211; Assert: Intuitive Testing</title>
		<link>http://huddledmasses.org/arrange-act-assert-intuitive-testing/</link>
		<comments>http://huddledmasses.org/arrange-act-assert-intuitive-testing/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 03:31:56 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[3As]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1757</guid>
		<description><![CDATA[Today I have a new module to introduce you to. It&#8217;s a relatively simple module for testing, and you can pick it up in short order and start testing your scripts, modules, and even compiled .Net code. If you put it together with WASP you can pretty much test anything The basis for the module [...]]]></description>
			<content:encoded><![CDATA[	<p>Today I have a new module to introduce you to. It&#8217;s a relatively simple module for testing, and you can pick it up in short order and start testing your scripts, modules, and even compiled .Net code. If you put it together with <a href="http://poshcode.org/2483" title="my UI Automation module">WASP</a> you can pretty much test anything  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=';-)' class='wp-smiley' /> </p>

	<p>The basis for the module is the arrange-act-assert model of testing. First we <strong>arrange</strong> the things we&#8217;re going to test: set up data structures or whatever you need for testing. Then we <strong>act</strong> on them: we perform the actual test steps. Finally, we <strong>assert</strong> the expected output of the test. Normally, the expectation is that during the assert step we&#8217;ll return <code>$false</code> if the test failed, and that&#8217;s all there is to it. Of course, there&#8217;s plenty more to testing, but lets move on to my new module.</p>

	<p>The module is called <a href="/downloads/PSaint.7z">PSaint</a> (pronounced &#8220;saint&#8221;), and it stands, loosely, for PowerShell Arrange-Act-Assert in testing. Of course, what it stands for isn&#8217;t important, just remember the name is PSaint  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> </p>

	<p>PSaint is really a very simple module, with only a few functions. There are two major functions which we&#8217;ll discuss in detail: Test-Code and New-RhinoMock, and then a few helpers which you may or may not even use:</p>

	<h3>Set-TestFilter </h3>

	<p>Sets filters (include and/or exclude) for the tests by name or category.</p>

	<h3>Set-TestSetup (alias &#8220;Setup&#8221;)</h3>

	<p>Sets the test setup ScriptBlock which will be run before each test.</p>

	<h3>Set-TestTeardown (alias &#8220;Teardown&#8221;)</h3>

	<p>Sets the test teardown ScriptBlock which will be run after each test.</p>

	<h3>Assert-That</h3>

	<p>Assserts something about an object (or the output of a scriptblock) and throws if that assertion is false.  This function supports asserting that an exception should be thrown, or that a test is false &#8230; and supports customizing the error message as well.</p>

	<h3>Assert-PropertyEqual</h3>

	<p>This is a wrapper around Compare-Object to compare the properties of two objects.</p>

	<h2>How to test with PSaint: Test-Code</h2>

	<p>Test-Code (alias &#8220;Test&#8221;) is the main driver of functionality in PSaint, and you use it to define the tests that you want to run.  Let&#8217;s jump to an example or two so you can see the usefulness of this module.</p>

	<p>Let&#8217;s start with an extremely simple function that we want to write: New-Guid.  We want a function that generates a valid random <span class="caps">GUID</span> as a string. We&#8217;ll start by writing a couple of tests. First we&#8217;ll test that the output of the function is a valid <span class="caps">GUID</span>.</p>

	<div class="posh code posh" style="font-family:monospace;">test <span style="color: #009900;">&quot;New-Guid outputs a Guid&quot;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;act <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guid</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Guid</span></span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;assert <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guid</span> <span style="color: #000066;">-is</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> Guid <span style="color: #660033; font-weight: bold;">$guid</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Now, to verify that the test works, you should define this function (the GUID-looking thing is one letter short) and then run that test:</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;">New-<span style="font-style: normal;">Guid</span></span> <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Another proof that it works would be that it should fail on this function too, because &#8220;x&#8221; is not a valid character in a Guid:</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;">New-<span style="font-style: normal;">Guid</span></span> <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>So, let&#8217;s write a minimal New-Guid that actually generates a valid Guid:</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;">New-<span style="font-style: normal;">Guid</span></span> <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>If you run our test on that, you will see:</p>

	<div class="text code text" style="font-family:monospace;">&nbsp; &nbsp;Result: Pass<br />
<br />
Result Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Category<br />
------ ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--------<br />
Pass &nbsp; New-Guid outputs a Guid<br />
&nbsp;</div>

	<p>If you don&#8217;t like the fact that the Category is empty, you could add a category or two to the end of our test.  We should also switch to using Assert-That if we want to know which test in the assert failed. Finally, we want to write another test which would test that New-Guid doesn&#8217;t just return the same Guid every time, the way ours does right now:</p>

	<div class="posh code posh" style="font-family:monospace;">test <span style="color: #009900;">&quot;New-Guid outputs a Guid&quot;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;act <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guid</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Guid</span></span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;assert <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Assert-<span style="font-style: normal;">That</span></span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$guid</span> <span style="color: #000066;">-is</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span> <span style="color: #333;">&#125;</span> <span style="color: #000066;">-FailMessage</span> <span style="color: #009900;">&quot;New-Guid returned a $($guid.GetType().FullName)&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> Guid <span style="color: #660033; font-weight: bold;">$guid</span> &nbsp;<span style="color: #666666; font-style: italic;"># Throws relevant errors already</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Category</span> Output, ValidGuid<br />
<br />
test <span style="color: #009900;">&quot;New-Guid outputs different Guids&quot;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;arrange <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guids</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$count</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">100</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;act <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># generate a bunch of Guids</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>; <span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$count</span>; <span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$guids</span> <span style="color: #66cc66;">+=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Guid</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;assert <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># compare each guid to all the ones after it</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>; <span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$count</span>; <span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$j</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span>; <span style="color: #660033; font-weight: bold;">$j</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$count</span>; <span style="color: #660033; font-weight: bold;">$j</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Assert-<span style="font-style: normal;">That</span></span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$guids</span><span style="color: #333;">&#91;</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$guids</span><span style="color: #333;">&#91;</span><span style="color: #660033; font-weight: bold;">$j</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-FailMessage</span> <span style="color: #009900;">&quot;There were equal Guids: $($guids[$i])&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Category</span> Output, RandomGuids<br />
&nbsp;</div>

	<p>Now, we have to actually fix our New-Guid function to generate real random Guids:</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;">New-<span style="font-style: normal;">Guid</span></span> <span style="color: #333;">&#123;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Guid</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">NewGuid</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>And at that point, we should have a function, and a couple of tests that verify it&#8217;s functionality&#8230;</p>

	<h3>The finer points of assertions</h3>

	<p>One thing you&#8217;ll notice the first time you use Get-Member after loading the PSaint module is a few script properties have been added to everything.  I did this because I found myself writing the same Assert-That calls over and over and decided that it would be slicker to make these extension methods than to write new functions for each one:</p>

	<div class="posh code posh" style="font-family:monospace;">MustBeA<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;">Type</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Expected</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;">$Message</span><span style="color: #333;">&#41;</span><br />
MustBeFalse<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;">$Message</span><span style="color: #333;">&#41;</span><br />
MustBeTrue<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;">$Message</span><span style="color: #333;">&#41;</span><br />
MustEqual<span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Object<span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Expected</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;">$Message</span><span style="color: #333;">&#41;</span><br />
MustNotEqual<span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Object<span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Expected</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;">$Message</span><span style="color: #333;">&#41;</span><br />
&nbsp;</div>

	<p>There&#8217;s also a <span style="font-family:monospace;">MustThrow<span style="color: #333;">(</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">[</span><span style="color: #003366; font-weight: bold;">Type</span><span style="color: #333;">]</span></span><span style="color: #660033; font-weight: bold;">$Expected</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">[</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">]</span></span><span style="color: #660033; font-weight: bold;">$Message</span><span style="color: #333;">)</span></span> which can be used on script blocks (note that this function executes the ScriptBlock immediately, so be careful how you use it).</p>

	<p>We can use these to tidy up our tests quite a bit, while still getting good error messages when tests fail:</p>

	<div class="posh code posh" style="font-family:monospace;">test <span style="color: #009900;">&quot;New-Guid outputs a Guid String&quot;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;act <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guid</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Guid</span></span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;assert <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guid</span>.<span style="color: #003366;">MustBeA</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: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> Guid <span style="color: #660033; font-weight: bold;">$guid</span> <span style="color: #666666; font-style: italic;"># Throws relevant errors already</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Category</span> Output, ValidGuid<br />
<br />
test <span style="color: #009900;">&quot;New-Guid outputs different Guids&quot;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;arrange <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guids</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$count</span> <span style="color: #66cc66;">=</span> <span style="color: #cc66cc;">100</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;act <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># generate a bunch of Guids</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>; <span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$count</span>; <span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$guids</span> <span style="color: #66cc66;">+=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Guid</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;assert <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># compare each guid to all the ones after it</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">=</span><span style="color: #cc66cc;">0</span>; <span style="color: #660033; font-weight: bold;">$i</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$count</span>; <span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">for</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$j</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #66cc66;">+</span><span style="color: #cc66cc;">1</span>; <span style="color: #660033; font-weight: bold;">$j</span> <span style="color: #000066;">-lt</span> <span style="color: #660033; font-weight: bold;">$count</span>; <span style="color: #660033; font-weight: bold;">$j</span><span style="color: #66cc66;">++</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$guids</span><span style="color: #333;">&#91;</span><span style="color: #660033; font-weight: bold;">$i</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">MustNotEqual</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$guids</span><span style="color: #333;">&#91;</span><span style="color: #660033; font-weight: bold;">$j</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-Category</span> Output, RandomGuids<br />
&nbsp;</div>

	<h3><span class="caps">COM</span> Objects </h3>

	<p>PSaint also has a wrapper for <span class="caps">COM</span> objects to help with testing them. It adds GetProperty and SetProperty methods to allow you to access <span class="caps">COM</span> object properties which don&#8217;t show up on boxed <span class="caps">COM</span> objects (a common problem when working with MSOffice, for instance).  It also adds InvokeMethod for <span class="caps">COM</span> objects to invoke methods that don&#8217;t show up for similar reasons.  These, of course, only help you if you&#8217;re already fairly literate with the <span class="caps">COM</span> object in question.</p>

	<h3>Mock Objects</h3>

	<p>PSaint includes New-RhinoMock, a function for generating a new mock object using <a href="http://hibernatingrhinos.com/open-source/rhino-mocks">RhinoMocks</a> (which is included).  Rhino Mocks is a BSD-licensed dynamic mock object framework for the .Net platform. Its purpose is to ease testing by allowing the developer to create mock implementations of custom objects and verify the interactions using unit testing.</p>

	<p>I have to admit that this New-RhinoMock function is incomplete, and exposes only a fraction of the options and power in RhinoMocks, but it&#8217;s been sufficient for the few times when I&#8217;ve wanted to actually mock objects from PowerShell, so I&#8217;m including it here.</p>

	<p>For those of you (developers) who want to know why RhinoMocks instead of your favorite mocking framework, the answer is astonishingly simple: it had the least number of necessary generic methods (which are impossible to call in PowerShell 2).</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/arrange-act-assert-intuitive-testing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ramblings about computer markets &#8230;</title>
		<link>http://huddledmasses.org/ramblings-about-computer-markets/</link>
		<comments>http://huddledmasses.org/ramblings-about-computer-markets/#comments</comments>
		<pubDate>Tue, 04 Oct 2011 04:30:29 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[BusinessModel]]></category>
		<category><![CDATA[Capitalism]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1762</guid>
		<description><![CDATA[This is what I call a stream of consciousness, edited. Please don&#8217;t rip my head off, call me names, etc. Microsoft is a product of the commodity hardware era. That is, Microsoft is a company that couldn&#8217;t have existed previously, in an era where computers cost tens of thousands of dollars (or hundreds of thousands [...]]]></description>
			<content:encoded><![CDATA[	<p>This is what I call a stream of consciousness, edited.  Please don&#8217;t rip my head off, call me names, etc.</p>

	<h3>Microsoft is a product of the commodity hardware era.  </h3>

	<p>That is, Microsoft is a company that couldn&#8217;t have existed previously, in an era where computers cost tens of thousands of dollars (or hundreds of thousands of dollars).  When the computers themselves were expensive, the hardware was the item of value.  </p>

	<h3>There was only one business model.</h3>

	<p>Companies producing them were not thinking about the software running on them as valuable (and even missed patenting things like windowed interfaces, pointing devices, and networking protocols), because they through the valuable thing would be the hardware forever.</p>

	<h3>Modern business models for personal computing.</h3>

	<p>In the modern era, we have three major business models:  hardware, software, service.</p>

	<p>Apple represents the hardware model: they&#8217;re making <strong>billions</strong> selling top-end hardware (phones, laptops, computers, tablets). They&#8217;re basically giving away their software. They&#8217;re trying to commodify the software &#8212; making it trivial and making it easier for thousands of companies and even individuals to produce competing versions of every possible application <em>on their hardware</em>.</p>

	<p>Microsoft represents the software model: they&#8217;re making <strong>billions</strong> selling software licenses for software that runs <em>on any kind of hardware</em>. They&#8217;re actively trying to commodify hardware, making their software run on any kind of hardware from hundreds of manufacturers, and driving prices of home computers, netbooks, and tablets down to a couple of hundred dollars.</p>

	<p>RedHat (and Linux vendors in general) represents the service model: they&#8217;re making <strong>millions</strong> selling service contracts for <em>free</em> software that runs on that same really cheap hardware that Microsoft&#8217;s model has been driving.</p>

	<h3>How might that affect service, software, and hardware?</h3>

	<p>It wouldn&#8217;t be any surprise if <em>service</em> companies didn&#8217;t care much about how user friendly the software is: after all, they only make money if you need support to use it.</p>

	<p>It would also not be surprising if <em>software</em> companies didn&#8217;t care how confusing the hardware choices are &#8212; they want to make sure that there are <em>lots</em> of hardware companies, because that&#8217;s how you maintain the commodity status of the hardware.</p>

	<p>And of course, it wouldn&#8217;t be a surprise if <em>hardware</em> companies made high end hardware, released their software updates freely or cheaply, treating the software like firmware designed to run only on their specific hardware models.  These companies <em>might</em> have the lowest barriers to switching hardware architectures and creating new hardware form factors, since they&#8217;re providing a stand-alone platform (the software is like firmware) without much regard for disruption of software platforms.</p>

	<h3>Which market is easier to enter?</h3>

	<p>It seems to me like the most sustainable of these models, and more importantly, the most favorable to the consumer &#8230; is the software model.  I prefer business models which encourage competition, and I think that hardware and service models do not.</p>

	<p>On the one hand it&#8217;s easier to grow a software company than it is to grow a new service company.  It&#8217;s very hard to compete with the big guys on service because of reach (you can&#8217;t provide world-wide service), and as a result, very few service companies make it past the mom-and-pop size to medium-sized businesses employing more than 10 people.</p>

	<p>On the other hand, it&#8217;s easier to create a new software company than it is to create a new hardware company. It&#8217;s very hard to compete with the big guys on hardware because of costs (you can&#8217;t get hardware costs down without substantial volume).</p>

	<p>You only have to look at the past few years to see that it takes a long time for a new hardware company to grow to a useful size, and that service companies tend to consolidate long before they become competitive.</p>

	<h3>But you&#8217;re not taking X into account</h3>

	<p>Of <em>course</em>, this is a fairly simple interpretation of the personal computer marketplace.  I know that. Tell me something I don&#8217;t know below.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/ramblings-about-computer-markets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with multiple versions of PowerShell Modules</title>
		<link>http://huddledmasses.org/working-with-multiple-versions-of-powershell-modules/</link>
		<comments>http://huddledmasses.org/working-with-multiple-versions-of-powershell-modules/#comments</comments>
		<pubDate>Wed, 31 Aug 2011 04:14:45 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Versioning]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1744</guid>
		<description><![CDATA[What follows is a brief explanation of modules, followed by an explanation of how I handle multiple versions of a module. My way isn&#8217;t the only way &#8212; and I&#8217;m rather annoyed that I have to do it &#8212; but it works, and might help someone, so here it is. Some back-story During development of [...]]]></description>
			<content:encoded><![CDATA[	<p>What follows is a brief explanation of modules, followed by an explanation of how <strong>I</strong> handle multiple versions of a module. My way isn&#8217;t the only way &#8212; and I&#8217;m <em>rather annoyed</em> that I have to do it &#8212; but it works, and might help someone, so here it is.</p>

	<h2>Some back-story</h2>

	<p>During development of a PowerShell module like <a href="http://ShowUI.CodePlex.com">ShowUI</a>, I am usually <strong>not</strong> using a released version of the module, since I&#8217;m obviously working on the next version. In addition, sometimes I need to have &#8220;beta&#8221; and &#8220;stable&#8221; releases &#8230; so I might have two or three versions of the module that I need to be able to load in order to support users and actually do development.</p>

	<p>In case you don&#8217;t know how modules work, here&#8217;s the deal: There&#8217;s an environment variable <code>PSModulePath</code>. It&#8217;s just like the <code>Path</code> environment variable, but for modules. The variable contains a semi-colon delimited list of folders paths, which PowerShell searches for modules.  Some people think of a PowerShell module as basically a .dll (binary module), a .psm1 (script module), or a .psd1 (manifest module)... but it&#8217;s never <em>just</em> a file, it&#8217;s a <em>*Folder* and a file</em>.  In order for PowerShell to find ShowUI when you write <code>Import-Module ShowUI</code>, you have to have a <strong>Folder</strong> in the PSModulePath named &#8220;ShowUI&#8221; and in it, a file (either .dll, .psm1, or .psd1) also named ShowUI.</p>

	<h3>What I would <em>like</em></h3>

	<p>The Import-Module command has a -Version parameter. What I expected What I would <em>like</em> to be able to do is create a folder &#8220;ShowUI&#8221; and in there, create folders &#8220;1.0&#8221; and &#8220;1.1&#8221; and &#8220;1.2&#8221; and then be able to use <code>Import-Module ShowUI -Version 1.1</code> to load a specific version. </p>

	<p>Sadly, this doesn&#8217;t work. First of all, the -Version parameter on Import-Module, is a <strong>minimum</strong> only. Additionally, Import-Module requires the file and folder to match names exactly, so putting the module inside a subfolder doesn&#8217;t work even if there&#8217;s only one.</p>

	<p>However, there are two things we can use to fix our problem:</p>

	<p>1. Just like the <span class="caps">PATH</span> variable, PSModulePath works in order. PowerShell searches the listed paths one at a time and uses the first Module that meets the specified minimimum version.<br />
2. Additionally, PowerShell allows you to specify a relative Path to a module that starts in a PSModulePath &#8230; I&#8217;ll explain more in a moment.</p>

	<h2>My <em>actual</em> working environment</h2>

	<p>All of my development projects are in $Home\Projects, so I put a &#8220;Modules&#8221; folder in there which is where I put modules that I&#8217;m actively working on.  Then I add that folder to my PSModulePath environment variable: @$Env:PSModulePath += &#8220;;$Home\Projects&#8221; ...</p>

	<p>Since I put it on the end, modules in there won&#8217;t be imported if there&#8217;s a module with the same name in my regular Module folder ( $Home\Documents\WindowsPowerShell\Modules ), <strong>unless</strong> I increment the version number in the psd1 metadata file and specify -Version when importing.</p>

	<p>For example, I have two copies of WASP:</p>

	<p>$Home\Documents\WindowsPowerShell\Modules\WASP\Wasp.psd1  (version 1.0)<br />
$Home\Projects\Modules\WASP\Wasp.psd1 (version 2.0.0.2)</p>

	<p>If I want to load the released version, I can just <code>Import-Module WASP</code> &#8212; this ensures that scripts that I have in my scripts folder generally load the released version of <span class="caps">WASP</span>.  When I want to load the development version, I can <code>Import-Module WASP -Version 2.0</code>, and get the version from my Projects folder, because the released version&#8217;s version number is lower than 2.0.</p>

	<h2>More layers onion boy?</h2>

	<p>When I need to have more than one older version, this presents a problem, because I would need another folder in my path, and for the numbering scheme to work despite the fact that -Version is only a minimum value, I would need the released version (say 1.0) to come first in the path, then the beta version (say 2.0.1), then the development version (say 2.1) ... which means I&#8217;d need to add a $Home\Projects\BetaReleaseModules or something like that, and put it in my PSModulePath before the $Home\Projects\Modules folder.  That would work, but you can imagine that it wouldn&#8217;t scale very well.</p>

	<p>Here&#8217;s what I do: past the release and development versions, I start creating folders like this:</p>

	<p>$Home\Documents\WindowsPowerShell\Modules\ShowUI1.0\ShowUI.psd1  (version 1.0)<br />
$Home\Documents\WindowsPowerShell\Modules\ShowUI\ShowUI.psd1  (Release version: 1.1)<br />
$Home\Documents\WindowsPowerShell\Modules\ShowUI1.1\ShowUI.psd1  (Release version: 1.1)<br />
$Home\Documents\WindowsPowerShell\Modules\ShowUI1.2\ShowUI.psd1  (Beta version 1.2)<br />
$Home\Projects\Modules\ShowUI\ShowUI.psd1 (Development version 1.3)</p>

	<p>Now, if I <code>Import-Module ShowUI</code>, I&#8217;ll get 1.1 and if I specify <code>Import-Module ShowUI -Version 1.2</code> I&#8217;ll get &#8230; version 1.3 (<em>whoops</em>).</p>

	<p>To load ShowUI 1.2 with that structure I have to do this: <code>Import-Module ShowUI1.2\ShowUI</code> &#8212; specifying the folder name <strong>and</strong> the module name.  Of course, I could use &#8220;ShowUIBeta&#8221; as the folder name instead, but usually when I get a request for help writing scripts, I can get people to give me the specific version that they&#8217;re working with, so I like the numbered folders instead.  </p>

	<p>A last important note is that I <strong>do not</strong> rename the psd1 or anything else.  </p>

	<p>I <em>could</em> rename the metadata file to $Home\Documents\WindowsPowerShell\Modules\ShowUI1.2\ShowUI1.2.psd1 and then I&#8217;d be able to <code>Import-Module ShowUI1.2</code>, but there&#8217;s a catch.  If I rename it, then I&#8217;ve renamed the module.  If I leave the metadata file as &#8220;ShowUI.psd1&#8221; then <em>once I&#8217;ve imported the module</em> I can call <code>Get-Module ShowUI</code> or <code>Get-Command -Module ShowUI</code> and they still work as they should.</p>

	<p>In any case, this folder-naming stuff is less than ideal and will hopefully be fixed in a future release of PowerShell, but with a &#8220;Projects\Modules&#8221; folder I can have two versions, and usually a development and release version is enough.  Personally, I keep old releases of major modules around in numbered folders just in case, but I rarely actually use them.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/working-with-multiple-versions-of-powershell-modules/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More ShowUI Widgets</title>
		<link>http://huddledmasses.org/more-showui-widgets/</link>
		<comments>http://huddledmasses.org/more-showui-widgets/#comments</comments>
		<pubDate>Wed, 20 Jul 2011 05:49:37 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Clock]]></category>
		<category><![CDATA[Gadgets]]></category>
		<category><![CDATA[ShowUI]]></category>
		<category><![CDATA[Widgets]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1735</guid>
		<description><![CDATA[Well, I got so many tweets and comments on IRC about my ShowUI clock that I figured I&#8217;d share a few other widgets I had lying around &#8230; but first, an update to New-UIWidget: function New-UIWidget &#123; &#91;CmdletBinding&#40;&#41;&#93; param&#40; &#160; &#160; &#91;ScriptBlock&#93;$Content, &#160; &#160; &#91;Alias&#40;&#34;Refresh&#34;&#41;&#93; &#160; &#160; &#91;TimeSpan&#93;$Interval = &#34;0:0:2&#34;, &#160; &#160; &#91;ScriptBlock&#93;$UpdateBlock, &#160; &#160; [...]]]></description>
			<content:encoded><![CDATA[	<p>Well, I got so many tweets and comments on <span class="caps">IRC</span> about <a href="http://huddledmasses.org/the-obligatory-showui-clock/">my ShowUI clock</a> that I figured I&#8217;d share a few other widgets I had lying around &#8230; but first, an update to New-UIWidget:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">UIWidget</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><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Content</span>,<br />
&nbsp; &nbsp; <span style="color: #333;">&#91;</span>Alias<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;Refresh&quot;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>TimeSpan<span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;0:0:2&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$UpdateBlock</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Show</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$AsJob</span><br />
<span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$WidgetValues</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; AllowsTransparency <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; WindowStyle <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;None&quot;</span> <br />
&nbsp; &nbsp; ShowInTaskbar <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; Background <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Transparent&quot;</span> <br />
&nbsp; &nbsp; On_MouseLeftButtonDown <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; On_Closing <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Stop</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; Tag <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;UpdateBlock&quot;</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$UpdateBlock</span>;<span style="color: #009900;">&quot;Interval&quot;</span><span style="color: #66cc66;">=</span><span style="color: #660033; font-weight: bold;">$Interval</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; SizeToContent <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;WidthAndHeight&quot;</span><br />
&nbsp; &nbsp; ResizeMode <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;NoResize&quot;</span><br />
&nbsp; &nbsp; On_SourceInitialized <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #003366;">Clock</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> Windows.<span style="color: #003366;">Threading</span>.<span style="color: #003366;">DispatcherTimer</span><span style="color: #333;">&#41;</span>.<span style="color: #003366; font-weight: bold;">PSObject</span>.<span style="color: #003366;">BaseObject</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #003366;">Clock</span>.<span style="color: #003366;">Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">Interval</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">EventHandler</span></span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #003366;">Clock</span> Tick <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span>.<span style="color: #003366;">UpdateBlock</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #003366;">Clock</span>.<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Null</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; On_ContentRendered <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$UpdateBlock</span> &nbsp; <br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Window</span></span> @WidgetValues <span style="color: #000066;">-Content</span> <span style="color: #660033; font-weight: bold;">$Content</span> <span style="color: #000066;">-Show</span>:<span style="color: #660033; font-weight: bold;">$Show</span> <span style="color: #000066;">-AsJob</span>:<span style="color: #660033; font-weight: bold;">$AsJob</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>Basically I just switched it to use Add-EventHandler, which in ShowUI does at <strong>lot</strong> of awesome magic to make sure all the variables you would want (i.e.: variables for named controls) are defined in your event handler.  It makes writing these gadgets much easier. Here are a few:</p>

	<p>Let&#8217;s start with the simplest Widget I can dream up:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">UIWidget</span></span> <span style="color: #333;">&#123;</span> Label <span style="color: #000066;">-Name</span> Time <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">48</span> <span style="color: #333;">&#125;</span> <span style="color: #009900;">&quot;0:0:0.2&quot;</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Time</span>.<span style="color: #003366;">Content</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span> <span style="color: #000066;">-f</span> <span style="color: #009900;">&quot;h:mm tt&quot;</span><span style="color: #333;">&#125;</span></div>

	<p>Yeah, just a simple text clock. To be honest, that&#8217;s a bit plain for me &#8230; but I do like digital. </p>

	<h3>Another few Clocks</h3>

	<p>My preference is for something very large, with the date and stuff on it:<br />
<img src="/images/ShowUI/Widget-DigiClock.png" alt="" /><br />
<script type="text/javascript" src="http://PoshCode.org/embed/2808"></script></p>

	<p>If you prefer analog clocks, this one has &#8220;hands&#8221; and old school stopped movement (no click sound, but maybe <em>you</em> could add that)...<br />
<img src="/images/ShowUI/Widget-HandsClock.png" alt="" /><br />
<script type="text/javascript" src="http://PoshCode.org/embed/2806"></script></p>

	<p>And finally, while I&#8217;m on the subject, the clock from yesterday could be a lot simpler if it didn&#8217;t need animation, here&#8217;s the target part of it. Feel free to explore.<br />
<img src="/images/ShowUI/Widget-TargetClock1.png" alt="" /><br />
<script type="text/javascript" src="http://PoshCode.org/embed/2807"></script></p>

	<h3>And now for something completely different</h3>

	<p>My other favorite widget to implement in new UI frameworks is a weather widget. Why? Well, mostly because it requires parsing an <span class="caps">RSS</span> feed and a few extra pieces of work that let you actually determine how hard it&#8217;s going to be to write more advanced UI. In any case, here&#8217;s my ShowUI weather widget (note that you have to change the <code>$woEID</code> to get your forecast):<br />
<img src="/images/ShowUI/Widget-Weather.png" alt="" /><br />
<script type="text/javascript" src="http://PoshCode.org/embed/2809"></script></p>

	<p>OK, that&#8217;s enough for one night, but I&#8217;ll take requests for tomorrow! As a side note, you know the cool thing about these gadgets? When I took the screenshots, those were all running from the same PowerShell window <code>-AsJob</code>s, and using less than 1% <span class="caps">CPU</span>.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/more-showui-widgets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Obligatory ShowUI Clock</title>
		<link>http://huddledmasses.org/the-obligatory-showui-clock/</link>
		<comments>http://huddledmasses.org/the-obligatory-showui-clock/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 05:44:42 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Animation]]></category>
		<category><![CDATA[ShowUI]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1724</guid>
		<description><![CDATA[Well, it all started when Richard Siddaway posted his PowerShell Clock using raw XAML. Then Doug posted his ShowUI Clock, and after some back and forth on our ShowUI developer mailing list, James Brundage posted a video walkthrough of building his clock &#8230; Now I&#8217;ve dug an old clock of mine out of mothballs and [...]]]></description>
			<content:encoded><![CDATA[	<p>Well, it all started when Richard Siddaway posted his <a href="http://msmvps.com/blogs/richardsiddaway/archive/2011/07/07/a-powershell-clock.aspx">PowerShell Clock</a> using raw <span class="caps">XAML</span>. Then <a href="http://www.dougfinke.com/blog/index.php/2011/07/13/updated-hippy-dippy-powershell-clock-with-showui/">Doug posted his ShowUI Clock</a>, and after some back and forth on our ShowUI developer mailing list,  <a href="http://www.youtube.com/watch?v=Hqn-b2HMgSM">James Brundage posted a video walkthrough of building his clock</a> &#8230;</p>

	<p>Now I&#8217;ve dug an old clock of mine out of mothballs and updated it to run on ShowUI &#8212; I believe that I&#8217;ve never posted this script before, so I don&#8217;t feel bad at all doing so now, even though I actually wrote it last December (hey, look, I have a <a href="http://huddledmasses.org/images/PowerBoots/Gadget-SuperClock.png">screenshot against my bright red Christmas wallpaper to prove it</a> &#8212; totally random, I know).  Anyway, here&#8217;s the deal: this post was supposed to be written 6 months ago, about building fun UI Widgets in PowerShell, but I never got to it, because we started working on the PowerBoots + <span class="caps">WPK</span> merger we call ShowUI.  So here&#8217;s a fun little function for you:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">UIWidget</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Content</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>TimeSpan<span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;0:0:2&quot;</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ScriptBlock</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$UpdateBlock</span>,<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$Show</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$AsJob</span><br />
<span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #660033; font-weight: bold;">$WidgetValues</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; AllowsTransparency <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; WindowStyle <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;None&quot;</span> <br />
&nbsp; &nbsp; ShowInTaskbar <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; Background <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;Transparent&quot;</span> <br />
&nbsp; &nbsp; On_MouseLeftButtonDown <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">DragMove</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; On_Closing <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Stop</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; Tag <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$UpdateBlock</span>,<span style="color: #660033; font-weight: bold;">$Interval</span><br />
&nbsp; &nbsp; SizeToContent <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;WidthAndHeight&quot;</span><br />
&nbsp; &nbsp; ResizeMode <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;NoResize&quot;</span><br />
&nbsp; &nbsp; On_SourceInitialized <span style="color: #66cc66;">=</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span> <span style="color: #66cc66;">=</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> Windows.<span style="color: #003366;">Threading</span>.<span style="color: #003366;">DispatcherTimer</span><span style="color: #333;">&#41;</span>.<span style="color: #003366; font-weight: bold;">PSObject</span>.<span style="color: #003366;">BaseObject</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Interval</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#93;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Add_Tick</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Window</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Resources</span>.<span style="color: #003366;">Timers</span>.<span style="color: #009900;">&quot;Clock&quot;</span>.<span style="color: #660033;">Start</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Window</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Null</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Window</span></span> @WidgetValues <span style="color: #000066;">-Content</span> <span style="color: #660033; font-weight: bold;">$Content</span> <span style="color: #000066;">-Show</span>:<span style="color: #660033; font-weight: bold;">$Show</span> <span style="color: #000066;">-AsJob</span>:<span style="color: #660033; font-weight: bold;">$AsJob</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>That script is what I use to create little &#8220;gadget&#8221; style windows that are transparent, don&#8217;t show up on the taskbar, but are draggable, and have an automatic update based on a timer.  Now, this is a <strong>very</strong> simple version of the gadgets, without using our PowerShell &#8220;DataSource&#8221; or any data binding at all.  I intend to update this with more functionality one of these days, but this was enough to make my clock work. You can see that basically all it does is sets a bunch of parameters for the Window, including a <code>SourceInitialized</code> event handler, and all the stuff necessary to make it transparent and draggable.</p>

	<p>Now let me post the New-TargetClock funtion, which <strong>depends</strong> on that function, and we&#8217;ll get to explaining it a bit down below.  First, the screenshot, this is what it looks like (with a PowerShell window behind it, instead of that bright red wallpaper):</p>

	<p><img src="/images/ShowUI/TargetClock.png" alt="" /></p>

	<p>And then the actual function:</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">TargetClock</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">param</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #666699; font-weight: bold;">Switch</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$ShowMarks</span><span style="color: #333;">&#41;</span><br />
<br />
<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">UIWidget</span></span> <span style="color: #000066;">-AsJob</span> <span style="color: #000066;">-Content</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; Grid <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$now</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Label</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span>HorizontalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Center&quot;</span>; VerticalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Top&quot;</span>;FontSize<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">25</span>;ZIndex<span style="color: #66cc66;">=</span><span style="color: #cc66cc;">1</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Hours</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Text</span> <span style="color: #660033;">H</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,-5,0,0'</span> <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> White @Label<br />
&nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Name</span> Hours <span style="color: #000066;">-Ov</span> el <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> Black `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">100</span> <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">350</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">350</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashArray</span> &nbsp;<span style="color: #cc66cc;">7.85</span>, <span style="color: #cc66cc;">7.85</span> &nbsp;<span style="color: #000066;">-Opacity</span> <span style="color: #cc66cc;">0.5</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashOffset</span> $<span style="color: #333;">&#40;</span><span style="color: #cc66cc;">7.85</span> <span style="color: #66cc66;">-</span> <span style="color: #333;">&#40;</span><span style="color: #cc66cc;">7.85</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Hour</span> <span style="color: #66cc66;">%</span> <span style="color: #cc66cc;">12</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Minute</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">12</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span> RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">&quot;$(11 - ($now.Hour % 12)):$(59 - $now.Minute):$(60 - $now.Second)&quot;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$el</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Minute</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Text</span> M &nbsp;<span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,20,0,0'</span> <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> White @Label<br />
&nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Name</span> Minutes <span style="color: #000066;">-Ov</span> el <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> Gray `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">75</span> &nbsp;<span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">300</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">300</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashArray</span> &nbsp;<span style="color: #cc66cc;">9.43</span>, <span style="color: #cc66cc;">9.43</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashOffset</span> $<span style="color: #333;">&#40;</span><span style="color: #cc66cc;">9.43</span> <span style="color: #66cc66;">-</span> <span style="color: #333;">&#40;</span><span style="color: #cc66cc;">9.43</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Minute</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Second</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span> RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">&quot;00:$(59 - $now.Minute):$(60 - $now.Second)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$el</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Seconds</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Text</span> S <span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,45,0,0'</span> <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> Gray @Label<br />
&nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Name</span> Seconds <span style="color: #000066;">-Ov</span> el <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> White `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">50</span> &nbsp;<span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">250</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">250</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashArray</span> <span style="color: #cc66cc;">12.57</span>,<span style="color: #cc66cc;">12.57</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-StrokeDashOffset</span> $<span style="color: #333;">&#40;</span><span style="color: #cc66cc;">12.57</span> <span style="color: #66cc66;">-</span> <span style="color: #333;">&#40;</span><span style="color: #cc66cc;">12.57</span> <span style="color: #66cc66;">*</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Second</span><span style="color: #66cc66;">/</span><span style="color: #cc66cc;">60</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span> RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">&quot;00:00:$(60 - $now.Second)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$el</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## These go in the center of the circles (notice the alignment)</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Centered</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span>HorizontalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Center&quot;</span>;VerticalAlignment<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Center&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; StackPanel @Centered <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Time <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> Black <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">30</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;h:mm&quot;</span><span style="color: #333;">&#41;</span> @Centered<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Day <span style="color: #000066;">-FontWeight</span> Normal <span style="color: #000066;">-Foreground</span> Black <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">23</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">DayOfWeek</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span> @Centered<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; StackPanel <span style="color: #000066;">-Orientation</span> Horizontal @Centered <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Date <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> Black <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">18</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">Day</span> <span style="color: #000066;">-Margin</span> <span style="color: #009900;">'0,0,5,0'</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TextBlock <span style="color: #000066;">-Name</span> Month <span style="color: #000066;">-FontWeight</span> ExtraBold <span style="color: #000066;">-Foreground</span> White <span style="color: #000066;">-FontSize</span> <span style="color: #cc66cc;">18</span> `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-Text</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;MMMM&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## Hour marks</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;">$ShowMarks</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">350</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">350</span> <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> White <span style="color: #000066;">-StrokeDashArray</span> <span style="color: #cc66cc;">0.5</span>,<span style="color: #cc66cc;">17.6</span> <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span>RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90.5</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-Opacity</span> <span style="color: #cc66cc;">0.8</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Ellipse <span style="color: #000066;">-Width</span> <span style="color: #cc66cc;">160</span> <span style="color: #000066;">-Height</span> <span style="color: #cc66cc;">160</span> <span style="color: #000066;">-StrokeThickness</span> <span style="color: #cc66cc;">5</span> <span style="color: #000066;">-Fill</span> Transparent <span style="color: #000066;">-Stroke</span> Black <span style="color: #000066;">-StrokeDashArray</span> <span style="color: #cc66cc;">0.5</span>,<span style="color: #cc66cc;">7.62</span> <span style="color: #000066;">-RenderTransformOrigin</span> <span style="color: #009900;">&quot;0.5,0.5&quot;</span> <span style="color: #000066;">-RenderTransform</span> <span style="color: #333;">&#123;</span>RotateTransform <span style="color: #000066;">-Angle</span> <span style="color: #66cc66;">-</span><span style="color: #cc66cc;">90.5</span><span style="color: #333;">&#125;</span> <span style="color: #000066;">-Opacity</span> <span style="color: #cc66cc;">0.8</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #000066;">-UpdateBlock</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$child</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildControl</span></span> <span style="color: #000066;">-Control</span> <span style="color: #660033; font-weight: bold;">$this</span>.<span style="color: #003366;">Tag</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$child</span>.<span style="color: #003366;">Name</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$child</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$now</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span><br />
<br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$now</span>.<span style="color: #003366;">Second</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</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;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">Tag</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-From</span> <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">StrokeDashArray</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">'00:01'</span> <span style="color: #000066;">-RepeatBehavior</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>system.<span style="color: #003366;">windows</span>.<span style="color: #003366;">media</span>.<span style="color: #003366;">animation</span>.<span style="color: #003366;">RepeatBehavior</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Forever</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</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; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Seconds</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<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;">$now</span>.<span style="color: #003366;">Minute</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">0</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</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;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">Tag</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">Tag</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-From</span> <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">StrokeDashArray</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">'01:00'</span> <span style="color: #000066;">-RepeatBehavior</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>system.<span style="color: #003366;">windows</span>.<span style="color: #003366;">media</span>.<span style="color: #003366;">animation</span>.<span style="color: #003366;">RepeatBehavior</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Forever</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</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; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Minutes</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <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;">$now</span>.<span style="color: #003366;">Hour</span> <span style="color: #000066;">-eq</span> <span style="color: #cc66cc;">12</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</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;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">Tag</span> <span style="color: #000066;">-ne</span> <span style="color: #660033; font-weight: bold;">$true</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$true</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #66cc66;">=</span> DoubleAnimation <span style="color: #000066;">-From</span> <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">StrokeDashArray</span><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #333;">&#93;</span> <span style="color: #000066;">-To</span> <span style="color: #cc66cc;">0</span> <span style="color: #000066;">-Duration</span> <span style="color: #009900;">'12:00'</span> <span style="color: #000066;">-RepeatBehavior</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>system.<span style="color: #003366;">windows</span>.<span style="color: #003366;">media</span>.<span style="color: #003366;">animation</span>.<span style="color: #003366;">RepeatBehavior</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Forever</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">BeginAnimation</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>System.<span style="color: #003366;">Windows</span>.<span style="color: #003366;">Shapes</span>.<span style="color: #003366;">Shape</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">StrokeDashOffsetProperty</span>, <span style="color: #660033; font-weight: bold;">$animate</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</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; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Hours</span>.<span style="color: #003366;">Tag</span> &nbsp;<span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$false</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Time</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;h:mm&quot;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Day</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">DayOfWeek</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Date</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">Day</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$children</span>.<span style="color: #003366;">Month</span>.<span style="color: #003366;">Text</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$Now</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;MMMM&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">ToUpper</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
&nbsp;</div>

	<p>What do you think of that?</p>

	<p>The clever part (which, believe me, took a <span class="caps">LOT</span> of experimenting), is that I&#8217;m creating a StrokeDashArray and animating the StrokeDashOffsetProperty in such a way that the &#8220;stroke&#8221; of the Ellipse (the circle of the clock) gets drawn slowly over time (very slowly, in the case of the hour &#8220;hand&#8221;).  Now, as you can see, I&#8217;m still setting up the animations by hand (I just didn&#8217;t convert the code to use <code>Start-Animation</code>), and in the UpdateBlock, I actually reset the animations if they&#8217;re at zero.  I can write more about this if people have questions, but it&#8217;s nearly 2:30am, so I&#8217;ll take questions tomorrow  <img src='http://huddledmasses.org/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> </p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/the-obligatory-showui-clock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

