<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Media And Microcode : Select-Object</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx</link><description>Tags: Select-Object</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Microcode: A Quick Trick to turn regular XML into Xaml</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2009/01/22/microcode-a-quick-trick-to-turn-regular-xml-into-xaml.aspx</link><pubDate>Thu, 22 Jan 2009 13:07:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9365908</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/9365908.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=9365908</wfw:commentRss><description>&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;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx">Microcode</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx">Select-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/WPF/default.aspx">WPF</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Xml/default.aspx">Select-Xml</category></item><item><title>Microcode: PowerShell Scripting Tricks: Select-Object (Note Properties) vs Add-Member (Script Properties)</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/26/microcode-powershell-scripting-tricks-select-object-note-properties-vs-add-member-script-properties.aspx</link><pubDate>Wed, 26 Nov 2008 07:30:20 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9143255</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/9143255.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=9143255</wfw:commentRss><description>&lt;p&gt;As I've said a number of times before, PowerShell's quantum leap forward is something called the Object Pipeline.&amp;#160; It allows you to take the results of one command and easily use them with the next, which means that each command you create becomes a link in a chain rather than an isolated island.&lt;/p&gt;  &lt;p&gt;In several posts, I've talked about how to create objects that are property bags as a means to an end (such as when I was &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/07/21/microcode-cleaning-up-get-recordedtv-with-select-object.aspx"&gt;Cleaning Up Get-RecordedTV with Select-Object&lt;/a&gt;), but I haven't really focused on how to make property bags that much on its own.&lt;/p&gt;  &lt;p&gt;There are two basic ways you can create property bags in PowerShell.&amp;#160; The first is by using the Add-Member cmdlet, and the second is by using Select-Object.&amp;#160; As with anything in programming, deciding which way to get a task done involves some trade offs.&amp;#160; Most of the trade off between Select-Object and Add-Member has to do with what type of properties the commands add to objects.&amp;#160; Select-Object will add note properties, which are fine for most purposes and quick to create, but they cannot do anything when the properties are set and cannot create properties that are always up to date.&lt;/p&gt;  &lt;p&gt;The following table shows when I tend to use Select-Object versus Add-Member&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="400" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;&lt;strong&gt;When your priority is...&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="200"&gt;&lt;strong&gt;You should use...&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Adding a few quick properties to an existing object &lt;/td&gt;        &lt;td valign="top" width="200"&gt;Select-Object&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Adding properties that may be take time to evaluate or need to be up-to-date&lt;/td&gt;        &lt;td valign="top" width="200"&gt;Add-Member&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Creating a property bag to summarize information from cmdlets &lt;/td&gt;        &lt;td valign="top" width="200"&gt;Select-Object&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Wrapping an existing object with a friendlier surface area &lt;/td&gt;        &lt;td valign="top" width="200"&gt;Add-Member&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;Adding a single property to an object&lt;/td&gt;        &lt;td valign="top" width="200"&gt;Add-Member&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;  &lt;p&gt;The bottom line of choosing which way to make your property bag comes down to speed and convenience.&amp;#160; Because you have to call Add-Member once for every property you wish to add to an object, Add-Member is often slower to use for this purpose than Select-Object.&amp;#160; However, to be fair, Select-Object is kind of ugly and a little inconvenient to write. To prove the speed gain and illustrate the strange syntax of Select-Object, here's two equivalent scripts that both create an object with two properties, Foo and Bar:&lt;/p&gt;  &lt;table cellspacing="0" cellpadding="2" width="400" border="0"&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td valign="top" width="200"&gt;&lt;strong&gt;Select-Object&lt;/strong&gt;&lt;/td&gt;        &lt;td valign="top" width="200"&gt;&lt;strong&gt;Add-Member&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td valign="top" width="200"&gt;         &lt;pre&gt;    1 | Select-Object @{
        Name='Foo'
        Expression={&amp;quot;Bar&amp;quot;}
    }, @{
        Name='Bar'
        Expression={&amp;quot;Baz&amp;quot;}
    }&lt;/pre&gt;
      &lt;/td&gt;

      &lt;td valign="top" width="200"&gt;
        &lt;pre&gt;      New-Object Object |
          Add-Member NoteProperty Foo Bar -passThru | 
          Add-Member NoteProperty Bar Baz -passThru
      &lt;/pre&gt;
      &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;&lt;/table&gt;

&lt;p&gt;Obviously, Select-Object is a lot less clean looking than Add-Member.&amp;#160; To determine which is faster, just pack each item into a long loop and run Measure-Command.&lt;/p&gt;

