<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">Media And Microcode</title><subtitle type="html">Microcode. Movies. Music. Games.  Personal Musings. - James Brundage's Personal Blog</subtitle><id>http://blogs.msdn.com/mediaandmicrocode/atom.xml</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/default.aspx" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/mediaandmicrocode/atom.xml" /><generator uri="http://communityserver.org" version="2.1.61025.2">Community Server</generator><updated>2008-11-30T02:10:27Z</updated><entry><title>New WPK Video Online: Multitouch Fingerpaint in 30 Lines of PowerShell Script</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2009/10/30/new-wpk-video-online-multitouch-fingerpaint-in-30-lines-of-powershell-script.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2009/10/30/new-wpk-video-online-multitouch-fingerpaint-in-30-lines-of-powershell-script.aspx</id><published>2009-10-30T20:32:21Z</published><updated>2009-10-30T20:32:21Z</updated><content type="html">&lt;p&gt;The 2nd video about WPK just hit Channel9.&amp;#160; The first video was a video walk thru of &lt;a href="http://channel9.msdn.com/posts/LarryLarsen/Quick-UI-with-WPK-in-Windows-PowerShell"&gt;How to Write User Interfaces with WPK&lt;/a&gt;, and this video walks thru &lt;a href="http://channel9.msdn.com/posts/LarryLarsen/Multitouch-Fingerpaint-in-30-Lines-of-PowerShell-Script/"&gt;How to Write a Multitouch FingerPaint with WPK&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;Enjoy,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT] &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9915455" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="MultiTouch" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/MultiTouch/default.aspx" /><category term="PowerShellPack" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShellPack/default.aspx" /><category term="WPK" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPK/default.aspx" /></entry><entry><title>Microcode: PowerShell Scripting Trick: Fun With Parameter Binding: The Fake Parameter Set Trick</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2009/04/10/microcode-powershell-scripting-trick-fun-with-parameter-binding-the-fake-parameter-set-trick.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2009/04/10/microcode-powershell-scripting-trick-fun-with-parameter-binding-the-fake-parameter-set-trick.aspx</id><published>2009-04-10T10:00:04Z</published><updated>2009-04-10T10:00:04Z</updated><content type="html">&lt;p&gt;I’ve been hearing a lot of questions recently about what things you can do with advanced functions.&amp;#160; People seem to be aching for good examples of using PowerShell V2 functions, and, since I’ve discovered a few handy tricks for advanced functions, I thought I’d start to share them there in a series called “Fun with Parameter Binding.”&lt;/p&gt;  &lt;p&gt;Here’s volume one: &lt;em&gt;The Fake Parameter Set Trick&lt;/em&gt;&lt;/p&gt;  &lt;p&gt;I found myself wanting to make an advanced function that took something strongly typed (in this case, the CommandInfo object, which is the base object for what you see when you run Get-Command) from the pipeline and returned items that matched a certain characteristic.&amp;#160; If I didn’t pipeline in any items, I wanted to get all of the commands and check for the same characteristic.&lt;/p&gt;  &lt;p&gt;What I really wanted was the function to act two ways, one parameterized, one unparameterized (like how you can run Get-Process or Get-Process PowerShell*)&lt;/p&gt;  &lt;p&gt;I know of one way to approach this, using the $psBoundParameters variable (&lt;a href="http://blogs.msdn.com/powershell/archive/2009/04/06/checking-for-bound-parameters.aspx"&gt;see this&lt;/a&gt; enlightening post by Marcel Ortiz Soto), but I recently happened upon another approach that I find kind of novel.&amp;#160; I call it the fake parameter set trick.&lt;/p&gt;  &lt;p&gt;Here’s an example:&lt;/p&gt;  &lt;pre class="PowerShellColorizedScript"&gt;&lt;span style="color: #a9a9a9"&gt;[&lt;/span&gt;&lt;span style="color: #add8e6"&gt;CmdletBinding&lt;/span&gt;&lt;span style="color: #000000"&gt;(&lt;/span&gt;&lt;span style="color: #000000"&gt;DefaultParameterSetName&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;=&lt;/span&gt;&lt;span style="color: #8b0000"&gt;&amp;quot;All&amp;quot;&lt;/span&gt;&lt;span style="color: #000000"&gt;)&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;]&lt;/span&gt;            
                
    &lt;span style="color: #00008b"&gt;param&lt;/span&gt;&lt;span style="color: #000000"&gt;(&lt;/span&gt;            
    &lt;span style="color: #a9a9a9"&gt;[&lt;/span&gt;&lt;span style="color: #add8e6"&gt;Parameter&lt;/span&gt;&lt;span style="color: #000000"&gt;(&lt;/span&gt;&lt;span style="color: #000000"&gt;Mandatory&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;=&lt;/span&gt;&lt;span style="color: #ff4500"&gt;$true&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;,&lt;/span&gt;            
        &lt;span style="color: #000000"&gt;ParameterSetName&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;=&lt;/span&gt;&lt;span style="color: #8b0000"&gt;&amp;quot;Command&amp;quot;&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;,&lt;/span&gt;            
        &lt;span style="color: #000000"&gt;ValueFromPipeline&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;=&lt;/span&gt;&lt;span style="color: #ff4500"&gt;$true&lt;/span&gt;&lt;span style="color: #000000"&gt;)&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;]&lt;/span&gt;            
    &lt;span style="color: #008080"&gt;[Management.Automation.CommandInfo]&lt;/span&gt;            
    &lt;span style="color: #ff4500"&gt;$command&lt;/span&gt;            
    &lt;span style="color: #000000"&gt;)&lt;/span&gt;            
                
    &lt;span style="color: #00008b"&gt;process&lt;/span&gt; &lt;span style="color: #000000"&gt;{&lt;/span&gt;            
        &lt;span style="color: #ff4500"&gt;$psCmdlet&lt;/span&gt;&lt;span style="color: #a9a9a9"&gt;.&lt;/span&gt;&lt;span style="color: #000000"&gt;ParameterSetName&lt;/span&gt;               
    &lt;span style="color: #000000"&gt;}&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The CmdletBinding attribute at the top of the function is one of the markers that the function is an advanced function, and it specifies the DefaultParameterSetName.&amp;#160; If no default parameter set name is specified, it would go ahead and default to whichever ParameterSetName it found on a parameter.&amp;#160; If you didn’t every mention a ParameterSetName, then the parameter set name would implicitly be __AllParameterSets.&lt;/p&gt;

&lt;p&gt;In my case, I’ve set the DefaultParameterSetName to All.&amp;#160; But there aren’t any parameters at all in All.&amp;#160; In fact, for All intents and purposes, All is nothing.&amp;#160; All is a fake parameter set.&lt;/p&gt;

&lt;p&gt;This lets me mark the $command parameter as mandatory and from pipeline, and lets me easily figure out if the parameter is there or not.&amp;#160; This is ideal for building good Get- advanced functions, because Get- cmdlets and functions tend to either be able to retrieve all of the data or retrieve a filtered subset of the data.&lt;/p&gt;

&lt;p&gt;Hope this Helps,&lt;/p&gt;

