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

<channel>
	<title>Huddled Masses &#187; PowerShell</title>
	<atom:link href="http://huddledmasses.org/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sun, 14 Mar 2010 04:48:29 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>A DSL for XML in PowerShell: New-XDocument</title>
		<link>http://huddledmasses.org/a-dsl-for-xml-in-powershell-new-xdocument/</link>
		<comments>http://huddledmasses.org/a-dsl-for-xml-in-powershell-new-xdocument/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 05:52:12 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Atom]]></category>
		<category><![CDATA[DSL]]></category>
		<category><![CDATA[Generator]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1406</guid>
		<description><![CDATA[	In July of last year I wrote a PowerShell script with the goal of allowing me to generate XML from PowerShell with a simple markup that would look a little like the resulting XML ... this week I was using that script again, and had a couple of issues that made me go back and [...]]]></description>
			<content:encoded><![CDATA[	<p>In July of last year <a href="http://poshcode.org/1233">I wrote a PowerShell script</a> with the goal of allowing me to generate <span class="caps">XML</span> from PowerShell with a simple markup that would look a little like the resulting <span class="caps">XML</span> ... this week I was using that script again, and had a couple of issues that made me go back and look at the source.</p>

	<p>While I was playing with the source and tweaking things a little bit to improve the way it handles namespaces, I started playing with the idea that I could improve the syntax. At the very least, I thought, I ought to be able to do away with all those &#8220;xe&#8221; aliases&#8230;</p>

	<p>Well, <a href="http://poshcode.org/1682">I was able to</a>. And what&#8217;s more, I managed to dramatically clean up the way namespaces work, and make it so that really, the only ugly part of the syntax is the initial declaration of namespaces! I&#8217;m going to start with two examples, and use them to walk you through the features <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>

	<h3>Example 1</h3>

	<p>The simplest example I could think of is to list all the files in a folder, with the file size and last modified stamp:</p>

	<div class="posh code posh" style="font-family:monospace;"><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;">$xml</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">XDocument</span></span> folder <span style="color: #000066;">-path</span> <span style="color: #660033; font-weight: bold;">$pwd</span> <span style="color: #333;">&#123;</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;">$file</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; file <span style="color: #000066;">-Modified</span> <span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">LastWriteTimeUtc</span> <span style="color: #000066;">-Size</span> <span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">Length</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">Name</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>The output of that, when run on my formats folder, looks like this:</p>

	<div class="xml code xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;folder</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;C:\Users\Jaykul\Documents\WindowsPowerShell\formats&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;file</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:00Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;30474&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>CliXml.xsd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/file<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;file</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:40.48001Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;14314&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>format.xsd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/file<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;file</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2010-01-16T21:30:06.0562796Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;18275&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>NppExternalLexers.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/file<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;file</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-03-18T21:28:51.6579351Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;5802&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Recommender.Types.Format.ps1xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/file<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;file</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:40.518029Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;5107&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>types.xsd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/file<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/folder<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div>

	<p>You can immediately see what the script does: New-XDocument (which is aliased as &#8216;xml&#8217;) actually generates the root xml node, so the first argument to it is the name of that node, and any other arguments become attributes &#8230; except for the script block. That script block turns into the <em>contents</em> of the node.</p>

	<p>Inside the script block, PowerShell code is parsed as usual, but whenever a command that doesn&#8217;t exist is encountered, it is turned into an xml node! Pretty simple, right?  Of course, if you wanted to create a node with a name that&#8217;s already taken by a PowerShell command, you can just replace <code>file</code> with <code>New-XElement file</code>, or (using aliases) <code>xe &#39;file&#39;</code>, which explicitly creates an xml node with the given name.</p>

	<p>That&#8217;s pretty much it for our first example, so let&#8217;s look at a more complicated example, with multiple namespaces, and deeper nesting.</p>

	<h3>Example 2</h3>

	<p>This time, we&#8217;ll create an Atom document, and we&#8217;ll include some namespace extensions (including a made up one for listing my files as we did above):</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">XDocument</span></span> <span style="color: #333;">&#40;</span><span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>XNamespace<span style="color: #333;">&#93;</span></span><span style="color: #009900;">&quot;http://www.w3.org/2005/Atom&quot;</span><span style="color: #333;">&#41;</span> <span style="color: #66cc66;">+</span> <span style="color: #009900;">&quot;feed&quot;</span><span style="color: #333;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;`<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-fi</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>XNamespace<span style="color: #333;">&#93;</span></span><span style="color: #009900;">&quot;http://huddledmasses.org/schemas/FileInfo&quot;</span><span style="color: #333;">&#41;</span> &nbsp; `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">-dc</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>XNamespace<span style="color: #333;">&#93;</span></span><span style="color: #009900;">&quot;http://purl.org/dc/elements/1.1&quot;</span><span style="color: #333;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; `<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">-</span>$<span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>XNamespace<span style="color: #333;">&#93;</span></span>::<span style="color: #003366; font-weight: bold;">Xml</span> <span style="color: #66cc66;">+</span><span style="color: #009900;">'lang'</span><span style="color: #333;">&#41;</span> <span style="color: #009900;">&quot;en-US&quot;</span> <span style="color: #000066;">-Encoding</span> <span style="color: #009900;">&quot;UTF-16&quot;</span> &nbsp; &nbsp; &nbsp; &nbsp;`<br />
<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;title <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;Huddled Masses: You can do more than breathe for free...&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;link <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;http://HuddledMasses.org/&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;updated <span style="color: #333;">&#123;</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span> <span style="color: #000066;">-f</span> u<span style="color: #333;">&#41;</span> <span style="color: #000066;">-replace</span> <span style="color: #009900;">&quot; &quot;</span>,<span style="color: #009900;">&quot;T&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;author <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; name <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;Joel Bennett&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; uri <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;http://HuddledMasses.org/&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;id <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;http://HuddledMasses.org/&quot;</span> <span style="color: #333;">&#125;</span><br />
<br />
&nbsp; &nbsp;entry <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; title <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;A DSL for XML in PowerShell: New-XDocument&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; link <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;http://HuddledMasses.org/A-DSL-for-XML-in-PowerShell-New-XDocument/&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; id <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;http://HuddledMasses.org/A-DSL-for-XML-in-PowerShell-New-XDocument/&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; updated <span style="color: #333;">&#123;</span><span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Date</span></span> <span style="color: #cc66cc;">2010</span><span style="color: #66cc66;">/</span>03<span style="color: #66cc66;">/</span>03 <span style="color: #000066;">-f</span> u<span style="color: #333;">&#41;</span> <span style="color: #000066;">-replace</span> <span style="color: #009900;">&quot; &quot;</span>,<span style="color: #009900;">&quot;T&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; summary <span style="color: #333;">&#123;</span><span style="color: #009900;">&quot;A while back, I posted a simple mini language for generating XML from PowerShell script. However, I was using it the other day, and I really just felt that the markup was ugly, since it was littered with 'xe' marks and such.&quot;</span><span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; link <span style="color: #000066;">-rel</span> license <span style="color: #000066;">-href</span> <span style="color: #009900;">&quot;http://creativecommons.org/licenses/by/3.0/&quot;</span> <span style="color: #000066;">-title</span> <span style="color: #009900;">&quot;CC By-Attribution&quot;</span><br />
&nbsp; &nbsp; &nbsp; dc:rights <span style="color: #333;">&#123;</span> <span style="color: #009900;">&quot;Copyright 2010, Some rights reserved (licensed under the Creative Commons Attribution 3.0 Unported license)&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; category <span style="color: #000066;">-scheme</span> <span style="color: #009900;">&quot;http://huddledmasses.org/tag/&quot;</span> <span style="color: #000066;">-term</span> <span style="color: #009900;">&quot;xml&quot;</span><br />
&nbsp; &nbsp; &nbsp; category <span style="color: #000066;">-scheme</span> <span style="color: #009900;">&quot;http://huddledmasses.org/tag/&quot;</span> <span style="color: #000066;">-term</span> <span style="color: #009900;">&quot;PowerShell&quot;</span><br />
&nbsp; &nbsp; &nbsp; category <span style="color: #000066;">-scheme</span> <span style="color: #009900;">&quot;http://huddledmasses.org/tag/&quot;</span> <span style="color: #000066;">-term</span> <span style="color: #009900;">&quot;DSL&quot;</span><br />
&nbsp; &nbsp; &nbsp; fi:folder <span style="color: #000066;">-Path</span> <span style="color: #009900;">&quot;~\Formats&quot;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">foreach</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$file</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Join-<span style="font-style: normal;">Path</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Split-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$profile</span><span style="color: #333;">&#41;</span> Formats<span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fi:file <span style="color: #000066;">-Created</span> <span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">CreationTimeUtc</span> <span style="color: #000066;">-Modified</span> <span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">LastWriteTimeUtc</span> <span style="color: #000066;">-Size</span> <span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">Length</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$file</span>.<span style="color: #003366;">Name</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Declaration</span>.<span style="color: #003366;">ToString</span><span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span>; <span style="color: #660033; font-weight: bold;">$_</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></div>

	<p>There are four things you should notice, in particular:</p>

	<p>First: the initial tag has a [XNamespace] added to it. You can specify a tag name that has a namespace by adding them together this way, or by embedding the namespace in the string like <code>&#34;{http://www.w3.org/2005/Atom}feed&#34;</code> instead.  Either way works. This initial namespace becomes the <strong>default</strong> namespace for the document. If you don&#8217;t specify a namespace on tags later, they automatically belong to that one.</p>

	<p>Second: when you want to add additional namespaces, you can do so with a custom prefix like: <code>-dc ([XNamespace]&#34;http://purl.org/dc/elements/1.1&#34;)</code>, and that prefix (dc) takes on a special meaning. When you want to have a tag later on that is part of that namespace, you just prefix the tag, like <code>dc:rights</code> &#8212;the same way you would in <span class="caps">XML</span>.</p>

	<p>Third: any number of attributes can be specified using the <code>-name value</code> syntax, but anything in a <code>{scriptblock}</code> becomes the content &#8212; and is subject to the same rules as the outer sections.</p>

	<p>Fourth: This generates an XDocument. When you cast an XDocument to string, the xml declaration is left off, so if you want it, you need to manually add it via <code>$XDocument.Declaration</code>.  Incidentally, XDocuments are <strong>not</strong> XMLDocuments, but they <strong>are</strong> trivially castable to them.</p>

	<p>The output of that particular section of New-XDocument is this:</p>

	<div class="xml code xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;feed</span> <span style="color: #000066;">xmlns:dc</span>=<span style="color: #ff0000;">&quot;http://purl.org/dc/elements/1.1&quot;</span> <span style="color: #000066;">xmlns:fi</span>=<span style="color: #ff0000;">&quot;http://huddledmasses.org/schemas/FileInfo&quot;</span> <span style="color: #000066;">xml:lang</span>=<span style="color: #ff0000;">&quot;en-US&quot;</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/2005/Atom&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; <br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>http://HuddledMasses.org/<br />
&nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;updated<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010-03-04T00:44:31Z<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/updated<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;author<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;name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Joel Bennett<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/name<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;uri<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://HuddledMasses.org/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/uri<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;/author<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;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://HuddledMasses.org/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<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;entry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;link</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>http://HuddledMasses.org/A-DSL-for-XML-in-PowerShell-New-XDocument/<br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;id<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>http://HuddledMasses.org/A-DSL-for-XML-in-PowerShell-New-XDocument/<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/id<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;updated<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2010-03-03T00:00:00Z<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/updated<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;summary<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>A while back, I posted a simple mini language for generating XML from PowerShell script. However, I was using it the other day, and I really just felt that the markup was ugly, since it was littered with 'xe' marks and such.<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/summary<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;link</span> <span style="color: #000066;">rel</span>=<span style="color: #ff0000;">&quot;license&quot;</span> <span style="color: #000066;">href</span>=<span style="color: #ff0000;">&quot;http://creativecommons.org/licenses/by/3.0/&quot;</span> <span style="color: #000066;">title</span>=<span style="color: #ff0000;">&quot;CC By-Attribution&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;dc:rights<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Copyright 2010, Some rights reserved (licensed under the Creative Commons Attribution 3.0 Unported license)<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dc:rights<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;category</span> <span style="color: #000066;">scheme</span>=<span style="color: #ff0000;">&quot;http://huddledmasses.org/tag/&quot;</span> <span style="color: #000066;">term</span>=<span style="color: #ff0000;">&quot;xml&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;category</span> <span style="color: #000066;">scheme</span>=<span style="color: #ff0000;">&quot;http://huddledmasses.org/tag/&quot;</span> <span style="color: #000066;">term</span>=<span style="color: #ff0000;">&quot;PowerShell&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;category</span> <span style="color: #000066;">scheme</span>=<span style="color: #ff0000;">&quot;http://huddledmasses.org/tag/&quot;</span> <span style="color: #000066;">term</span>=<span style="color: #ff0000;">&quot;DSL&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;fi:folder</span> <span style="color: #000066;">path</span>=<span style="color: #ff0000;">&quot;~\Formats&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;fi:file</span> <span style="color: #000066;">created</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:00Z&quot;</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:00Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;30474&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>CliXml.xsd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fi:file<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;fi:file</span> <span style="color: #000066;">created</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:40.4529965Z&quot;</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:40.48001Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;14314&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>format.xsd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fi:file<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;fi:file</span> <span style="color: #000066;">created</span>=<span style="color: #ff0000;">&quot;2009-02-07T13:56:12Z&quot;</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2010-01-16T21:30:06.0562796Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;18275&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>NppExternalLexers.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fi:file<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;fi:file</span> <span style="color: #000066;">created</span>=<span style="color: #ff0000;">&quot;2009-08-09T19:10:06.3647094Z&quot;</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-03-18T21:28:51.6579351Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;5802&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>Recommender.Types.Format.ps1xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fi:file<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;fi:file</span> <span style="color: #000066;">created</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:40.4970185Z&quot;</span> <span style="color: #000066;">modified</span>=<span style="color: #ff0000;">&quot;2009-11-07T07:27:40.518029Z&quot;</span> <span style="color: #000066;">size</span>=<span style="color: #ff0000;">&quot;5107&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>types.xsd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/fi:file<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;/fi:folder<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;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/category<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/entry<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/feed<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div>

	<p>The New-XDocument script itself is on PoshCode in the <a href="http://poshcode.org/1682">Xml Module 4</a> along with a few interesting functions like Select-<span class="caps">XML</span> (which improves over the built-in by being able to ignore namespaces when you write XPath) and Remove-XmlNamespace (which was instrumental in removing namespaces for Select-Xml). There&#8217;s also a  Format-Xml for pretty-printing, and a Convert-Xml for processing <span class="caps">XSL</span> transformations.</p>

	<p>I&#8217;ll probably post some more examples of this in the next week or two, and I really should write some commentary about the function itself, which uses the tokenizer to discover which &#8220;commands&#8221; are really xml nodes &#8230; but for now, I&#8217;ll leave you to enjoy.<h6 class="zemanta-related-title">Related articles by Zemanta</h6><ul class="zemanta-article-ul"><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/json-from-powershell-but-why/"><span class="caps">JSON</span> from PowerShell (but why?)</a> (huddledmasses.org)</li><li class="zemanta-article-ul-li"><a href="http://apache.sys-con.com/node/1211348">What&#8217;s in a Namespace</a> (apache.sys-con.com)</li><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/ignoring-namespaces-in-xpath/">Ignoring Namespaces in XPath</a> (huddledmasses.org)</li></ul></p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/c26e9d24-6176-4c07-a3f7-9eb438404e7e/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=c26e9d24-6176-4c07-a3f7-9eb438404e7e" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/a-dsl-for-xml-in-powershell-new-xdocument/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Are you interested in a virtual PowerShell brown-bag event?</title>
		<link>http://huddledmasses.org/are-you-interested-in-a-virtual-powershell-brown-bag-event/</link>
		<comments>http://huddledmasses.org/are-you-interested-in-a-virtual-powershell-brown-bag-event/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 18:30:00 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Brown Bag]]></category>
		<category><![CDATA[Poll]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[User Group]]></category>
		<category><![CDATA[Virtual Group]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/are-you-interested-in-a-virtual-powershell-brown-bag-event/</guid>
		<description><![CDATA[	I just put up a poll on the PowerShell Virtual Group to see if people are interested in a low-planning brown-bag event.

	The initial question is: would you attend a weekly (or monthly) virtual brown-bag lunch if I put one together.

	The idea is that we would start each session with a short collection of interesting links, [...]]]></description>
			<content:encoded><![CDATA[	<p>I just <a href="http://powershellgroup.org/virtual/brown-bag-poll-1">put up a poll</a> on the <a href="http://powershellgroup.org/virtual">PowerShell Virtual Group</a> to see if people are interested in a low-planning brown-bag event.</p>

	<p>The initial question is: would you attend a weekly (or monthly) virtual brown-bag lunch if I put one together.</p>

	<p>The idea is that we would start each session with a short collection of interesting links, tips and tricks, or <a href="http://connect.microsoft.com/PowerShell">connect</a> issues, and then have a presentation or discussion or script club or open-mic session, depending on interest.</p>

	<p>Basically, this is meant to flow, on a week-to-week basis, from script-club to formal user group presentations. </p>

	<p>Some weeks we would have presenters from various local user groups share content they had prepared for their local groups. We would encourage you to take ownership of this time, request topics, and prepare presentations (no matter how short).</p>

	<p>Some weeks we would have an open-format script club using our private pastebin, <span class="caps">IRC</span> channel, and LiveMeeting voice chat.  This time could vary from real-world problem solving to scripting games and &#8220;project Euler&#8221;-style challenges.</p>

	<p>Some weeks we would have open-mic time and solicit feedback for the PowerShell team from anyone who cared to give it. I would make an effort to make sure I wasn&#8217;t the only <span class="caps">MVP</span> there, so you could feel that even if there wasn&#8217;t a Microsoft employee present on a given day, your voice could be heard when you make suggestions or vent frustrations &#8230; </p>

	<p>The point is: the format would vary a bit, and we would adjust it over time to fit whatever works the best within our virtual meeting and time constraints.</p>

	<p>So, what do you think? <a href="http://powershellgroup.org/virtual/brown-bag-poll-1">Are you interested?</a></p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/are-you-interested-in-a-virtual-powershell-brown-bag-event/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>UPNYPUG &#8211; Rochester PowerShell UserGroup Meeting Wednesday</title>
		<link>http://huddledmasses.org/upnypug-rochester-powershell-usergroup-meeting-wednesday/</link>
		<comments>http://huddledmasses.org/upnypug-rochester-powershell-usergroup-meeting-wednesday/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 15:06:53 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[GettingStarted]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShellGroup]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Rochester New York]]></category>
		<category><![CDATA[UserGroup]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1397</guid>
		<description><![CDATA[Image via Wikipedia

	I&#8217;ve written this up on the new website for our Rochester PowerShell group and on the old blog, and on UGSS Facebook and Twitter &#8230; and now that there&#8217;s only two days left, it&#8217;s time to mention it again, on my blog  

	This Wednesday, January 20, 2010 &#8211; 6:00pm

	It&#8217;s a new year, [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img"><div><dl class="wp-caption alignright"><dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/Image:Roc_032c.JPG"><img src="http://upload.wikimedia.org/wikipedia/en/thumb/5/55/Roc_032c.JPG/300px-Roc_032c.JPG" alt="A portion of Rochester's skyline, looking nort..." title="A portion of Rochester's skyline, looking nort..." /></a></dt><dd class="wp-caption-dd zemanta-img-attribution">Image via <a href="http://en.wikipedia.org/wiki/Image:Roc_032c.JPG">Wikipedia</a></dd></dl></div></div>

	<p>I&#8217;ve written this up on the new website for our <a href="http://powershellgroup.org/rochester-ny">Rochester PowerShell group</a> and on the <a href="http://upnypug.wordpress.com">old blog</a>, and on <a href="http://www.usergroupsupportservices.com/UserGroupInformation.ugss?ActiveID=5048">UGSS</a> Facebook and Twitter &#8230; and now that there&#8217;s only two days left, it&#8217;s time to mention it again, on my blog <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

	<h3><a href="http://powershellgroup.org/rochester-ny/events/january-20-2010">This Wednesday, January 20, 2010 &#8211; 6:00pm</a></h3>

	<p>It&#8217;s a new year, and a new opportunity to get started with PowerShell. With the new year, we&#8217;re going to put a renewed focus on trying to make our meetings valuable to everyone. With that in mind, the first Rochester meeting of the upstate New York PowerShell users group in 2010 will feature two separate presentations:</p>

	<h5>Getting Started: The PowerShell Pipeline (100 Level)</h5>

	<ul>
		<li>Different types of commands in PowerShell</li>
		<li>Variable assignment and Pipeline arguments</li>
		<li>Understanding the Pipe</li>
		<li>Why PowerShell&#8217;s pipeline is different</li>
	</ul>
	<ul>
		<li>Exploiting pipelines for fun and profit</li>
	</ul>

	<h5>Creating PowerShell script Modules (300 Level)</h5>

	<ul>
		<li>Turning your script or function into a module</li>
		<li>What makes a function an &#8220;advanced function&#8221;</li>
		<li>Providing in-line help for functions</li>
		<li>Controlling what functions and variables your module exports</li>
	</ul>
	<ul>
		<li>Why you should use Module Metadata files</li>
	</ul>

	<p>Everyone is welcome, from beginners to pros! Bring a friend and introduce them to PowerShell. As always, our meeting will be at New Horizons&#8217; in Henrietta, 50 Methodist Hill Drive, Suite 50.</p>

	<p>In order to keep things on time, we&#8217;ll be starting our presentations at 6:30 exactly, after a short pizza, wings, and networking time starting at 6pm. We only ask that if you can come early for the food you <strong>let us know ahead of time</strong> and come ready to pitch in a few dollars to help cover the cost.</p>

	<p>PS: There will be swag. We have several books, an Arc Mouse, and copies of Windows 7 and Office 2007 to give away&#8230;</p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/cf741a5f-0b2b-4dcc-a258-5d0f0738e972/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=cf741a5f-0b2b-4dcc-a258-5d0f0738e972" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/upnypug-rochester-powershell-usergroup-meeting-wednesday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Module Manifests Tip: allowed cmdlets and variables</title>
		<link>http://huddledmasses.org/powershell-module-manifests-tip-allowed-cmdlets-and-variables/</link>
		<comments>http://huddledmasses.org/powershell-module-manifests-tip-allowed-cmdlets-and-variables/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 02:56:58 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Manifest]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Windows 7]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1394</guid>
		<description><![CDATA[	I was under the impression that module manifests allow only DATA stuff. In fact, if you try to use cmdlets or variables in them, you get the usual Data-language errors, like this:

	Import-Module : The module manifest &#8216;C:\Modules\Test\Test.psd1&#8217; could not be processed because it is not a valid PowerShell restricted language file. Please remove the elements [...]]]></description>
			<content:encoded><![CDATA[	<p>I was under the impression that module manifests allow only <span class="caps">DATA</span> stuff. In fact, if you try to use cmdlets or variables in them, you get the usual Data-language errors, like this:</p>

	<p><code style="color: red; margin-left: 10px;"></code><p>Import-Module : The module manifest &#8216;C:\Modules\Test\Test.psd1&#8217; could not be processed because it is not a valid PowerShell restricted language file. Please remove the elements that are not permitted by the restricted language: The command &#8216;Get-ChildItem&#8217; is not in allowed in restricted language mode or a Data section.</p><br />
<p>Import-Module : The module manifest &#8216;C:\Modules\Test\Test.psd1&#8217; could not be processed because it is not a valid PowerShell restricted language file. Please remove the elements that are not permitted by the restricted language: A variable that cannot be referenced in restricted language mode or a Data section is being referenced. Variables that can be referenced include the following: $PSCulture, $PSUICulture, $true, $false, and $null.</p></p>

	<p><span class="caps">BUT</span> <span class="caps">THEN</span> I came across this in the Windows 7 built-in BitsTransfer module:</p>

	<p>RequiredAssemblies=Join-Path $psScriptRoot &#8220;Microsoft.BackgroundIntelligentTransfer.Management.Interop.dll&#8221;</p>

	<p><span class="caps">AND</span> IT WORKS?!</p>

	<p>Well, that&#8217;s very weird, because <code>Join-Path</code> is certainly not allowed in a normal &#8220;restricted language&#8221; file, and (as you can tell from above) neither is <code>$PsScriptRoot</code> &#8212; in fact, as far as I know, you shouldn&#8217;t have to do that at all, since RequiredAssemblies knows enough to look in your module folder&#8230; but nevermind that, why does it work?</p>

	<h3>The Rest of the Story</h3>

	<p>So I went digging, and it turns out that although they are parsed as Restricted Language (like a &#8220;data section,&#8221; see <a href="http://technet.microsoft.com/en-us/library/dd347678.aspx">about_Data_Sections</a>), module manifests are allowed extra cmdlets:  &#8220;Import-LocalizedData&#8221;, &#8220;ConvertFrom-StringData&#8221;, &#8220;Write-Host&#8221;, &#8220;Out-Host&#8221;, &#8220;Join-Path&#8221; and even special variables that aren&#8217;t normally allowed in data sections: specifically $PsScriptRoot which is the ModuleBase (the parent folder of the psd1) and environment variables ($Env:), plus the usual $PSCulture, $PSUICulture, and of course $true, $false, and $null.</p>

	<p>However, although you can use those variables, you can&#8217;t embed them in strings, so if you wanted to use <code>$Env:Windir</code> or <code>$Env:Temp</code> as part of a path (for instance), you need to take advantage of the availability of <code>Join-Path</code>.</p>

	<p>Now, I can&#8217;t find this documented anywhere (although I did add it to the <a href="http://msdn.microsoft.com/en-us/library/dd878337%28VS.85%29.aspx">module manifest documentation on MSDN</a>), but it&#8217;s true, nonetheless &#8212; you&#8217;ll just have to trust me <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Yeah, PowerShell is starting to drive me crazy again.</p>

<h6 class="zemanta-related-title">Related articles by Zemanta</h6><ul class="zemanta-article-ul"><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/a-question-about-powershell-module-manifests/">A question about PowerShell Module Manifests</a> (huddledmasses.org)</li><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/another-module-manifest-gotcha/">Another Module Manifest Gotcha</a> (huddledmasses.org)</li></ul>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/4ca92c55-78cf-49bf-9cd4-a02adb78774d/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=4ca92c55-78cf-49bf-9cd4-a02adb78774d" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-module-manifests-tip-allowed-cmdlets-and-variables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Another Module Manifest Gotcha</title>
		<link>http://huddledmasses.org/another-module-manifest-gotcha/</link>
		<comments>http://huddledmasses.org/another-module-manifest-gotcha/#comments</comments>
		<pubDate>Fri, 15 Jan 2010 03:42:36 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Error message]]></category>
		<category><![CDATA[Globally Unique Identifier]]></category>
		<category><![CDATA[Import-Module]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[RequiredModules]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1386</guid>
		<description><![CDATA[	Shay Levy, ScriptFanatic, wrote about the PowerShellHostVersion on his blog this morning, explaining how it is not a field you should use in your module manifests.

	Of course, there&#8217;s an exception: if your module is dependent on a specific host.  For instance, if you&#8217;ve written a module for PoshConsole which exploits the WpfHost display features [...]]]></description>
			<content:encoded><![CDATA[	<p>Shay Levy, ScriptFanatic, wrote <a href="http://blogs.microsoft.co.il/blogs/scriptfanatic/archive/2010/01/14/module-manifest-gotcha.aspx">about the PowerShellHostVersion</a> on his blog this morning, explaining how it is <strong>not</strong> a field you should use in your <a href="http://msdn.com/library/dd878337.aspx">module manifests</a>.</p>

	<p>Of course, there&#8217;s an exception: if your module is dependent on a specific host.  For instance, if you&#8217;ve written a module for <a href="http://poshconsole.codeplex.com">PoshConsole</a> which exploits the WpfHost display features or the BgHost hotkeys feature &#8230; or if you&#8217;ve written <a href="http://code.msdn.microsoft.com/PowerShellPack">ISEPack</a> based on the menu and script-editor features of PowerShell <span class="caps">ISE</span>), then it makes sense to specify the <strong>PowerShellHostName</strong> and the <strong>PowerShellHostVersion</strong> together.  However, if you aren&#8217;t taking a dependency on a specific host &#8230; you should definitely <strong>never</strong> specify PowerShellHostVersion by itself.</p>

	<h3>RequiredModules</h3>

	<p>I&#8217;ve got another one that I think you should not use. PowerShell has several ways of specifying prerequisites for your modules, such as assemblies that should be loaded, modules that must be nested, etc. In every case <strong>except</strong> RequiredModules, PowerShell will actually import those things for you.</p>

	<p>That is, if you specify that you RequiredAssemblies = &#8220;System.Windows.Forms&#8221; it will automatically load it. If you specify NestedModules = &#8220;BitsTransfer&#8221; it will automatically load that. But if you specify RequiredModules = &#8220;BitsTransfer&#8221; you&#8217;re sore out of luck.</p>

	<p>Not only does PowerShell not load them for you, it doesn&#8217;t give you all the information you need to load them when it fails. For example, consider that you have a module called &#8220;ReallyRequired&#8221; and one called &#8220;TestModule&#8221; which requires ReallyRequired.  It&#8217;s metadata file is very simple, it looks like this:</p>

	<div class="posh code posh" style="font-family:monospace;">@<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; Author<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Joel Bennett&quot;</span><br />
&nbsp; &nbsp; ModuleToProcess<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;TestModule.psm1&quot;</span>; ModuleVersion<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;1.0.0.0&quot;</span><br />
&nbsp; &nbsp; RequiredModules<span style="color: #66cc66;">=</span>@<span style="color: #333;">&#123;</span>ModuleName<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;ReallyRequired&quot;</span>;GUID<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;84b5ab08-3620-4f72-bffd-44d2a6bb506d&quot;</span>; ModuleVersion<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;2.5.0.0&quot;</span><br />
<span style="color: #333;">&#125;</span></div>

	<p>Before we try to import it, we might try to check which modules it requires, and since it doesn&#8217;t appear to require any, we&#8217;ll go ahead and import it:</p>

	<div class="posh code posh" style="font-family:monospace;"><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> <span style="color: #000066;">-list</span> TestModule <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> RequiredModule<br />
<br />
RequiredModules &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #66cc66;">---------------</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color: #333;">&#123;</span><span style="color: #333;">&#125;</span><br />
<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> TestModule<br />
<br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> : The required module <span style="color: #009900;">'ReallyRequired'</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> loaded. <span style="color: #003366;">Load</span> the module <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> remove the module <span style="color: #666699; font-weight: bold;">from</span> <span style="color: #009900;">'RequiredModules'</span> <span style="color: #666699; font-weight: bold;">in</span> the file <span style="color: #009900;">'C:\Users\Joel\Documents\WindowsPowerShell\Modules\TestModule\TestModule.psd1'</span>.</div>

	<p>Apparently, there&#8217;s just no way to tell which module(s) you need to preload (or even whether there are any) until you get an error message. You might think you could just write a script to test for that error and then run <code>Import-Module ReallyRequired</code> &#8230; but what you don&#8217;t know is that after you load your copy of the ReallyRequired module:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #333;">&#91;</span><span style="color: #cc66cc;">3</span><span style="color: #333;">&#93;</span>: ImportModule TestModule<br />
<br />
<span style="color: #0066cc; font-style: italic;">Import-<span style="font-style: normal;">Module</span></span> : The required module <span style="color: #009900;">'ReallyRequired'</span> with version <span style="color: #009900;">'2.5.0.0'</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> loaded. <span style="color: #003366;">Load</span> the module <span style="color: #333399; font-weight: bold; font-style: italic;">or</span> remove the module <span style="color: #666699; font-weight: bold;">from</span> <span style="color: #009900;">'RequiredModules'</span> <span style="color: #666699; font-weight: bold;">in</span> the file <span style="color: #009900;">'C:\Users\Joel\Documents\WindowsPowerShell\Modules\TestModule\TestModule.psd1'</span>.</div>

	<p>If you&#8217;re like me, right now you&#8217;re tearing out your hair wondering why the error message didn&#8217;t tell you that in the first place. Then you have to go off and try to find a newer version of your RequiredModules. And that&#8217;s not even the crazy thing! The crazy thing is, if you find the wrong one, you could still get a message about the <span class="caps">GUID</span> not matching next. <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_eek.gif' alt='8-O' class='wp-smiley' /> </p>

	<p>So yeah, RequiredModules is really unlikely to be helpful right now. You&#8217;re better off just putting an <code>Import-Module ReallyRequired -version 2.5 -ErrorAction Stop</code> at the top of you script module (although that won&#8217;t help you if you&#8217;re writing a binary cmdlet module).</p>

	<h3>Some good news</h3>

	<p>This is just one of the things that the new PoshCode is being designed to address, so I&#8217;ll be blogging more about this shortly, but for now, you can use this function to list RequiredModules:</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;">Get-<span style="font-style: normal;">RequiredModules</span></span> <span style="color: #333;">&#123;</span><br />
<span style="color: #666699; font-weight: bold;">Param</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Path</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033; font-weight: bold;">$dataSource</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Content</span></span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Resolve-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$Path</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-delim</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">char</span><span style="color: #333;">&#93;</span></span><span style="color: #cc66cc;">0</span><br />
<br />
<span style="color: #666666; font-style: italic;">## We are ONLY going to &quot;Tokenize&quot; this to make sure there isn't an extra &quot;}&quot; which could lead to an exploit:</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$null</span> <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Management.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">PSParser</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Tokenize</span><span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;&quot;</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ref</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$null</span><span style="color: #333;">&#41;</span> &nbsp;<span style="color: #666666; font-style: italic;"># work around a PowerShell BUG</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$ParseErrors</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">Object</span></span> <span style="color: #009900;">&quot;System.Collections.ObjectModel.Collection[System.Management.Automation.PSParseError]&quot;</span><br />
&nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$global</span>:tokens <span style="color: #66cc66;">=</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>Management.<span style="color: #003366;">Automation</span>.<span style="color: #003366;">PSParser</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">Tokenize</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$dataSource</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">ref</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$ParseErrors</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$ParseErrors</span>.<span style="color: #003366;">Count</span> <span style="color: #000066;">-gt</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: #660033; font-weight: bold;">$ParseErrors</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span><span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">throw</span> <span style="color: #009900;">&quot;$($_.Message)<span style="color: #000099; font-weight: bold;">`n</span>$File at line:$($_.Token.StartLine) char:$($_.Token.Start)&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
<span style="color: #660033; font-weight: bold;">$dataSource</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$dataSource</span> <span style="color: #000066;">-replace</span> <span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">`n</span># SIG #&quot;</span>,<span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">`n</span> # SIG #&quot;</span><br />
<span style="color: #666699; font-weight: bold;">return</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Invoke-<span style="font-style: normal;">Expression</span></span> <span style="color: #009900;">&quot;DATA {<span style="color: #000099; font-weight: bold;">`n</span> $dataSource <span style="color: #000099; font-weight: bold;">`n</span>}&quot;</span><span style="color: #333;">&#41;</span>.<span style="color: #003366;">RequiredModules</span><br />
<span style="color: #333;">&#125;</span></div>

<h6 class="zemanta-related-title">Related articles by Zemanta</h6><ul class="zemanta-article-ul"><li class="zemanta-article-ul-li"><a href="http://huddledmasses.org/a-question-about-powershell-module-manifests/">A question about PowerShell Module Manifests</a> (huddledmasses.org)</li></ul>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/bf32d64f-fae9-4f34-ab85-385a6242e5ba/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=bf32d64f-fae9-4f34-ab85-385a6242e5ba" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/another-module-manifest-gotcha/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The Virtual PowerShell Group</title>
		<link>http://huddledmasses.org/the-virtual-powershell-group/</link>
		<comments>http://huddledmasses.org/the-virtual-powershell-group/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 20:39:00 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Discussion Groups]]></category>
		<category><![CDATA[Internet Relay Chat]]></category>
		<category><![CDATA[IRC]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[User Group]]></category>

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

	This is old news and new news &#8230; but I figured it&#8217;s about time I break it on my blog, since it was mostly my doing (and since my Northeast Developer Evangelist Jim O&#8217;Neil already mentioned it on his blog).

	We have created an official Virtual PowerShell Group (official, in the sense that it&#8217;s recognized by [...]]]></description>
			<content:encoded><![CDATA[	<p><img src="http://powershellgroup.org/sites/default/files/garland_logo.png" class="zemanta-pixie-img" align="right" alt="" width="199" height="128" /></p>

	<p>This is old news and new news &#8230; but I figured it&#8217;s about time I break it on my blog, since it was mostly my doing (and since my Northeast Developer Evangelist <a href="http://blogs.msdn.com/jimoneil/archive/2010/01/04/powershell-virtually.aspx">Jim O&#8217;Neil already mentioned it on his blog</a>).</p>

	<p>We have created an official Virtual PowerShell Group (official, in the sense that it&#8217;s recognized by Microsoft&#8217;s <a href="https://www.usergroupsupportservices.com/UserGroupInformation.ugss?UGName=VirtualPowerShellGroup">User Group Support Services</a> out of the unofficial <a href="irc://irc.freenode.net/PowerShell">#PowerShell channel on irc.freenode.net</a> and have created <a href="http://PowerShellGroup.org/virtual">a website to support it</a> including a page where you can <a href="http://powershellgroup.org/virtual/live">join us online via web-based chat</a> any time you like.</p>

	<p>Of course, this isn&#8217;t <em>exactly</em> headline news: The #PowerShell <span class="caps">IRC</span> channel has been around for years and has always been helpful and polite.  What&#8217;s new is that we are officially a User Group, and have swag to give away (more on that later)!  We&#8217;re hoping that this will help some of you justify joining us, and using <span class="caps">IRC</span> as a resource for your PowerShell learning and for those sticky questions!</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/the-virtual-powershell-group/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell: Determine your function&#8217;s position in the pipeline</title>
		<link>http://huddledmasses.org/powershell-determine-your-functions-position-in-the-pipeline/</link>
		<comments>http://huddledmasses.org/powershell-determine-your-functions-position-in-the-pipeline/#comments</comments>
		<pubDate>Mon, 28 Dec 2009 02:54:33 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Pipeline]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell Functions]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1362</guid>
		<description><![CDATA[	I just posted an article to the FAQ on the PoshCode Wiki answering this question that came up again on our IRC PowerShell user group today. It came up in the context of determining whether a function was the last function on the pipeline, because one of our users was looking for a way (other [...]]]></description>
			<content:encoded><![CDATA[	<p>I just posted an article to the <a href="http://wiki.poshcode.org/index.php?title=FAQ/Tips_and_Tricks/How_Do_I..._Determine_My_Function%27s_Position_in_the_Pipeline"><span class="caps">FAQ</span> on the PoshCode Wiki</a> answering this question that came up again on our <span class="caps">IRC</span> <a href="http://PowerShellGroup.org/virtual">PowerShell user group</a> today. It came up in the context of determining whether a function was the last function on the pipeline, because one of our users was looking for a way (other than creating ps1xml files) to output objects onto the pipeline for use in other functions, but still format those objects nicely if they were output directly. </p>

	<p>Before I give the solution, I just want to say: <strong>don&#8217;t change your output based on where you are in a pipeline.</strong></p>

	<p>There are numerous scenarios where your function will be the last one on a pipeline, but still be participating in further pipelines, including formatting and output modification. For example, take our function Test-Pipeline (defined below) in these three scenarios below. In none of these scenarios would it be appropriate for the function to write formatted output instead of outputting the raw object, but in each case, the function <strong>is</strong> the last function in the pipeline.</p>

	<div class="poshcode code poshcode" style="font-family:monospace;"><br />
# Assignment<br />
$order = Get-ChildItem | Test-Pipeline<br />
$order | Format-Table *<br />
<br />
# Nested Pipelines<br />
Get-ChildItem | Where-Object { $_.PsIsContainer} | ForEach-Object {<br />
Get-ChildItem $_ | Test-Pipeline<br />
} | Select-Object Pipe*<br />
<br />
# Nested Expressions<br />
@( Get-ChildItem | Test-Pipeline )[0].PipelineLength | ForEach-Object { $_ }<br />
&nbsp;</div>

	<p>However, if you want to determine your function&#8217;s position in the pipeline for some other reason, the answer is simple. You need to use <code>$MyInvocation</code> and compare the <code>PipelineLength</code> and <code>PipelinePosition</code> properties:</p>

	<div class="poshcode code poshcode" style="font-family:monospace;"><br />
## Useful for testing all sorts of things about the pipeline<br />
function Test-Pipeline {<br />
[CmdletBinding()]<br />
Param(<br />
&nbsp; &nbsp;[Parameter(ValueFromPipeline=$true)]<br />
&nbsp; &nbsp;[PSObject]$InputObject,<br />
&nbsp; &nbsp;[Switch]$Passthru,<br />
&nbsp; &nbsp;[Switch]$PassCmdlet<br />
)<br />
BEGIN { <br />
&nbsp; &nbsp;Write-Output $MyInvocation<br />
&nbsp; &nbsp;if($PassCmdlet) {<br />
&nbsp; &nbsp; &nbsp; Write-Output $PsCmdlet<br />
&nbsp; &nbsp;}<br />
}<br />
PROCESS { if($Passthru){ $_ } }<br />
}<br />
<br />
## Shows <br />
function Test-LastInPipeline {<br />
Param(<br />
&nbsp; &nbsp;[Parameter(ValueFromPipeline=$true)]<br />
&nbsp; &nbsp;[PSObject]$InputObject,<br />
&nbsp; &nbsp;[Switch]$Passthru<br />
)<br />
BEGIN { <br />
&nbsp; &nbsp;$IsLast = $MyInvocation.PipelineLength -eq $MyInvocation.PipelinePosition<br />
&nbsp; &nbsp;if(!$IsLast) { $MyInvocation }<br />
}<br />
PROCESS { if($Passthru){ $_ } }<br />
}<br />
&nbsp;</div>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/d70821bd-4e06-4fc1-81f4-451e14c63c2f/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=d70821bd-4e06-4fc1-81f4-451e14c63c2f" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-determine-your-functions-position-in-the-pipeline/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows PowerShell 2.0 SDK Released</title>
		<link>http://huddledmasses.org/windows-powershell-2-0-sdk-released/</link>
		<comments>http://huddledmasses.org/windows-powershell-2-0-sdk-released/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 20:53:36 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[APIs]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1360</guid>
		<description><![CDATA[	So, the Windows PowerShell 2.0 Software Development Kit is basically a collection of samples, and it has been released separately from the Windows Platform SDK for a change, making the download a tiny 2.35MB &#8230;

	There are lots of examples in there in C# (no other languages), and honestly, some of them ought to make it [...]]]></description>
			<content:encoded><![CDATA[	<p>So, the <a href="http://support.microsoft.com/kb/968929">Windows PowerShell 2.0</a> <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=50633A1F-A665-425D-923C-1A269F8AC084" title="SDK">Software Development Kit</a> is basically a collection of samples, and it has been released separately from the Windows Platform <span class="caps">SDK</span> for a change, making the download a tiny 2.35MB &#8230;</p>

	<p>There are lots of examples in there in C# (no other languages), and honestly, some of them ought to make it into <span class="caps">PSCX</span> or some other project where people could grab pre-compiled versions <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

	<p>	<ul>
		<li>A Template for creating PSProviders, and a sample PSProvider (for Access databases).</li>
		<li>A sample of participating in Transactions (a set of &#8220;transacted comment&#8221; cmdlets for creating comments that go along with a transaction).</li>
		<li>Example cmdlets: Select-Object, Select-String, Get-Process, Stop-Process</li>
		<li>Dealing with issues with Serialization in PowerShell
		<li>PowerShell Eventing:
	<ul>
		<li>Deriving from ObjectEventRegistrationBase to create Register-FileSystemEvent</li>
	</ul></li>
	<ul>
		<li>Receiving notifications from PowerShell Events on remote computers.</li>
		<li>Hosting APIs, including (among others):
		<li>Restricted runspaces</li>
		<li>Runspace pools</li>
		<li>Remote runspaces (and remote runspace pools)</li>
		<li>Running commands in parallel or sequentially</li>
		<li>Calling Cmdlets and passing parameters</li>
	</ul></li>
	</ul>
	<ul>
		<li>Reproducing the default PowerShell.exe output</li>
	</ul></li></p>

	<p>Honestly, if you&#8217;re a developer that&#8217;s been wondering about learning to code cmdlets, or host PowerShell as a scripting engine, now&#8217;s the time.</p>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/windows-powershell-2-0-sdk-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ignoring Namespaces in XPath</title>
		<link>http://huddledmasses.org/ignoring-namespaces-in-xpath/</link>
		<comments>http://huddledmasses.org/ignoring-namespaces-in-xpath/#comments</comments>
		<pubDate>Sat, 05 Dec 2009 21:32:51 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Xml]]></category>
		<category><![CDATA[XPath]]></category>
		<category><![CDATA[Xsl]]></category>
		<category><![CDATA[Xslt]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1348</guid>
		<description><![CDATA[	I know that I just wrote a post last week about XPath and namespaces in PowerShell, but at the time I left out one possible way of dealing with namespaces, because it&#8217;s not the right way of doing things.  However, sometimes it&#8217;s nice to have options, and when you&#8217;re working on the command-line in [...]]]></description>
			<content:encoded><![CDATA[	<p>I know that I just wrote a post last week about <a href="http://huddledmasses.org/xpath-and-namespaces-in-powershell/">XPath and namespaces in PowerShell</a>, but at the time I left out one possible way of dealing with namespaces, because it&#8217;s not the <em>right</em> way of doing things.  However, sometimes it&#8217;s nice to have options, and when you&#8217;re working on the command-line in PowerShell, or just trying to figure out a proof-of-concept call to a web service, you really don&#8217;t <em>need</em> to deal with namespaces correctly, you just need it to work.</p>

	<p>With that in mind, I present to you the fourth option: just strip the namespaces out!  The simplest way to do that is to run the <span class="caps">XML</span> through an <span class="caps">XSL</span> stylesheet which just outputs the <code>local-name()</code> of each node (including attributes), and remove any namespace definitions (processing instructions).</p>

	<div class="xml code xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:stylesheet</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">xmlns:xsl</span>=<span style="color: #ff0000;">&quot;http://www.w3.org/1999/XSL/Transform&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;xsl:output</span> <span style="color: #000066;">method</span>=<span style="color: #ff0000;">&quot;xml&quot;</span> <span style="color: #000066;">indent</span>=<span style="color: #ff0000;">&quot;yes&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;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;/|comment()|processing-instruction()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates<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;/xsl:apply-templates<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;/xsl:copy<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{local-name()}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:apply-templates</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;@*|node()&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:apply-templates<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;/xsl:element<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<br />
&nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:template</span> <span style="color: #000066;">match</span>=<span style="color: #ff0000;">&quot;@*&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:attribute</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;{local-name()}&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:value-of</span> <span style="color: #000066;">select</span>=<span style="color: #ff0000;">&quot;.&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:value-of<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;/xsl:attribute<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:template<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:output<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/xsl:stylesheet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div>

	<p>That stylesheet and the basic steps of the process will work anywhere, from Java to C# to the web &#8230; but since my current language of choice for prototyping is PowerShell, I&#8217;ll show you how to implement it there as <a href="http://poshcode.org/1492">Remove-XmlNamespace</a>. Once you have that, I think you&#8217;ll see that it was relatively simple for me to write <a href="http://poshcode.org/1504">a new Select-XML</a> which adds a parameter <code>RemoveNamespace</code> which is implemented by calling this <a href="http://poshcode.org/1492">Remove-XmlNamespace</a> &#8230;</p>

	<p>That actually allows you to call <code>Select-Xml</code> with the <code>-RemoveNamespace</code> parameter just as though the namespaces didn&#8217;t exist.  Of course, the returned <span class="caps">XML</span> nodes will, in fact, <span class="caps">NOT</span> have namespaces &#8230; so they may not be quite the same as the source, but the data will all be there. <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>

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

<script type="text/javascript" src="http://PoshCode.org/embed/1504"></script>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/bba0ce48-3de7-4675-8c1a-a449e3ae8a96/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=bba0ce48-3de7-4675-8c1a-a449e3ae8a96" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/ignoring-namespaces-in-xpath/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Notepad++ For PowerShell Editing</title>
		<link>http://huddledmasses.org/using-notepad-plus-plus-for-powershell-editing/</link>
		<comments>http://huddledmasses.org/using-notepad-plus-plus-for-powershell-editing/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 02:09:08 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Notepad++]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scintilla]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Syntax Highlighting]]></category>

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

	A while back Thell Fowler (with a little help, and a lot of testing from me) wrote a very good PowerShell Lexer for Notepad++ 5.2 and later&#8230; it&#8217;s very thorough, has good code-folding, and full support for PowerShell 2.0 syntax highlighting.

	I mention this because Notepad++ 5.6 just released yesterday, and it has built-in support for [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_1341" class="wp-caption alignright" style="width: 310px"><a href="http://huddledmasses.org/wordpress/wp-content/uploads/2009/12/PowerShell_Lexer_Notepad++.png"><img src="http://huddledmasses.org/wordpress/wp-content/uploads/2009/12/PowerShell_Lexer_Notepad++-300x271.png" alt="The style I use has a nice black background..." title="PowerShell_Lexer_Notepad++" class="size-medium wp-image-1341" height="271" width="300" /></a><p class="wp-caption-text">The style I use has a nice black background...</p></div>

	<p>A while back Thell Fowler (with a little help, and a lot of testing from me) wrote a <strong>very</strong> good <a href="http://poshcode.org/notepad++lexer">PowerShell Lexer</a> for <a href="http://notepad-plus.sourceforge.net/uk/site.htm">Notepad++</a> 5.2 and later&#8230; it&#8217;s very thorough, has good <a class="zem_slink" href="http://en.wikipedia.org/wiki/Code_folding" title="Code folding" rel="wikipedia">code-folding</a>, and full support for PowerShell 2.0 syntax highlighting.</p>

	<p>I mention this because Notepad++ 5.6 just released yesterday, and it has built-in support for PowerShell syntax courtesy of <a class="zem_slink" href="http://www.scintilla.org/" title="Scintilla (editing component)" rel="homepage">Scintilla</a> ... but it&#8217;s <strong>very,</strong> <strong>very</strong> bad. The scintilla PowerShell lexer is probably the most minimal PowerShell lexer I&#8217;ve seen (it&#8217;s worse than the old &#8220;user style&#8221; I had created for Notepad++) and has no support for:</p>

	<p>	<ul>
		<li>The ` <a class="zem_slink" href="http://en.wikipedia.org/wiki/Escape_character" title="Escape character" rel="wikipedia">escape character</a> </li>
		<li>Here-strings (which can contain quotes, etc)</li>
		<li>The difference between strings and literal strings and literal here-strings</li>
		<li>The begin/process/end block keywords and Param() </li>
		<li>PowerShell operators (like -is or -gt or -notcontains)</li>
		<li>[System.Namespace.Class]::Method() syntaxes</li>
		<li>Nested $variables inside strings</li>
		<li>Nested $( code blocks ) inside strings (with strings inside those, and &#8230;)
		<li>Any of the new PowerShell 2 syntax like:
	<ul>
		<li>multi-line comments</li>
		<li>[Parameter()] and [Alias()] and [Validate &#8230;. ]</li>
	</ul></li>
	</ul>
	<ul>
		<li>[CmdletBinding()]</li>
	</ul></li></p>

	<p>There&#8217;s probably more, but I couldn&#8217;t be bothered to spend more than a couple of minutes with it. As you can probably guess &#8230; <strong>all of those features</strong> are supported by the external PowerShell Lexer plugin that Thell wrote, so if you&#8217;re a PowerShell and Notepad++ user, I apologize for not drawing your attention to our <a href="http://poshcode.org/notepad++lexer">PowerShell Lexer for Notepad++</a> before <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>

	<p>Incidentally, I stuck a screenshot in this post so you can see how <strong>I</strong> use it, but there&#8217;s one a more complete example of the <a href="http://poshcode.org/notepad++lexer">PowerShell Syntax Highlighting</a> on that lexer download page. <img src='http://huddledmasses.org/wordpress/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/fdf36a60-04ff-42dc-9722-b30ccfb8d28b/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=fdf36a60-04ff-42dc-9722-b30ccfb8d28b" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/using-notepad-plus-plus-for-powershell-editing/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