&lt;pre&gt;Measure-Command {
    foreach ($n in (1..1000))  {
        1 | Select-Object @{
            Name='Foo'
            Expression={&amp;quot;Bar&amp;quot;}
        }, @{
            Name='Bar'
            Expression={&amp;quot;Baz&amp;quot;}
        }
    }
}

Measure-Command {
    foreach ($n in (1..1000))  {
        New-Object Object |
            Add-Member NoteProperty Foo Bar -passThru | 
            Add-Member NoteProperty Bar Baz -passThru
    }
}&lt;/pre&gt;

&lt;p&gt;On my computer, Select-Object is much faster. It's actually twice as fast over 1000 objects. The more properties you add with Add-Member, the slower it will be.&amp;#160; This concern should really only come into play when dealing with thousands of objects, so if you were adding properties to the output of Get-Process, the difference should be negligible, but if you're adding properties to every single file underneath Windows\System32, you'll probably want to use Select-Object.&lt;/p&gt;

&lt;p&gt;Add-Member does have one huge advantage over Select-Object, and that's the type of properties that it can tack on.&amp;#160; Select-Object adds Note Properties, which means that it will evaluate each item as you add it to the object (and never again).&amp;#160; For instance, if I wanted to add a property to a file object that would tell me who currently had the file open, then I would need that property to always be up to date.&amp;#160; In this case, if you had a command that would determine if the file was open (let's call it Test-FileOpen) you could add something like Add-Member ScriptProperty IsOpened { Test-FileOpen $this.Fullname }.&lt;/p&gt;

&lt;p&gt;The other thing you can do with a script property that you can't do with a note property is set values.&amp;#160; To do this with a ScriptPropery, you simply give Add-Member two script blocks.&amp;#160; The first is a getter and the second is a setter. In the simple example below, I update the value of Bar through the setter of Foo&lt;/p&gt;

&lt;pre&gt;$i = New-Object Object |
    Add-Member NoteProperty Bar &amp;quot;baz&amp;quot; -passThru |     
    Add-Member ScriptProperty Foo {$this.Bar} { $this.Bar = $args[0]} -passThru 
$i
$i.Foo = &amp;quot;bing&amp;quot;
$i&lt;/pre&gt;

&lt;p&gt;ScriptProperties are especially useful if you would like to take a surface area that's awkward and make it nicer to use in PowerShell.&amp;#160; In this case, you simply create a new object, attach the original object to it as a note property, and then use Script Properties to talk to the original object.&amp;#160; Sadly, in order to demonstrate the usefulness of that particular capability, I have to walk through a long and complicated API.&amp;#160;&amp;#160; Rather than make this post more long and complicated, I'll leave this post as food for thought on where you can use note properties and script properties in your code.&lt;/p&gt;