&lt;p&gt;James Brundage&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9542628" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="Scripting Tricks" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+Tricks/default.aspx" /><category term="Fun With Parameter Binding" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Fun+With+Parameter+Binding/default.aspx" /></entry><entry><title>Microcode: A Quick Trick to turn regular XML into Xaml</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/22/microcode-a-quick-trick-to-turn-regular-xml-into-xaml.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/22/microcode-a-quick-trick-to-turn-regular-xml-into-xaml.aspx</id><published>2009-01-22T13:07:36Z</published><updated>2009-01-22T13:07:36Z</updated><content type="html">&lt;p&gt;MSDN has tons of examples about XAML.&amp;nbsp; Nearly everything in WPF has an example in XAML, but not all of these XAML examples actually reference the namespace that is required for this Xaml to be loadable by WPF.&amp;nbsp; It's still valid XML, just not valid XAML.&lt;/p&gt; &lt;p&gt;Here's a quick example of what I mean.&amp;nbsp; I just copied and pasted this chunk from the MSDN topic on &lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.media.lineargradientbrush.aspx"&gt;LinearGradientBrush&lt;/a&gt;:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&amp;lt;!-- This rectangle is painted with a diagonal linear gradient. --&amp;gt;&lt;br&gt;&amp;lt;Rectangle Width="200" Height="100"&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;Rectangle.Fill&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LinearGradientBrush StartPoint="0,0" EndPoint="1,1"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Yellow" Offset="0.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Red" Offset="0.25" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Blue" Offset="0.75" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="LimeGreen" Offset="1.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/LinearGradientBrush&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;/Rectangle.Fill&amp;gt;&lt;br&gt;&amp;lt;/Rectangle&amp;gt;&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Now if I try to simply load that up as XAML, XamlReader barfs&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;$x&amp;nbsp; =[xml]'&amp;lt;!-- This rectangle is painted with a diagonal linear gradient. --&amp;gt;&lt;br&gt;&amp;lt;Rectangle Width="200" Height="100"&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;Rectangle.Fill&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;LinearGradientBrush StartPoint="0,0" EndPoint="1,1"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Yellow" Offset="0.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Red" Offset="0.25" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="Blue" Offset="0.75" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;GradientStop Color="LimeGreen" Offset="1.0" /&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/LinearGradientBrush&amp;gt;&lt;br&gt;&amp;nbsp; &amp;lt;/Rectangle.Fill&amp;gt;&lt;br&gt;&amp;lt;/Rectangle&amp;gt;&lt;br&gt;'  &lt;p&gt;[Windows.Markup.XamlReader]::Parse($x.OuterXml)&lt;/p&gt;&lt;/blockquote&gt; &lt;blockquote&gt; &lt;p style="color: red"&gt;Exception calling "Parse" with "1" argument(s): "'' XML namespace prefix does not map to a namespace URI, so cannot resolve property 'Width'. Line '1' Position '79'."&lt;br&gt;At line:14 char:35&lt;br&gt;+ [Windows.Markup.XamlReader]::Parse &amp;lt;&amp;lt;&amp;lt;&amp;lt; ($x.OuterXml)&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : NotSpecified: (:) [], MethodInvocationException&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : DotNetMethodException&lt;pre&gt;&lt;/pre&gt;&lt;/blockquote&gt;
&lt;p&gt; Obviously, that's not ideal.&amp;nbsp; Luckily, with CTP3, there's a cmdlet called Select-Xml, which will allow me to query a document with xPath, regardless of namespaces.&lt;/p&gt;
&lt;p&gt;This means that I can check to see if the fist element has a reference to the WPF namespace, and add it if it's not there.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;$t = $x |&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select-Xml //* | &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Select-Object -First 1 | &lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Foreach-Object {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (-not $_.Node.xmlns) {&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_.Node.SetAttribute("xmlns", '&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation')"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation')&lt;/a&gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $_.Node.OuterXml&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;I'll stop and explain this pipeline a little.&amp;nbsp; $x is the XML, I pipe it into Select-Xml, with the xPath parameter of //*.&amp;nbsp; //* roughly translates to any node.&amp;nbsp; I pick out the first node (with Select-Object -first 1) and then I check to see if the Node contains an xmlns attribute.&amp;nbsp; If it doesn't, I add it.&amp;nbsp; Either way, I emit the first node's OuterXml, which basically means I emit the entire XML chunk as text.&amp;nbsp; That's what $t is when I am done.
&lt;p&gt;Then I use this chunk to display it:
&lt;blockquote&gt;
&lt;p&gt;$w = New-Object Windows.Window&lt;br&gt;$w.Content = [Windows.Markup.XamlReader]::Parse($t)&lt;br&gt;$w.SizeToContent = "WidthAndHeight"&lt;br&gt;$w.ShowDialog()&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Now I have the MSDN sample working, regardless of if it had an xmlns attribute in the first place.&lt;/p&gt;
&lt;p&gt;Hope this Helps,&lt;/p&gt;
&lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9365908" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="Select-Object" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx" /><category term="WPF" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPF/default.aspx" /><category term="Select-Xml" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Xml/default.aspx" /></entry><entry><title>Media: The Moment Obama Got Inaugurated and PhotoSynth Hit Mainstream</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/20/media-the-moment-obama-got-inaugurated-and-photosynth-hit-mainstream.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/20/media-the-moment-obama-got-inaugurated-and-photosynth-hit-mainstream.aspx</id><published>2009-01-20T23:12:34Z</published><updated>2009-01-20T23:12:34Z</updated><content type="html">&lt;p&gt;&lt;a href="http://photosynth.net/"&gt;Photosynth&lt;/a&gt; is a really cool product out of live labs.&amp;#160; It's sort of an uber photo collage application.&amp;#160; It takes photos taken from different people, at different resolutions and different times, and collects them into a 3d view of a location that you can navigate around.&lt;/p&gt;  &lt;p&gt;CNN.com worked with Photosynth to show the world the Moment of Obama's Inauguration.&amp;#160; It's a pretty cool way to view history.&lt;/p&gt;  &lt;p&gt;Check it out:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://www.cnn.com/SPECIALS/2009/44.president/inauguration/themoment/" href="http://www.cnn.com/SPECIALS/2009/44.president/inauguration/themoment/"&gt;http://www.cnn.com/SPECIALS/2009/44.president/inauguration/themoment/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Hope this Helps,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9350720" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="Media" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Media/default.aspx" /><category term="Photosynth" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Photosynth/default.aspx" /></entry><entry><title>PowerScripting Podcast Online</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/19/powerscripting-podcast-online.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/19/powerscripting-podcast-online.aspx</id><published>2009-01-20T00:44:35Z</published><updated>2009-01-20T00:44:35Z</updated><content type="html">&lt;p&gt;My interview with the PowerScripting Podcast is now online.&amp;#160; Check it out:&lt;/p&gt;  &lt;p&gt;&lt;a title="http://powerscripting.wordpress.com/2009/01/18/episode-55-jeff-hicks-in-for-hal-and-an-interview-with-james-brundage/" href="http://powerscripting.wordpress.com/2009/01/18/episode-55-jeff-hicks-in-for-hal-and-an-interview-with-james-brundage/"&gt;http://powerscripting.wordpress.com/2009/01/18/episode-55-jeff-hicks-in-for-hal-and-an-interview-with-james-brundage/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Hope this helps,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9340839" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author></entry><entry><title>Please Join Me for a Power Scripting Podcast Tonight @ 9PM EST (6PM PST)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/15/please-join-me-for-a-power-scripting-podcast-tonight-9pm-est-6pm-pst.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/15/please-join-me-for-a-power-scripting-podcast-tonight-9pm-est-6pm-pst.aspx</id><published>2009-01-15T21:30:11Z</published><updated>2009-01-15T21:30:11Z</updated><content type="html">&lt;p&gt;I’m going to be doing a PowerScripting Podcast tonight @ 9PM EST.&amp;#160; There’s a live chat room where you can ask questions and pick the brains of a tester / avid scripter on the PowerShell team.&lt;/p&gt;  &lt;p&gt;It should be fun.&amp;#160; I hope to see your questions there.&lt;/p&gt;  &lt;p&gt;&lt;a title="http://powerscripting.wordpress.com/2009/01/14/tomorrow-on-powerscripting-live-james-brundage/" href="http://powerscripting.wordpress.com/2009/01/14/tomorrow-on-powerscripting-live-james-brundage/"&gt;http://powerscripting.wordpress.com/2009/01/14/tomorrow-on-powerscripting-live-james-brundage/&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Hope this Helps,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9321313" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author></entry><entry><title>Media: The Future of Newspapers is Pay For Play Journalism?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/28/media-the-future-of-newspapers-is-pay-for-play-journalism.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/28/media-the-future-of-newspapers-is-pay-for-play-journalism.aspx</id><published>2008-12-28T03:45:35Z</published><updated>2008-12-28T03:45:35Z</updated><content type="html">&lt;p&gt;I love my news.&amp;#160; For whatever reason, I find catching up on the world to be one of the most relaxing and rewarding things you can do in your spare time.&amp;#160; Even though I like to read the news, I rarely read a physical newspaper or magazine or watch a news program .&amp;#160; My cell phone and web browser are my gateways to the news world.&amp;#160; I make an exception for especially good local weeklies (Seattle's &lt;a href="http://www.thestranger.com/"&gt;The Stranger&lt;/a&gt;) and very insightful magazines with a broad range of news ( like &lt;a href="http://www.economist.com/"&gt;The Economist&lt;/a&gt; ).&amp;#160; But times are tough for newspapers and magazines alike.&amp;#160; Local small-market newspapers are dropping like flies, and even big outfits like &lt;a href="http://www.nytimes.com/"&gt;The New York Times&lt;/a&gt; are struggling.&amp;#160; Digitization has been a painfully slow paradigm shift with major publications.&lt;/p&gt;  &lt;p&gt;This is primarily because of a loss in advertising revenue on many fronts.&amp;#160; It's harder to convince a businessman to buy a 6&amp;quot; ad for hundreds of dollars upfront with limited tracking and return when they can buy a search keyword for a fraction of that.&amp;#160; It's also very hard to convince someone to put a classified ad in at a dollar a word when &lt;a href="http://www.craigslist.org/"&gt;Craigslist&lt;/a&gt; will do it for free.&amp;#160; So it's no suprise that there have been any number of propositions about &amp;quot;the future of newspapers.&amp;quot;&amp;#160; Most are still advertising focused,&amp;#160; and the general mind set in publishing still seems to ignore what happens when &lt;a href="http://en.wikipedia.org/wiki/The_Long_Tail"&gt;the Long Tail effect&lt;/a&gt; hits news and ignoring the peril of wire services.&amp;#160; By this I mean that if finding the news I am interested in is no longer restricted by where I am, then I'll end up reading publications from wherever news comes that interests me, and it becomes harder for any publication to really gain a mental foothold.&amp;#160; Further more, if every time I pick up a newspaper, 80% of the content comes from a news wire service, then that newspaper is no different from any other newspaper I'd run across, and I'm no more or less likely to pick it up in the future.&lt;/p&gt;  &lt;p&gt;This is a very tricky situation, that presents no great way out.&amp;#160; But today, I ran across a way that is so worrisomely bad that I've decided to talk about it here.&lt;/p&gt;  &lt;p&gt;Ironically, I ran this very bad answer to the problems newspapers are facing on &lt;a href="http://www.good.is/"&gt;Good&lt;/a&gt;, through a link on MSN title &lt;a href="http://www.good.is/?p=14300&amp;amp;GT1=34127"&gt;&amp;quot;When Newspapers Are Gone&amp;quot;&lt;/a&gt;.&amp;#160; This is an article about a web site called &lt;a href="http://www.spot.us/"&gt;Spot.Us&lt;/a&gt;, where a few community minded individuals pay a reporter to write a news story.&amp;#160; &lt;/p&gt;  &lt;p&gt;In my personal opinion, this is a very, very bad idea.&lt;/p&gt;  &lt;p&gt;Why?&lt;/p&gt;  &lt;p&gt;First and foremost, it's &amp;quot;pay for play&amp;quot; journalism.&amp;#160; If this is the future of news, then the future of news will mean that people who cannot afford to be covered will not be.&amp;#160; What's that mean?&amp;#160; Well, unless you get a lot of donations from a lot of people, no coverage of any danger zone, so most likely no international coverage whatsoever.&amp;#160; If this sort of news becomes popular, than suffering becomes a &amp;quot;tree falls in a forest&amp;quot; problem.&amp;#160; If 1,000 people are killed in an earthquake due to shoddy infrastructure, and no one can afford to report on it, do their deaths mean anything?&lt;/p&gt;  &lt;p&gt;The second problem is what I call NIMBY journalism (NIMBY is &lt;em&gt;Not In My Backyard&lt;/em&gt;).&amp;#160; An individual can provide up to 20% of the amount required to cover a story, which means that a small group of individuals can fund a story of their own liking. Don't like that eyesore building going up across the street?&amp;#160; Pool 5 of your neighbors and have someone you've never met run a news story about the decline and fall of your neighborhoods look.&amp;#160; Concerned about increasing homelessness in your area?&amp;#160; Fund an article pushing for a homeless shelter far away.&lt;/p&gt;  &lt;p&gt;The third problem is funding transparency.&amp;#160; If only a few people can fund a story on Spot.Us, which pitches the story to other major outlets, then it's possible to get stories written that back up your political beliefs.&amp;#160; While Spot.Us does have &amp;quot;fact-checking editors&amp;quot; (a freelance journalist can turn down the first two if they choose), there's little on who watches the watchdogs, less on how retractions work, and nothing that I can see that would prevent individuals with different political slants from funding a story.&amp;#160; As the story is picked up by other outlets, both patent lies and innuendo can seep into the news cycle with a significantly greater pedigree than information recycled from blogs.&amp;#160; While you can see the individuals that sponsored the article on Spot.Us, you do not have any information about their affiliations with companies, and it's unlikely that whoever would pick up a story from Spot.Us would list the individuals who paid for the article.&lt;/p&gt;  &lt;p&gt;The fourth problem is that pitch-based news doesn't come up with the news no one wants to hear.&amp;#160; A simple and sarcastic example of this was my time (12 years) writing film reviews.&amp;#160; During this time, I saw a lot of movies I suspected would be awful, not because I particularly wanted to, but because &lt;em&gt;someone &lt;/em&gt;has to and my editor gave me marching orders to cover the movies.&amp;#160; Some of them were awful, some of them were unexpectedly great. When journalists do their own pitching of stories entirely, the editorial process is greatly degraded, because people simply do not go out to cover many things, like violent crime (or exceedingly bad movies), without being told to do so.&amp;#160; Sometimes the best stories start from the most mundane pieces of information.&lt;/p&gt;  &lt;p&gt;The fifth problem is the transparency in the expenses of a story.&amp;#160; Salaried employees of a newspaper can sometimes expense costs of the story to a newspaper, but there is a lot of transparency in the process.&amp;#160; Receipts must be kept.&amp;#160; Purchases must be justified.&amp;#160; As much as I wish journalists were paid better for their work, I do not believe that they should be their own accountants or set all of their own rates.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.spot.us/news_items"&gt;A quick look of the story pitches on Spot.Us&lt;/a&gt; gives a lot of foundation for these concerns.&amp;#160;&amp;#160; Right now, I see a pitch about problems with state adopted children ($500 required), a pitch about a retirement community residents who had to resign from a community board because they formed their own online paper ($25 required), a pitch about why the VOA takes too long to process claims ($1000), a pitch to cover the poor in San Francisco ($500), a pitch about the digital future of Bay Area newspapers ($1000), a pitch about the electricity sources in the Bay Area ($1500), a pitch about if Oakland can survive the next quake ($450), and a pitch about how the recession is hitting bay area hookers ($500).&amp;#160; Each of these pitches raises a lot of questions about what the money's being spent on (especially the last one) and why the rates are so wildly different.&amp;#160; I'd go out on a limb and guess that the community board pitch ($25) is someone who wants to give more legitimacy to their community association dispute.&amp;#160; That there's even a pitch for a digitization of news story on an online news site raises obvious conflict of interest questions.&amp;#160; Several of the stories seem wildly overvalued, and others incredibly under expensed (how can someone assess is Oakland is ready for the next quake for $450?).&amp;#160; Magazines with great readership (hundreds of thousands or even millions) will generally not pay more than a few thousand dollars a story to a freelancer.&amp;#160; Why is a story that can be researched from a laptop while sipping a latte worth $1000?&lt;/p&gt;  &lt;p&gt;I apologize to veer off my normal course of technical information and highlighting interesting information that I find online, but the idea of journalism as funded by the angry mob makes me very worried.&amp;#160; Journalism should help the mob become incensed about what they do not know, not become the voice of the angry mob to recruit more members.&amp;#160; Journalists should calm the mob when it is irrationally angry, and not owe their paycheck to the mob.&amp;#160; Journalists should show be a check and balance to the world, instead of balancing their checkbooks by what their neighborhood says is right.&lt;/p&gt;  &lt;p&gt;Hope this Helps,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9254644" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="Media" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Media/default.aspx" /></entry><entry><title>Microcode: PowerShell + XNA: New-SpriteFont</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/24/microcode-powershell-xna-new-spritefont.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/24/microcode-powershell-xna-new-spritefont.aspx</id><published>2008-12-24T13:07:46Z</published><updated>2008-12-24T13:07:46Z</updated><content type="html">&lt;p class="PostHeader"&gt;As I said in a previous post, I've started to explore the wild world of &lt;a href="http://creators.xna.com"&gt;XNA&lt;/a&gt;. XNA just released version 3, which allows you to make games for Windows, Xbox, and Zune. The SDK is free, and you can download it &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7D70D6ED-1EDD-4852-9883-9A33C0AD8FEE&amp;amp;displaylang=en"&gt;here&lt;/a&gt;.&lt;/p&gt;  &lt;p class="PostHeader"&gt;&lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/24/microcode-powershell-scripting-tricks-get-font.aspx"&gt;The last post introduced Get-Font&lt;/a&gt;, a quick function that lets me see what fonts are on the system. I wrote this function to save me the potential future headache of making a typo in my SpriteFont file, and in this post I'll show you New-SpriteFont, which uses Get-Font and emits a Sprite Font file with a number of parameters for any font on my system.&lt;/p&gt;  &lt;p class="PostHeader"&gt;New-SpriteFont was fairly straightforward. I simply check for any font that is named what I say, and throw an error if one is not found. Then I copied a sprite font file from the sample Platformer project into my function, and added a parameter for each part of the XML I wanted to parameterize in a script. Since font names cannot contain characters that would trouble XML (and I've already checked to make sure the font exists), I don't need to worry about escaping my XML for the font name. Almost everything else was an integer, except for style. The only interesting curve ball that the spritefont XML threw me was that it used a lowercase true. True will read as &amp;quot;True&amp;quot;, and since XML is case-sensitive (even though PowerShell is not), I coerced the switch parameter into a string and then turned the string into a lowercase string.&lt;/p&gt;  &lt;p class="PostHeader"&gt;Then I tacked on some inline help, and I had a New-SpriteFont that did the trick. I'm using &lt;a href="http://blogs.msdn.com/powershell/archive/2008/12/24/write-commandblogpost.aspx"&gt;Write-CommandBlogPost&lt;/a&gt; to write up New-SpriteFont for public consumption. Enjoy!&lt;/p&gt;  &lt;br /&gt;  &lt;p class="CmdletSynopsis"&gt;&lt;b&gt;Synopsis:&lt;/b&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;blockquote&gt;Creates a New XNA SpriteFont &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;br /&gt;  &lt;p class="CmdletSyntax"&gt;&lt;b&gt;Syntax:&lt;/b&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;blockquote&gt;New-SpriteFont [[-font] [&amp;lt;Object&amp;gt;]] [[-size] [&amp;lt;Int32&amp;gt;]] [[-spacing] [&amp;lt;Int32&amp;gt;]] [[-style] [&amp;lt;Object&amp;gt;]] [&amp;lt;CommonParameters&amp;gt;] &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;br /&gt;  &lt;p class="CmdletDescription"&gt;&lt;b&gt;Detailed Description:&lt;/b&gt;    &lt;br /&gt;&lt;/p&gt;  &lt;blockquote&gt;Generates an XNA SpriteFont file. Allows you to specify the font name, size, spacing, style, and if kerning is used or not &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;br /&gt;  &lt;p class="Examples"&gt;Examples: &lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="CmdletExample"&gt;    -------------------------- EXAMPLE 1 --------------------------





# Create a simple New sprite font
New-SpriteFont
    &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;pre class="CmdletExample"&gt;    -------------------------- EXAMPLE 2 --------------------------





# Create a sprite font using the font Garamond and a fontsize of 12
New-SpriteFont &amp;quot;Garamond&amp;quot; 12
    &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p class="CmdletParameters"&gt;Command Parameters: &lt;/p&gt;

&lt;blockquote&gt;
  &lt;table&gt;&lt;colgroup&gt;&lt;col /&gt;&lt;col /&gt;&lt;/colgroup&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;th&gt;Name&lt;/th&gt;

        &lt;th&gt;Description&lt;/th&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td&gt;font&lt;/td&gt;

        &lt;td&gt;The font name of the XNA sprite font to use (default Lucida Console)&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td&gt;size&lt;/td&gt;

        &lt;td&gt;The font size of the XNA Sprite Font (default 14)&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td&gt;spacing&lt;/td&gt;

        &lt;td&gt;The spacing between the fonts (default 0)&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td&gt;useKerning&lt;/td&gt;

        &lt;td&gt;If set, the XNA sprite font will use kerning&lt;/td&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td&gt;style&lt;/td&gt;

        &lt;td&gt;The style of the font (e.g. Regular, Bold, Italic)&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p&gt;Here's New-SpriteFont: &lt;i&gt;&lt;/i&gt;

  &lt;blockquote&gt;
    &lt;pre class="CmdletDefinition"&gt;function New-SpriteFont {
           
    &amp;lt;#
    .Synopsis
        Creates a New XNA SpriteFont
    .Description
        Generates an XNA SpriteFont file.  Allows you to specify the font name, size, spacing, style, and if kerning is used or not
    .Parameter font
        The font name of the XNA sprite font to use (default Lucida Console)
    .Parameter size
        The font size of the XNA Sprite Font (default 14)
    .Parameter spacing
        The spacing between the fonts (default 0)
    .Parameter useKerning
        If set, the XNA sprite font will use kerning
    .Parameter style
        The style of the font (e.g. Regular, Bold, Italic)
    .Link
        Get-Font
    .Example
        # Create a simple New sprite font
        New-SpriteFont
    .Example
        # Create a sprite font using the font Garamond and a fontsize of 12
        New-SpriteFont &amp;quot;Garamond&amp;quot; 12
    #&amp;gt;
param($font = &amp;quot;Lucida Console&amp;quot;,
    [int]$size = 14,
    [int]$spacing = 0,
    [switch]$useKerning,
    $style = &amp;quot;Regular&amp;quot;)
if (-not (Get-Command Get-Font -ErrorAction SilentlyContinue )) { throw $error[0] }
    $checkedFont = Get-Font $font
    if (-not $checkedFont) {
        throw &amp;quot;The font name $font is not valid. Pick a new one a-hole.&amp;quot;
    }
@&amp;quot;
&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;utf-8&amp;quot;?&amp;gt;
&amp;lt;!--
This file contains an xml description of a font, and will be read by the XNA
Framework Content Pipeline. Follow the comments to customize the appearance
of the font in your game, and to change the characters which are available to draw
with.
--&amp;gt;
&amp;lt;XnaContent xmlns:Graphics=&amp;quot;Microsoft.Xna.Framework.Content.Pipeline.Graphics&amp;quot;&amp;gt;
  &amp;lt;Asset Type=&amp;quot;Graphics:FontDescription&amp;quot;&amp;gt;

    &amp;lt;!--
    Modify this string to change the font that will be imported.
    --&amp;gt;
    &amp;lt;FontName&amp;gt;$font&amp;lt;/FontName&amp;gt;

    &amp;lt;!--
    Size is a float value, measured in points. Modify this value to change
    the size of the font.
    --&amp;gt;
    &amp;lt;Size&amp;gt;$size&amp;lt;/Size&amp;gt;

    &amp;lt;!--
    Spacing is a float value, measured in pixels. Modify this value to change
    the amount of spacing in between characters.
    --&amp;gt;
    &amp;lt;Spacing&amp;gt;$spacing&amp;lt;/Spacing&amp;gt;

    &amp;lt;!--
    UseKerning controls the layout of the font. If this value is true, kerning information
    will be used when placing characters.
    --&amp;gt;
    &amp;lt;UseKerning&amp;gt;$($useKerning.ToString().ToLower())&amp;lt;/UseKerning&amp;gt;

    &amp;lt;!--
    Style controls the style of the font. Valid entries are &amp;quot;Regular&amp;quot;, &amp;quot;Bold&amp;quot;, &amp;quot;Italic&amp;quot;,
    and &amp;quot;Bold, Italic&amp;quot;, and are case sensitive.
    --&amp;gt;
    &amp;lt;Style&amp;gt;$style&amp;lt;/Style&amp;gt;

    &amp;lt;!--
    If you uncomment this line, the default character will be substituted if you draw
    or measure text that contains characters which were not included in the font.
    --&amp;gt;
    &amp;lt;!-- &amp;lt;DefaultCharacter&amp;gt;*&amp;lt;/DefaultCharacter&amp;gt; --&amp;gt;

    &amp;lt;!--
    CharacterRegions control what letters are available in the font. Every
    character from Start to End will be built and made available for drawing. The
    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
    character set. The characters are ordered according to the Unicode standard.
    See the documentation for more information.
    --&amp;gt;
    &amp;lt;CharacterRegions&amp;gt;
      &amp;lt;CharacterRegion&amp;gt;
        &amp;lt;Start&amp;gt;&amp;amp;#32;&amp;lt;/Start&amp;gt;
        &amp;lt;End&amp;gt;&amp;amp;#126;&amp;lt;/End&amp;gt;
      &amp;lt;/CharacterRegion&amp;gt;
    &amp;lt;/CharacterRegions&amp;gt;
  &amp;lt;/Asset&amp;gt;
&amp;lt;/XnaContent&amp;gt;
&amp;quot;@    

}    &lt;/pre&gt;
  &lt;/blockquote&gt;