&lt;p&gt;Have fun experimenting, and remember: Select-Object's Speedy, Add-Member's Adaptable.&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=9143255" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx">Microcode</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx">Select-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+Tricks/default.aspx">Scripting Tricks</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Measure-Command/default.aspx">Measure-Command</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Add-Member/default.aspx">Add-Member</category></item><item><title>Microcode: Scripting RSS Feeds with PowerShell and Microsoft.FeedsManager</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/11/microcode-scripting-rss-feeds-with-powershell-and-microsoft-feedsmanager.aspx</link><pubDate>Tue, 11 Nov 2008 04:34:53 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9059055</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/9059055.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=9059055</wfw:commentRss><description>&lt;p&gt;PowerShell's an amazing glue language.&amp;#160;&amp;#160; It can help you bring code from all corners of the earth into one environment, and then you can custom the code to be more to your liking.&amp;#160; While the last several entries of my blog have spent time looking at what we can glue together with .NET, this one shows you how you can bring COM into the mix.&lt;/p&gt;  &lt;p&gt;Internet Explorer has an RSS feed manager which you can script in .NET.&amp;#160; While the command line might not be the ideal spot to read your blogs, it's possible to make a much nicer front end by scripting WPF &amp;amp; PowerShell, and having a quick and easy API to get at your RSS feeds makes building applications that use RSS feeds as a way to synchronize information between multiple machines.&lt;/p&gt;  &lt;p&gt;The object that makes this all work is &lt;a href="http://msdn.microsoft.com/en-us/library/ms684749.aspx"&gt;Microsoft.FeedsManager&lt;/a&gt;, and the cmdlet that makes working with it possible is &lt;a href="http://technet.microsoft.com/en-us/library/bb978545.aspx"&gt;New-Object&lt;/a&gt;.&amp;#160; By default, New-Object will create a new .NET object from the classes that are currently loaded by .NET (for more on this, see my previous posts about &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/10/23/microcode-powershell-scripting-tricks-exploring-net-types-with-a-get-type-function-and-reflection.aspx"&gt;Get-Type&lt;/a&gt; and &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/11/08/microcode-exploring-more-of-net-with-get-assembly.aspx"&gt;Get-Assembly&lt;/a&gt;).&amp;#160; While .NET is a fairly easy world to explore, COM is considerably more tricky.&lt;/p&gt;  &lt;p&gt;Luckily, COM objects are the main backbone of VBScript.&amp;#160; This is an important point for VBScripters trying to learn PowerShell: while the world of .NET may be new and exotic, and Cmdlets might be cool, you don't have to drop your VBScript knowledge at the door.&amp;#160; While some of a VBScript (e.g. strings) will require new learning in PowerShell, the vast majority of it doesn't.&lt;/p&gt;  &lt;p&gt;Microsoft.FeedsManager is one of these examples.&amp;#160; I found out about this object by looking at the source code for the RSS reader vista sidebar gadget, and, once I knew its name, I knew how to get at it in PowerShell.&amp;#160; Even though I was looking at javascript, I knew that there was a scriptable COM object there to help me out, and I knew how to bring it into PowerShell. &lt;/p&gt;  &lt;p&gt;To create a Microsoft.FeedsMananger, simply use this one liner:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;New-Object -comObject Microsoft.FeedsManager&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Since the root folder looks promising, let's explore that:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;(New-Object -comObject Microsoft.FeedsManager).RootFolder&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;While I can just save this into a variable and script it like I were still in VBScript land (e.g. $feeds = New-Object -comObject Microsoft.FeedsManager, $feeds.RootFolder), I far prefer the parlance of PowerShell, so I'll make a quick Get-Feed function to explore feeds more easily.&amp;#160; I'll accept a wildcard for the name or title of the feed, and, since the feeds can have an arbitrary number of subfolders, I'll add a -recurse parameter.&amp;#160; In order to make -recurse work elegantly, I'll use a short recursive script and I'll add a $folder parameter, which can be null and will be assumed to be the root folder.&amp;#160; Finally, since I'll often want to read the items more than the feed, I'll add a switch parameter to extract the articles.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;function Get-Feed($feed = &amp;quot;*&amp;quot;, $folder, [switch]$recurse, [switch]$articles) {&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if (! $folder) {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $feedsManager = New-Object -ComObject Microsoft.FeedsManager&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $folder = $feedsManager.RootFolder&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; $folder.Feeds |         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Where-Object {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; ($_.Title -like &amp;quot;$feed&amp;quot;) -or ($_.Name -like &amp;quot;$feed&amp;quot;)         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; } | Foreach-Object {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; if ($articles) { $_.Items } else { $_ }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; if ($recurse) {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $folder.Subfolders | Foreach-Object {         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get-Feed $feed $_ -recurse -articles:$articles         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }         &lt;br /&gt;}&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Once I've defined Get-Feed, I can use it to search my feeds through PowerShell.&amp;#160; This one liner will get my all my feeds, sort them by name, and display just the Name and URL:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Get-Feed -recurse | Sort-Object Name | Select-Object Name, URL &lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;To see all of the feed items sort them by when they were published, and display the post title, the blog title, and the publish date, you can use this pipeline:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;Get-Feed -articles -recurse |        &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Sort-Object PubDate -descending |         &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Select-Object Title, @{Name='Blog'; Expression={$_.Parent.Title }}, PubDate&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;I promise that we can do much more with RSS and PowerShell, but hopefully this post will get you started down the path of using the FeedsManager from PowerShell.&lt;/p&gt;  &lt;p&gt;Hope this helps,&lt;/p&gt;  &lt;p&gt;James Brundage [MSFT]&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;table border="1"&gt;&lt;theader&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;&lt;strong&gt;Module Name&lt;/strong&gt;&lt;/td&gt;        &lt;td&gt;&lt;strong&gt;Scripts&lt;/strong&gt;&lt;/td&gt;     &lt;/tr&gt; &lt;/theader&gt;&lt;/tbody&gt;&lt;tbody&gt;     &lt;tr&gt;       &lt;td&gt;&lt;a href="http://cid-2b8a402d0ba15e82.skydrive.live.com/browse.aspx/PowerShell%20Scripts/RSS"&gt;RSS&lt;/a&gt;&lt;/td&gt;        &lt;td&gt;&lt;a href="http://cid-2b8a402d0ba15e82.skydrive.live.com/self.aspx/PowerShell%20Scripts/RSS/Get-Feed.ps1"&gt;Get-Feed&lt;/a&gt;&lt;/td&gt;     &lt;/tr&gt;   &lt;/tbody&gt;&lt;/table&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9059055" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx">Microcode</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx">Select-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Sort-Object/default.aspx">Sort-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Feed/default.aspx">Get-Feed</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/New-Object/default.aspx">New-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microsoft.FeedsManager/default.aspx">Microsoft.FeedsManager</category></item><item><title>Microcode: PowerShell Scripting Tricks - Exploring .NET Types with a Get-Type function and Reflection</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2008/10/23/microcode-powershell-scripting-tricks-exploring-net-types-with-a-get-type-function-and-reflection.aspx</link><pubDate>Fri, 24 Oct 2008 01:16:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9014243</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/9014243.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=9014243</wfw:commentRss><description>&lt;p&gt;There's a simple yet powerful function that nearly everyone on the PowerShell team has written a version of.&amp;#160; My version is called Get-Type.&amp;#160; It's only a one-liner, but it's an amazing way to explore .NET and it's also an amazing example of some of the things you can do with the object pipeline.&amp;#160; What my version does is get all of the existing .NET types loaded in the current program.&amp;#160; In this post, I'll introduce the basic function, and I'll build upon it in order to show some cool things you can do with .NET reflection.&amp;#160; I first introduced this function in the &lt;a href="http://blogs.msdn.com/powershell/archive/2008/05/23/wpf-powershell-part-2-exploring-wpf-and-the-rest-of-net-with-scripts.aspx"&gt;2nd post of my series on WPF&lt;/a&gt;, but I didn't really show that much .NET fun with it.&lt;/p&gt;  &lt;p&gt;Here's a simple version:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;function Get-Type() {      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160; [AppDomain]::CurrentDomain.GetAssemblies() |&amp;#160; Foreach-Object { $_.GetTypes() }       &lt;br /&gt;}&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Go ahead and run it.&amp;#160; Running it on CTP2 of Graphical PowerShell on my home box, I got 19303 .NET types.&amp;#160; That's over 19000 things you can build upon.&amp;#160; 19000 potential solutions sitting right there at your fingertips.&amp;#160; A remarkable amount of information can be gleaned just looking directly at the types, and it's a lot faster than looking it up on MSDN (although MSDN is a great companion to this knowledge).&lt;/p&gt;  &lt;p&gt;How I figured out there were 19303 .NET types is a great example of the object pipeline:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Get-Type | Measure-Object&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;But that's only scratching the surface of what we can do with the rich data of .NET and PowerShell's powerful object pipeline.&lt;/p&gt;  &lt;p&gt;Let's suppose that I want to find every Xml-related type:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Get-Type | ? { $_.Name -like &amp;quot;*Xml*&amp;quot; } &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now suppose I want to find the constructors of the constructors of the objects:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Get-Type | ? { $_.Name -like &amp;quot;*Xml*&amp;quot; } | % { $_.GetConstructors() }&amp;#160; | %&amp;#160; { &amp;quot;$_&amp;quot; }&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Now suppose I want to check out what each constructor can do:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Get-Type | ? { $_.Name -like &amp;quot;*Xml*&amp;quot; } | % { $_.GetConstructors() } | Get-Member&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Looking at this, I can see that constructors contain a GetParameters() method.&amp;#160; Let's put that together with Get-Type to build something that will find all of the types that I can build using that type.&lt;/p&gt;  &lt;p&gt;function Search-Constructor([Type]$parameterType, $namespace) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get-Type |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Where-Object { $_.Namespace -like &amp;quot;*$namespace*&amp;quot; } |&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Where-Object {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $_.GetConstructors() |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Foreach-Object {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $_.GetParameters() |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Where-Object {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $_.ParameterType -eq $parameterType     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;} &lt;/p&gt;  &lt;p&gt;It will probably take a little bit to run (on my machine, it took about 30 seconds to find anything that used XmlDocument in its constructor, with no namespace specified) , but you can easily use this to start discovering how .NET types interact.&lt;/p&gt;  &lt;p&gt;Similar functions will let you find Properties, Events, and Methods:&lt;/p&gt;  &lt;p&gt;function Search-Method([Type]$parameterType, $namespace) {    &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Get-Type |&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Where-Object { $_.Namespace -like &amp;quot;*$namespace*&amp;quot; } |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Where-Object {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $_.GetMethods() |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Foreach-Object {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $_.GetParameters() |     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Where-Object {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; $_.ParameterType -eq $parameterType     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; }     &lt;br /&gt;}&lt;/p&gt;  &lt;p&gt;If you want to check out any property, just use Select-Object to view the type.&amp;#160; (You can also summarize the object by adding hashtables, for instance, this expression will output each type's fullname and all of their methods:&lt;/p&gt;  &lt;p&gt;Get-Type | Select-Object FullName, @{Name='Methods';Expression={$_.GetMethods() | % {$_.ToString()}}}&lt;/p&gt;  &lt;p&gt;This is a great example of the usefulness of the Object pipeline.&amp;#160; Instead of getting a list of all of the typenames, you can delve deep into the what a type can do for you.&amp;#160; The more you explore .NET.&amp;#160; These little snippets should help get you started, but the sky's the limit.&amp;#160; Try writing a few of your own. The more you explore .NET, the more you'll be amazed at the variety of code that exists to solve your everyday programming problems.&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=9014243" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx">Microcode</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx">Select-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Scripting+Tricks/default.aspx">Scripting Tricks</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Where-Object/default.aspx">Where-Object</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-Type/default.aspx">Get-Type</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Reflection/default.aspx">Reflection</category></item><item><title>Microcode: Cleaning up Get-RecordedTV with Select-Object</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2008/07/21/microcode-cleaning-up-get-recordedtv-with-select-object.aspx</link><pubDate>Mon, 21 Jul 2008 02:28:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8759683</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/8759683.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=8759683</wfw:commentRss><description>&lt;p&gt;In a previous post, I introduced &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/07/13/microcode-getting-dvr-metadata-with-search-windowsdesktop.aspx"&gt;Get-RecordedTV&lt;/a&gt;, which was built upon another function, &lt;a href="http://blogs.msdn.com/mediaandmicrocode/archive/2008/07/13/microcode-windows-powershell-windows-desktop-search-problem-solving.aspx"&gt;Search-WindowsDesktop&lt;/a&gt;.&lt;/p&gt;  &lt;p&gt;The old version of Get-RecordedTV directly returned the properties related to DVR from Windows Desktop Search, with incredibly long names like 'System.RecordedTV.IsRepeatBroadcast'.&amp;#160; In the interests of making future code shorter and explaining one of the free benefits you get with objects in PowerShell (Select-Object), I'm going to start by giving a new Get-RecordedTV.&amp;#160; Instead of giving you the properties directly from Desktop Search, this Get-RecordedTV reinterprets the results to make them easier to read.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;function Get-RecordedTV() {     &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Search-WindowsDesktop 'System.Title',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.EpisodeName',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.ChannelNumber',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.StationName',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.IsRepeatBroadcast',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.StationCallsign',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.ProgramDescription',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.IsSAP',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.IsHDContent',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.RecordedTV.RecordingTime',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.Video.FrameHeight',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.Video.FrameWidth',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.Video.EncodingBitrate',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.Media.DateEncoded',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.ParentalRating',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.Size',      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; 'System.ItemPathDisplay' &amp;quot;WHERE System.RecordedTV.ChannelNumber IS NOT NULL&amp;quot; |      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Select-Object @{Name='Series';Expression={$_.'System.Title'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='Episode';Expression={$_.'System.RecordedTV.EpisodeName'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='Description';Expression={$_.'System.RecordedTV.ProgramDescription'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='Channel';Expression={      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &amp;quot;$($_.'System.RecordedTV.ChannelNumber')-$($_.'System.RecordedTV.StationCallsign')-$($_.'System.RecordedTV.StationName')&amp;quot;      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='File';Expression={      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Get-Item $_.'System.ItemPathDisplay' -errorAction SilentlyContinue      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; }},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='Size';Expression={$_.'System.Size'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='DateRecorded';Expression={$_.'System.RecordedTV.RecordingTime'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='IsSAP';Expression={$_.'System.RecordedTV.IsSAP'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='IsHD';Expression={$_.'System.RecordedTV.IsHDContent'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='IsRepeatBroadcast';Expression={$_.'System.RecordedTV.IsRepeatBroadcast'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='Width';Expression={$_.'System.Video.FrameWidth'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='Height';Expression={$_.'System.Video.FrameHeight'}},      &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; @{Name='Rating';Expression={$_.'System.ParentalRating'}}      &lt;br /&gt;}&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This entire function is still one pipeline.&amp;#160; It gets the results from Search-WindowsDesktop, and, as each item arrives, it pipes the results to Select-Object.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://technet.microsoft.com/en-us/library/bb978655(TechNet.10).aspx"&gt;Select-Object&lt;/a&gt; is an incredibly useful PowerShell Cmdlet.&amp;#160; It is used to select one or more objects from a type, and return them in a bag of properties.&amp;#160; While it works great for selecting just a property or two (e.g. Get-Process | Select Name, ID), it can also be used in some interesting other ways.&lt;/p&gt;  &lt;p&gt;The way I use it above is to rename a number of properties.&amp;#160; If you have an parameter in Select-Object that takes the format @{Name='&lt;em&gt;String';Expression={expression}}, &lt;/em&gt;you will create a new property on the object with the value of the expression.&amp;#160; You can refer to something on the current object by using $_ (which, in PowerShell, is pretty commonly the current element in the pipeline).&amp;#160; You can also use this to run methods and return their values as properties.&amp;#160; And, finally, you can actually create a type that is only properties this way, by using a simple other PowerShell coolness, the range operator.&lt;/p&gt;  &lt;p&gt;So, to create one hundred anonymous objects with two random numbers:&lt;/p&gt;  &lt;p&gt;$random=New-Object Random   &lt;br /&gt;1..100 |    &lt;br /&gt;&amp;#160; Select-Object @{Name='Random1';Expression={$random.Next()}},    &lt;br /&gt;&amp;#160; @{Name='Random2';Expression={$random.Next()}}&lt;/p&gt;  &lt;p&gt;People familiar with functional programming might know this sort of thing as a &lt;a href="http://blogs.msdn.com/ericwhite/pages/Tuples-and-Anonymous-Types.aspx"&gt;Tuple&lt;/a&gt;, but knowing the correct terminology doesn't help the usefulness sink in all that much to me.&lt;/p&gt;  &lt;p&gt;In the case of Get-RecordedTV, the first use is pretty obvious: it reduces the amount of typing for each property name and makes it easier to identify.&amp;#160; The second advantage is more subtle.&amp;#160; By re-interpreting the return type from Search-WindowsDesktop to be a bunch of properties that the system decides to a bunch of properties that I choose, it means that I can make the dependency on Search-WindowsDesktop removable.&amp;#160; In doing so, I hurt anyone that has already built scripts around Get-RecordedTV, because they have to change their scripts to handle a new signature for the anonymous type, because the change subtracted types.&lt;/p&gt;  &lt;p&gt;Subtractive changes break backwards compatibility, but in this case it frees me from the stack that I used to depend on.&amp;#160; This is a wonderful flexibility of writing in an interpreted language, and can be valuable because you can use it to make a flexible dependency instead of a fixed one.&amp;#160; With a flexible dependency, if I find out that they have turned Windows Desktop Search off, or I find a better mechanism down the line, I can replace my dependency on Search-WindowsDesktop with another technology.&lt;/p&gt;  &lt;p&gt;I could write an interface to express the data I want to get, but that's overkill for my situation.&amp;#160; If I write an interface, then I have to have a real type already loaded, and I've swapped one dependency (on Search-WindowsDesktop) for two ( the type that implements the interface and the interface type ) and have essential hard-bolted a dependency on my interface to any application that wants to use the data.&lt;/p&gt;  &lt;p&gt;Anonymous types allow you to get most of the benefits of interfaces with a flexible dependency.&amp;#160; As long as you keep the bag of properties the same, you can build upon scripts that return anonymous properties.&amp;#160; You can use this to coerce data into forms that are easier to remember, and to summarize data in simpler forms.&amp;#160; You will also find that a number of cmdlets within PowerShell (Select-Object, Sort-Object, and Group-Object) work amazingly well with bags of properties.&lt;/p&gt;  &lt;p&gt;In a later posts, we'll use this base of code and these cmdlets to prune the collection, and demonstrate how the use of property bags and the exploration into Windows Desktop Search leads to a variety of wonderful side effects.&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=8759683" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Microcode/default.aspx">Microcode</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Get-RecordedTV/default.aspx">Get-RecordedTV</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Select-Object/default.aspx">Select-Object</category></item></channel></rss>