&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p class="Postfooter"&gt;Hope this Helps,&lt;/p&gt;

&lt;p class="Postfooter"&gt;James Brundage [MSFT]&lt;/p&gt;

&lt;p style="font-size: xx-small"&gt;Automatically generated with &lt;a href="http://blogs.msdn.com/powershell/archive/tags/Write-CommandBlogPost/default.aspx"&gt;Write-CommandBlogPost&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9251648" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="PowerShell" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx" /><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="XNA" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/XNA/default.aspx" /><category term="Get-Font" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Font/default.aspx" /><category term="New-SpriteFont" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/New-SpriteFont/default.aspx" /></entry><entry><title>Microcode: PowerShell Scripting Tricks: Get-Font</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/24/microcode-powershell-scripting-tricks-get-font.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/24/microcode-powershell-scripting-tricks-get-font.aspx</id><published>2008-12-24T12:33:57Z</published><updated>2008-12-24T12:33:57Z</updated><content type="html">&lt;p class="PostHeader"&gt;I've started to explore the wild world of &lt;a href="http://creators.xna.com"&gt;XNA&lt;/a&gt;. XNA just released version 3, which allows you to make games for Windows, Xbox, and Zune. The SDK is free, and you can download it &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7D70D6ED-1EDD-4852-9883-9A33C0AD8FEE&amp;amp;displaylang=en"&gt;here&lt;/a&gt;. It comes with a nifty little platformer game (think a 3-screen Super Mario Brothers), which helps a lot with the process of learning XNA.&lt;/p&gt;  &lt;p class="PostHeader"&gt;XNA involves a lot of little resource files, including one called a SpriteFont. The format for a SpriteFont file is really simple XML, so I decided to make a quick PowerShell function that would create a sprite font file. I could be very lazy, and simply accept whatever font name they gave me on faith, but I'm sure I would be very frustrated the first time I typed New-SpriteFont Arrial, and spent the next 15 minutes of my life wondering why my project wasn't compiling when all that was wrong was an extra 'r'. To save myself this future pain, I've made Get-Font, so New-SpriteFont can check what fonts exist before creating the file.&lt;/p&gt;  &lt;p class="PostHeader"&gt;Making Get-Font wasn't all that hard. I simply used my Get-Type function to find all of the types named fonts (Get-Type | Where-Object { .Name -eq &amp;quot;Fonts&amp;quot; } | Select FullName) and then explored static member properties. I wrote Get-Font in the Windows PowerShell Integrated Scripting Editor, so I added a check to load up the right assembly (which I also found out by using Get-Type) in case I was trying to use Get-Font from the PowerShell console. All told, Get-Font took about 5 minutes to write, and ended up being a quick PowerShell lesson for my girlfriend. I added inline help, and then I was done. Here's Get-Font. I'll show New-SpriteFont in a separate post.&lt;/p&gt;  &lt;br /&gt;  &lt;p class="CmdletName"&gt;Get-Font&lt;/p&gt;  &lt;br /&gt;  &lt;p class="CmdletSynopsis"&gt;&lt;b&gt;Synopsis:&lt;/b&gt;     &lt;br /&gt;&lt;/p&gt;  &lt;blockquote&gt;Gets the fonts currently loaded on the system &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;br /&gt;  &lt;p class="CmdletSyntax"&gt;&lt;b&gt;Syntax:&lt;/b&gt;     &lt;br /&gt;&lt;/p&gt;  &lt;blockquote&gt;Get-Font [[-font] [&amp;lt;Object&amp;gt;]] [&amp;lt;CommonParameters&amp;gt;] &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;br /&gt;  &lt;p class="CmdletDescription"&gt;&lt;b&gt;Detailed Description:&lt;/b&gt;     &lt;br /&gt;&lt;/p&gt;  &lt;blockquote&gt;Uses the type System.Windows.Media.Fonts static property SystemFontFamilies,    &lt;br /&gt;to retrieve all of the fonts loaded by the system. If the Fonts type is not found,     &lt;br /&gt;the PresentationCore assembly will be automatically loaded &lt;/blockquote&gt;  &lt;p&gt;&lt;/p&gt;  &lt;br /&gt;  &lt;p class="Examples"&gt;Examples: &lt;/p&gt;  &lt;blockquote&gt;   &lt;pre class="CmdletExample"&gt;    -------------------------- EXAMPLE 1 --------------------------





# Get All Fonts
Get-Font
    &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;blockquote&gt;
  &lt;pre class="CmdletExample"&gt;    -------------------------- EXAMPLE 2 --------------------------





# Get All Lucida Fonts
Get-Font *Lucida*
    &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p class="CmdletParameters"&gt;Command Parameters: &lt;/p&gt;

&lt;blockquote&gt;
  &lt;table&gt;&lt;colgroup&gt;&lt;col /&gt;&lt;col /&gt;&lt;/colgroup&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;th&gt;Name&lt;/th&gt;

        &lt;th&gt;Description&lt;/th&gt;
      &lt;/tr&gt;

      &lt;tr&gt;
        &lt;td&gt;font&lt;/td&gt;

        &lt;td&gt;A wildcard to search for font names&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p&gt;Here's Get-Font: &lt;i&gt;&lt;/i&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;pre class="CmdletDefinition"&gt;function Get-Font {
           
    &amp;lt;#
    .Synopsis
        Gets the fonts currently loaded on the system
    .Description
        Uses the type System.Windows.Media.Fonts static property SystemFontFamilies,
        to retrieve all of the fonts loaded by the system.  If the Fonts type is not found,
        the PresentationCore assembly will be automatically loaded
    .Parameter font
        A wildcard to search for font names
    .Example
        # Get All Fonts
        Get-Font
    .Example
        # Get All Lucida Fonts
        Get-Font *Lucida*
    #&amp;gt;
    param($font = &amp;quot;*&amp;quot;)
if (-not (&amp;quot;Windows.Media.Fonts&amp;quot; -as [Type])) {
        Add-Type -AssemblyName &amp;quot;PresentationCore&amp;quot;
    }       

    [Windows.Media.Fonts]::SystemFontFamilies |
        Where-Object { $_.Source -like &amp;quot;$font&amp;quot; } 

}
    &lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;br /&gt;

&lt;p class="Postfooter"&gt;Hope this Helps,&lt;/p&gt;

&lt;p class="Postfooter"&gt;James Brundage [MSFT]&lt;/p&gt;

&lt;p style="font-size: xx-small"&gt;Automatically generated with &lt;a href="http://blogs.msdn.com/powershell/archive/tags/Write-CommandBlogPost/default.aspx"&gt;Write-CommandBlogPost&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9251628" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="PowerShell" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx" /><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="XNA" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/XNA/default.aspx" /><category term="Get-Font" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Font/default.aspx" /></entry><entry><title>Microcode: Cool Posts: Visual Studio Tips &amp; Tricks</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/17/microcode-cool-posts-visual-studio-tips-tricks.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/17/microcode-cool-posts-visual-studio-tips-tricks.aspx</id><published>2008-12-18T01:57:11Z</published><updated>2008-12-18T01:57:11Z</updated><content type="html">&lt;p&gt;&lt;a href="http://blogs.msdn.com/benko/archive/2008/12/17/visual-studio-tips-tricks-listing.aspx"&gt;Benko&lt;/a&gt; just posted a &lt;a href="http://blogs.msdn.com/benko/archive/2008/12/17/visual-studio-tips-tricks-listing.aspx"&gt;Visual Studio Tips &amp;amp; Tricks&lt;/a&gt; listing.&amp;#160; It's missing on of my favorites, which a coworker on the PowerShell team, Ibrahim Abdul Rahim, showed me:&lt;/p&gt;  &lt;p&gt;In a couple of circumstances, you'll see a red squiggle (like a syntax error) at the end of a line.&amp;#160; This squiggle occurs when you're renaming something, or when you're referencing a class that exist in a namespace that hasn't been used.&amp;#160; If you press ALT + SHIFT + F10, you'll get a handy menu that allows you to rename all of the references or add a &amp;quot;using&amp;quot; to that namespace.&amp;#160; Since this is the first option, and both are really handy, you can fly using this keyboard combo in visual studio by using ALT + SHIFT + F10 + ENTER (to select the first item and add the using or rename other mentions of a property).&lt;/p&gt;  &lt;p&gt;Hope this helps,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9232231" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="Visual Studio" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Visual+Studio/default.aspx" /><category term="Cool Posts" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Cool+Posts/default.aspx" /></entry><entry><title>Media: xBox 360: 70 XNA Games in 24 Days</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/13/media-xbox-360-70-xna-games-in-24-days.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/13/media-xbox-360-70-xna-games-in-24-days.aspx</id><published>2008-12-13T14:26:50Z</published><updated>2008-12-13T14:26:50Z</updated><content type="html">&lt;p&gt;It’s the weekend.&amp;#160; I love my video games, and I really love my xBox 360.&amp;#160; I’ve had one since just after they first came out, and I’ve slowly but surely accumulated about 70 physical games for the 360 made by major producers.&amp;#160; I remember seeing the total xBox 360 games climb past one hundred, and I remember losing count.&amp;#160; But until now, it’s been rare to see more than a few games come out each month.&lt;/p&gt;  &lt;p&gt;But now there’s &lt;a href="http://www.xna.com/"&gt;XNA&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;XNA is a way for Joe Schmoe to write (and now profit) off of writing video games.&amp;#160; Using XNA, you can write video games in C#.&amp;#160; It’s been possible to write XNA games for a couple of years, but it was only November 19th that XNA games went out on xBox Live and were up for sale.&lt;/p&gt;  &lt;p&gt;It’s been 24 days since then, and there are 70 community games on Xbox Live.&amp;#160; They range from 200-800 points (~$3-~$10) and a large chunk of the cash goes to the one or two people that develop the games.&amp;#160; They all have free trial versions.&lt;/p&gt;  &lt;p&gt;So support poor game developers.&amp;#160; Fire up your xbox 360 and check some XNA games out.&lt;/p&gt;  &lt;p&gt;Enjoy,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9208502" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="Media" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Media/default.aspx" /><category term="XNA" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/XNA/default.aspx" /><category term="Xbox 360" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Xbox+360/default.aspx" /></entry><entry><title>Microcode: PowerShell Scripting Tricks: Scripting the Web (Part 3) (Resolve-Link, Get-WebPageLink)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/12/microcode-powershell-scripting-tricks-scripting-the-web-part-3-resolve-link-get-webpagelink.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/12/microcode-powershell-scripting-tricks-scripting-the-web-part-3-resolve-link-get-webpagelink.aspx</id><published>2008-12-12T12:59:00Z</published><updated>2008-12-12T12:59:00Z</updated><content type="html">&lt;P&gt;The first post in this series was learning to crawl.&amp;nbsp; I introduced &lt;A href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/01/microcode-powershell-scripting-tricks-scripting-the-web-part-1-get-web.aspx" mce_href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/01/microcode-powershell-scripting-tricks-scripting-the-web-part-1-get-web.aspx"&gt;Get-Web&lt;/A&gt;, which allows you to use System.Net.Webclient to download web sites in a variety of ways.&amp;nbsp; The next post was learning to walk.&amp;nbsp; I showed us &lt;A href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/08/microcode-powershell-scripting-tricks-scripting-the-web-part-2-get-markuptag.aspx" mce_href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/08/microcode-powershell-scripting-tricks-scripting-the-web-part-2-get-markuptag.aspx"&gt;Get-MarkupTag&lt;/A&gt;, which helps coerce parts of the web into XML.&amp;nbsp; Now we can start to really have some fun with the data and run wild.&lt;/P&gt;
&lt;P&gt;Pulling out semi-structured data is one thing, but it’s important to be able to pull out more complex information as well.&amp;nbsp; One interesting case is pulling out all of the links from a webpage.&amp;nbsp;&amp;nbsp; This task breaks down into four smaller tasks:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Downloading the page (done with Get-Web) 
&lt;LI&gt;Getting the &amp;lt;a&amp;gt; tags in a meaningful way (done with &lt;A href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/08/microcode-powershell-scripting-tricks-scripting-the-web-part-2-get-markuptag.aspx" mce_href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/08/microcode-powershell-scripting-tricks-scripting-the-web-part-2-get-markuptag.aspx"&gt;Get-MarkupTag&lt;/A&gt;) 
&lt;LI&gt;Extracting out the href attribute 
&lt;LI&gt;Determining if the link is relative or absolute &lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;To determine if the link is relative or absolute, I made a Resolve-Link function.&amp;nbsp; It takes a base url (e.g &lt;A href="http://www.foo.com/blah/blah.asp" mce_href="http://www.foo.com/blah/blah.asp"&gt;http://www.foo.com/blah/blah.asp&lt;/A&gt;) and a link found on it, and returns the real item it resolves to.&amp;nbsp; It optionally returns a property bag with the type of link and the resolved link.&lt;/P&gt;
&lt;P&gt;Here’s Resolve-Link:&lt;/P&gt;&lt;I&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE class=CmdletDefinition&gt;function Resolve-Link([Uri]$uri,
    [string]$link,
    [switch]$returnLinkType) {
    #.Synopsis
    #   Resolves a relative or absolute link to an absolute url
    #.Description
    #   Takes a uri and a link to a page and returns the absolute url, or
    #   optionally returns a property bag with the link type
    #   (absolute, relative, or host relative) and the link
    #.Parameter uri
    #   The uri the link is located on
    #.Parameter link
    #   The original link text
    #.Parameter returnLinkType
    #   The return link type
    #.Example
    #   Resolve-Link http:/www.microsoft.com/ /technet/scriptcenter
    if ($link.StartsWith("/")) {
        # Relative to Host site
        if ($returnLinkType) {
            return New-Object Object |
                Add-Member NoteProperty Type "Host Relative" -PassThru |
                Add-Member NoteProperty Link ([uri]"$($uri.Scheme)://$($uri.DnsSafehost)$($link)") -PassThru
        }
        return "$($uri.Scheme)://$($uri.DnsSafehost)$($link)"
    } else {
        if ($link.StartsWith("$($uri.Scheme)://")) {
            # Absolute Link
            if ($returnLinkType) {
                return New-Object Object |
                    Add-Member NoteProperty Type "Absolute" -PassThru |
                    Add-Member NoteProperty Link ([uri]$link) -PassThru
            }            
            return $link
        } else {
            # Relative link
            $realLink = $uri.AbsoluteUri.Substring(0,
                $uri.AbsoluteUri.LastIndexOf("/")) + "/$link"    
            if ($returnLinkType) {
                return New-Object Object |
                    Add-Member NoteProperty Type "Relative" -PassThru |
                    Add-Member NoteProperty Link ([uri]$realLink) -PassThru
            }
            return $realLink            
        }
    }    
}&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/I&gt;
&lt;P&gt;Once Resolve-Link was written, making Get-WebPageLink is an incredible snap.&amp;nbsp; It’s below, and it actually takes only 3 lines to do the real work and&amp;nbsp; 11 lines to explain the work and give examples.&lt;/P&gt;&lt;I&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE class=CmdletDefinition&gt;function Get-WebPageLink($url) {
    #.Synopsis
    #   Returns all of the links within a webpage
    #.Description
    #   Resolves all &amp;lt;A&amp;gt; references and returns a property bag with
    #   the text contained in the link, the page the link came from,
    #   and the type of link returned (absolute, host relative, or relative)
    #.Parameter urltp
    #   The page to get links from
    #.Example
    #   Get-WebPageLink http://blogs.msdn.com/
    Get-MarkupTag a (Get-Web $url) | Foreach-Object {
        Resolve-Link $url $_.Xml.Href -returnLinkType |
            Add-Member NoteProperty Text $_.Xml."#text" -PassThru 
    }
}&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/I&gt;
&lt;P&gt;Go ahead and give Get-WebpageLink a whirl: &lt;/P&gt;&lt;I&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE&gt;Get-WebpageLink http://blogs.msdn.com&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/I&gt;
&lt;P&gt;Ready for some real fun? Remember way back when I did a post about getting RSS feeds in PowerShell with Microsoft.FeedsManager (&lt;A href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/11/microcode-scripting-rss-feeds-with-powershell-and-microsoft-feedsmanager.aspx" mce_href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/11/microcode-scripting-rss-feeds-with-powershell-and-microsoft-feedsmanager.aspx"&gt;Get-Feed&lt;/A&gt;).&amp;nbsp; If you have that script handy, go ahead and check out this one liner that will refresh every RSS item you’ve got and extract out all of the links from it.&lt;/P&gt;&lt;I&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE&gt;    
Get-Feed -recurse -articles | Foreach-Object { Get-WebPageLink $_.Link }&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/I&gt;
&lt;P&gt;That particular command line can take a while, depending on how many blogs you subscribe to, but it gives you a brand new view on blogs (as a simmering stew of scripts, rather than just text to be read and comprehended).&lt;/P&gt;
&lt;P&gt;There’s more fun to come in unlocking the web, but these two scripts should get you started in extracting a little more into the wild world of the web.&lt;/P&gt;
&lt;P&gt;Hope this Helps,&lt;/P&gt;
&lt;P&gt;James Brundage [MSFT]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9201602" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="PowerShell" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx" /><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="Scripting Tricks" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+Tricks/default.aspx" /><category term="Get-Feed" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Feed/default.aspx" /><category term="Get-Web" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Web/default.aspx" /><category term="Get-MarkupTag" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-MarkupTag/default.aspx" /><category term="Get-WebPageLink" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-WebPageLink/default.aspx" /><category term="Resolve-Link" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Resolve-Link/default.aspx" /><category term="Scripting The Web" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+The+Web/default.aspx" /></entry><entry><title>Microcode: PowerShell Scripting Tricks: Scripting The Web (Part 2) (Get-MarkupTag)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/08/microcode-powershell-scripting-tricks-scripting-the-web-part-2-get-markuptag.aspx" /><link rel="enclosure" type="application/octet-stream" length="11118" href="http://blogs.msdn.com/mediaandmicrocode/attachment/9183927.ashx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/08/microcode-powershell-scripting-tricks-scripting-the-web-part-2-get-markuptag.aspx</id><published>2008-12-08T11:17:00Z</published><updated>2008-12-08T11:17:00Z</updated><content type="html">&lt;P&gt;The first post about scripting the was a lot of waxing philosophical but little about how to extract data and give it form.&amp;nbsp; There are several approaches, with various difficulties.&amp;nbsp; I could build a full HTML parser and walk though object models, or I could use the object model of IE.&amp;nbsp; Since I personally like to minimize dependencies, I’ve chosen to use &lt;A href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/01/microcode-powershell-scripting-tricks-scripting-the-web-part-1-get-web.aspx" mce_href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/01/microcode-powershell-scripting-tricks-scripting-the-web-part-1-get-web.aspx"&gt;System.Net.Webclient&lt;/A&gt; to download the webpage as text rather than use Internet Explorer and get it through a proper object model. This means I will either have to write an HTML parser, or I’ll have to nudge HTML into something more useful to avoid writing a full parser.&lt;/P&gt;
&lt;P&gt;HTML is preciously close to XML, and XML is something that PowerShell supports quite well, so e IE sI decided to try to nudge HTML into XML.&amp;nbsp; I wrote a function, Get-MarkupTag, which will extract out the text for a markup tag (e.g. &amp;lt;a&amp;gt;) and attempt to coerce it into XML.&lt;/P&gt;
&lt;P&gt;It’s not a perfect approach, because there several things that are legal in HTML but not in XML.&amp;nbsp; Here’s an inventory of every curveball I’ve hit so far.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Unclosed tags like &amp;lt;IMG&amp;gt;: &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Some tags in HTML, like &amp;lt;IMG&amp;gt; are unmatched.&amp;nbsp; I’ll first have to identify all of the unmatched tags and coerce them into property closed xml (e.g. ensure that &amp;lt;IMG is &amp;lt;IMG /&amp;gt;).&amp;nbsp; For things like &amp;lt;BR&amp;gt; or &amp;lt;HR&amp;gt; this is easy, because attributes are rare, but for IMG, getting this right is critically important, because it’s how you download images.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;HTML Escape Sequences end up as XML unrecognized entities:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There’s a lot of ways to embed special characters within HTML that get recognized by the parser as XML entities.&amp;nbsp; The most common example is &amp;amp;nbsp; (the explicit space), but foreign currencies often show up in this format as well.&amp;nbsp; I found a complete list online that I could extract out all of the sequences from, and I embedded a hashtable within to hold each item.&amp;nbsp; Then I walked through the hashtable and replaced the escape sequences with their real value.&amp;nbsp; However, since the entity is legal in any since the entity is legal in any case (e.g. &amp;amp;nsbp; is the same as &amp;amp;NBSP; to an HTML parser), I had to write a quick case insensitive replace.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Unquoted Attributes&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;Most browsers will accept HTML attributes without quotes, e.g. &amp;lt;a href=www.microsoft.com&amp;gt;, but XML can handle this.&amp;nbsp; Once I’ve got figured out the text in each tag, I need to check each attribute within that tag to ensure that the attributes are quoted.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Nested tags&lt;/STRONG&gt;:&lt;/P&gt;
&lt;P&gt;One of the more interesting parts of parsing HTML was nested tags.&amp;nbsp; In order to match nested tags, what I did was use two regular expressions to identify all of the matches.&amp;nbsp; While PowerShell has a –match operator, –match doesn’t work for multiline strings.&amp;nbsp; So what I did was use New-Object to create the Regular Expression for extracting out a tag and then stored the result in a variable.&lt;/P&gt;
&lt;P&gt;If the number of start tags was equal to the number of end tags, I assumed that the tags are balanced.&amp;nbsp; If they’re odd, I’ll only deal with the start tags instead.&amp;nbsp; If I need to determine which start tag matches which end tag, I need to use a data structure called a stack.&amp;nbsp; Luckily, .NET comes with one (&lt;A href="http://msdn.microsoft.com/en-us/library/system.collections.stack.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.collections.stack.aspx"&gt;System.Collections.Stack&lt;/A&gt;).&amp;nbsp; A stack in code is just like a stack in real life.&amp;nbsp; You can put something on the top of the stack (Push), see what’s on top of the stack (Peek), and pull off the top of of the stack (Pop).&lt;/P&gt;
&lt;P&gt;If I put start tags and end tags in one list, and sort them by the order that they occurred (in PowerShell, this is $list1 + $list2 | Sort-Object PropertyName), then I can simply walk through the list, pushing the start tags onto the stack and popping off end tags as I encounter them.&lt;/P&gt;
&lt;P&gt;I don’t believe that I’ve taken care of all of the possible pains that exist (for instance, I know that georgraphic coordinates on wikipedia do not coerce into XML at this point.&amp;nbsp; However, it’s a good start and it can yield some quite interesting results.&lt;/P&gt;
&lt;P&gt;Since Get-MarkupTag involves a lot of escape sequences, which lends to very annoying blog formatting, I’m going to attach the script instead of embedding it.&amp;nbsp; &lt;A title=Get-MarkupTag href="http://blogs.msdn.com/mediaandmicrocode/attachment/9183927.ashx" mce_href="http://blogs.msdn.com/mediaandmicrocode/attachment/9183927.ashx"&gt;You can download it here&lt;/A&gt;.&lt;I&gt;&amp;nbsp;&lt;/I&gt;&lt;/P&gt;
&lt;P&gt;If you look at the code in Get-MarkupTag, close to the end, you’ll see a trap statement. This means that there’s any error coercing the chunk of HTML into XML will be swallowed into the verbose log.&amp;nbsp; If you want to examine why you can’t use the XML, simply set $verbosePreference to “continue” and you will be able to see the errors produced trying to convert the tag into XML.&amp;nbsp; This is an example of a technique I call error redirection.&lt;/P&gt;
&lt;P&gt;One of the kind of cool things you can do with it is extract the individual rows from ConvertTo-HTML:&lt;/P&gt;&lt;I&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE&gt;    $text = Get-ChildItem | Select Name, LastWriteTime | ConvertTo-HTML | Out-String 
    Get-MarkupTag "tr" $text
        &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/I&gt;
&lt;P&gt;It's also possible to extract out all of the pages &lt;A href="http://www.microsoft.com/" mce_href="http://www.microsoft.com"&gt;www.microsoft.com&lt;/A&gt; links to:&lt;/P&gt;&lt;I&gt;
&lt;BLOCKQUOTE&gt;&lt;PRE&gt;    $microsoft= (New-Object Net.Webclient).DownloadString("http://www.microsoft.com/")
    Get-MarkupTag "a" $microsoft | % { $_.Xml.Href }        &lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;/I&gt;
&lt;P&gt;What this fairly slightly quick and dirty approach to extracting out HTML gives you is a fairly simply way to start giving the data form. With XML you get the syntactic sugar PowerShell pours on XML, and you also get the power of XPath, and from that, you can start turning the HTML into something more interesting.&lt;/P&gt;
&lt;P&gt;In the next post, I’ll look at some of the things you can do with this new toy.&lt;/P&gt;
&lt;P&gt;Try it out on a few sites.&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;James Brundage [MSFT]&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9183927" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="PowerShell" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx" /><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="Get-MarkupTag" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-MarkupTag/default.aspx" /><category term="Scripting The Web" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+The+Web/default.aspx" /></entry><entry><title>Microcode: PowerShell Scripting Tricks: Scripting The Web (Part 1) (Get-Web)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/01/microcode-powershell-scripting-tricks-scripting-the-web-part-1-get-web.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/12/01/microcode-powershell-scripting-tricks-scripting-the-web-part-1-get-web.aspx</id><published>2008-12-01T06:13:06Z</published><updated>2008-12-01T06:13:06Z</updated><content type="html">&lt;p&gt;Several of the last posts have tackled how to take the wild world of data and start to turn it into PowerShell objects, so that it’s easier to make heads or tails out of it.&amp;#160; Once all of that data is in a form that PowerShell can use more effectively in the object pipeline, you can use PowerShell to slice and dice that data in wonderfully effective ways.&lt;/p&gt;  &lt;p&gt;Data mining is a strange art that I find scripting languages normally are a little better at than compiled languages. I find that PowerShell can be incredibly useful for data miners for two important reasons.&amp;#160; First, it can pull upon an unprecedented array of technologies (COM, WMI, .NET, SQL, Regular Expressions, Web Service, Command Line) in order to get structured data.&amp;#160; Second, and more importantly, since you can easily create objects on the fly in PowerShell, and since PowerShell has wonderful string processing, you can often use PowerShell to extract structure data out of unstructured data.&lt;/p&gt;  &lt;p&gt;Being able to pull data out of the mist and give it form is a very valuable skill, because people do not think in structured data.&amp;#160; While it might be useful to the computing world to have most information in structured data, most people disseminating information don’t think or record their thoughts with rigorous structure.&amp;#160; However, many people do record their thoughts in semi-rigorous structure, like the sentences and paragraphs you’re reading now.&lt;/p&gt;  &lt;p&gt;The fact of the matter is that tons of data floats on the web requiring a very little bit of work and a small amount of art to extract it.&amp;#160; This is because the web that people record their thoughts in is largely in HTML, and so, it is possible to learn a few ways to pull the data from the little structure that exists.&lt;/p&gt;  &lt;p&gt;The first piece of the toolkit to extract out data from the Web is a function I’ve called Get-Web.&amp;#160; Get-Web will simply download web pages, and it wraps part of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.webclient.aspx"&gt;System.Net.Webclient&lt;/a&gt; object.&lt;/p&gt;  &lt;p&gt;Using WebClient has pros and cons.&amp;#160; The biggest pro is that it relies on .NET, rather than on a particular browser, which means that you can use it without IE.&amp;#160; The biggest con is that a lot of web pages do checks on the browser in order to change how they display.&lt;/p&gt;  &lt;p&gt;Get-Web is below.&amp;#160; As with &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/30/microcode-powershell-scripting-tricks-more-joy-of-hashtables-with-get-hashtableasobject.aspx"&gt;Get-HashtableAsObject&lt;/a&gt;, I’m using comments to declare some nifty inline help.&lt;/p&gt;  &lt;pre&gt;function Get-Web($url, 
    [switch]$self,
    $credential, 
    $toFile,
    [switch]$bytes)
{
    #.Synopsis
    #    Downloads a file from the web
    #.Description
    #    Uses System.Net.Webclient (not the browser) to download data
    #    from the web.
    #.Parameter self
    #    Uses the default credentials when downloading that page (for downloading intranet pages)
    #.Parameter credential
    #    The credentials to use to download the web data
    #.Parameter url
    #    The page to download (e.g. www.msn.com)    
    #.Parameter toFile
    #    The file to save the web data to
    #.Parameter bytes
    #    Download the data as bytes   
    #.Example
    #    # Downloads www.live.com and outputs it as a string
    #    Get-Web http://www.live.com/
    #.Example
    #    # Downloads www.live.com and saves it to a file
    #    Get-Web http://wwww.msn.com/ -toFile www.msn.com.html
    $webclient = New-Object Net.Webclient
    if ($credential) {
        $webClient.Credential = $credential
    }
    if ($self) {
        $webClient.UseDefaultCredentials = $true
    }
    if ($toFile) {
        if (-not &amp;quot;$toFile&amp;quot;.Contains(&amp;quot;:&amp;quot;)) {
            $toFile = Join-Path $pwd $toFile
        }
        $webClient.DownloadFile($url, $toFile)
    } else {
        if ($bytes) {
            $webClient.DownloadData($url)
        } else {
            $webClient.DownloadString($url)
        }
    }
}&lt;/pre&gt;

&lt;p&gt;To walk through a few examples of Get-Web, simply point it to any webpage. &lt;/p&gt;

&lt;pre&gt;	Get-Web http://en.wikipedia.org/&lt;/pre&gt;

&lt;p&gt;To save a page to disk &lt;/p&gt;

&lt;pre&gt;	Get-Web http://www.msn.com/ -toFile www.msn.com.html&lt;/pre&gt;

&lt;p&gt;Just downloading the data is only the first step.&amp;#160; All being able to download web data gives you is a way to get the mist into a bottle, but it doesn’t help you give it form.&amp;#160; The next piece will cover how to pull the data out of the web and into PowerShell.&lt;/p&gt;

&lt;p&gt;Hope this helps,&lt;/p&gt;

&lt;p&gt;James Brundage [MSFT] &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9159333" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="PowerShell" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx" /><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="Get-Web" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Web/default.aspx" /><category term="System.Net.Webclient" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/System.Net.Webclient/default.aspx" /><category term="Scripting The Web" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+The+Web/default.aspx" /></entry><entry><title>Microcode: PowerShell Scripting Tricks: More Joy of Hashtables (with Get-HashtableAsObject)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/30/microcode-powershell-scripting-tricks-more-joy-of-hashtables-with-get-hashtableasobject.aspx" /><id>http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/30/microcode-powershell-scripting-tricks-more-joy-of-hashtables-with-get-hashtableasobject.aspx</id><published>2008-11-30T05:10:27Z</published><updated>2008-11-30T05:10:27Z</updated><content type="html">&lt;p&gt;I recently did two different &amp;quot;in depth&amp;quot; posts.&amp;#160; One on &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/27/microcode-powershell-scripting-tricks-the-joy-of-using-hashtables-with-windows-powershell.aspx"&gt;The Joy Of Hashtables&lt;/a&gt; and another on &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/26/microcode-powershell-scripting-tricks-select-object-note-properties-vs-add-member-script-properties.aspx"&gt;Select-Object versus Add-Member&lt;/a&gt;.&amp;#160; At the end of Select-Object vs Add-Member, I hinted at more convenient ways to write objects that used Script Properties.&amp;#160; Script Properties are particularly useful because, unlike Note Properties, they are evaluated when they are requested.&amp;#160; This means that PowerShell scripts that use script properties will often be faster than those using note properties.&amp;#160; Sadly, they're kind of clunky to add.&amp;#160; A script property will normally look like:&lt;/p&gt; &lt;i&gt;   &lt;blockquote&gt;     &lt;pre&gt;New-Object Object | Add-Member ScriptProperty Foo { Get-Random } -passThru&lt;/pre&gt;
  &lt;/blockquote&gt;
&lt;/i&gt;

&lt;p&gt;This gets pretty ugly, pretty fast.&lt;/p&gt;

&lt;p&gt;Luckily, the post on hashtables gives us a good way out of this problem.&amp;#160; Hashtables look fairly clean in PowerShell scripts, and, with a little bit of work, you can easily turn a hashtable into an object. Here's the Get-HashtableAsObject function.&lt;/p&gt;

&lt;p&gt;In case you're curious, the comments inside of the function aren't just there for fun. They're an example of script-embedded help (which will not be out until CTP3). Once script-embedded Help is there, you can write help content for a function with just what's in the function below, and you'll be able to Get-Help on your function just like any other command.&lt;/p&gt;
&lt;i&gt;
  &lt;blockquote&gt;
    &lt;pre&gt;function Get-HashtableAsObject([Hashtable]$hashtable)
{  
    #.Synopsis
    #    Turns a Hashtable into a PowerShell object
    #.Description
    #    Creates a new object from a hashtable.
    #.Example
    #    # Creates a new object with a property foo and the value bar
    #    Get-HashtableAsObject @{&amp;quot;Foo&amp;quot;=&amp;quot;Bar&amp;quot;}
    #.Example
    #    # Creates a new object with a property Random and a value
    #    # that is generated each time the property is retreived
    #    Get-HashtableAsObject @{&amp;quot;Random&amp;quot; = { Get-Random }}
    #.Example
    #    # Creates a new object from a hashtable with nested hashtables
    #    Get-HashtableAsObject @{&amp;quot;Foo&amp;quot; = @{&amp;quot;Random&amp;quot; = {Get-Random}}} 
    process {       
        $outputObject = New-Object Object
        if ($hashtable -and $hashtable.Count) {
            $hashtable.GetEnumerator() | Foreach-Object {
                if ($_.Value -is [ScriptBlock]) {
                    $outputObject = $outputObject | 
                        Add-Member ScriptProperty $_.Key $_.Value -passThru
                } else {
                    if ($_.Value -is [Hashtable]) {
                        $outputObject = $outputObject | 
                            Add-Member NoteProperty $_.Key (Get-HashtableAsObject $_.Value) -passThru
                    } else {                    
                        $outputObject = $outputObject | 
                            Add-Member NoteProperty $_.Key $_.Value -passThru
                    }
                }                
            }
        }
        $outputObject
    }
}&lt;/pre&gt;
  &lt;/blockquote&gt;
&lt;/i&gt;

&lt;p&gt;Let's check out a few practical examples of Get-HashtableAsObject:&lt;/p&gt;

&lt;p&gt;Check out how we can use Get-HashtableAsObject to create a random card&lt;/p&gt;
&lt;i&gt;
  &lt;blockquote&gt;
    &lt;pre&gt;$card = Get-HashtableAsObject @{
    Card = {2..9 + &amp;quot;Jack&amp;quot;, &amp;quot;Queen&amp;quot;, &amp;quot;King&amp;quot;, &amp;quot;Ace&amp;quot; | Get-Random}
    Suit = {&amp;quot;Clubs&amp;quot;, &amp;quot;Hearts&amp;quot;, &amp;quot;Diamonds&amp;quot;, &amp;quot;Spades&amp;quot; | Get-Random}
}
$card
$card
$card&lt;/pre&gt;
  &lt;/blockquote&gt;
&lt;/i&gt;

&lt;p&gt;Notice that each time I output $card, the Card and Suit change. This is because the script property is being evaluated each time it is read. Essentially, it's shuffling every card. Cool, right?&lt;/p&gt;

&lt;p&gt;The last post introduced you to PowerShell's ability to add hashtables together to merge them.&amp;#160; Check out how we can use this to combine an object that generates user information and an object that generates system information.&lt;/p&gt;
&lt;i&gt;
  &lt;blockquote&gt;
    &lt;pre&gt;$userInfo = @{
    LocalUsers = {Get-WmiObject &amp;quot;Win32_UserAccount WHERE LocalAccount='True'&amp;quot;}
    LoggedOnUsers = {Get-WmiObject &amp;quot;Win32_LoggedOnUser&amp;quot; }    
}

$systemInfo = @{
    Memory = {Get-WmiObject Win32_PhysicalMemory}
    Drives = {Get-WmiObject Win32_LogicalDisk}
}

$liveUserInfo = Get-HashtableAsObject $userInfo
$liveSystemInfo = Get-HashtableAsObject $systemInfo
$allInfo = Get-HashtableAsObject ($userInfo + $systemInfo)

$liveUserInfo.LocalUsers
$allInfo.Drives&lt;/pre&gt;
  &lt;/blockquote&gt;
&lt;/i&gt;

&lt;p&gt;This trick is particularly convenient for quickly joining together chunks of logic from different scripts. For instance, if I wanted to add a property the $userInfo object that kicked off all users who had been logged on for over a period of time, I'd simply add another hashtable to the user info to accomplish this task. For those much more in tune with object-oriented programming, what this essentially gives me is the ability to inherit from an objects defined this way in PowerShell, without the joy of overloading.&amp;#160; Faking overloading is considerably more complicated, so we'll save that one for another day, but I hope that the tricks contained within this post help you write more robust scripts.&lt;/p&gt;

&lt;p&gt;Hope this helps,&lt;/p&gt;

&lt;p&gt;James Brundage [MSFT]&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9156852" width="1" height="1"&gt;</content><author><name>JamesBrundage</name><uri>http://blogs.msdn.com/members/JamesBrundage.aspx</uri></author><category term="PowerShell" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx" /><category term="Microcode" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx" /><category term="Add-Member" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Add-Member/default.aspx" /><category term="System.Collections.Hashtable" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/System.Collections.Hashtable/default.aspx" /><category term="Get-HashtableAsObject" scheme="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-HashtableAsObject/default.aspx" /></entry></feed>