<?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 : TechNet</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/tags/TechNet/default.aspx</link><description>Tags: TechNet</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Microcode: Windows PowerShell, Windows Desktop Search &amp; Problem Solving</title><link>http://blogs.msdn.com/mediaandmicrocode/archive/2008/07/13/microcode-windows-powershell-windows-desktop-search-problem-solving.aspx</link><pubDate>Sun, 13 Jul 2008 23:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8729498</guid><dc:creator>JamesBrundage</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.msdn.com/mediaandmicrocode/comments/8729498.aspx</comments><wfw:commentRss>http://blogs.msdn.com/mediaandmicrocode/commentrss.aspx?PostID=8729498</wfw:commentRss><description>&lt;P&gt;In the pursuit of my passion of media (specifically, trying to prune my DVR collection in a more flexible way than Windows Media Center), I started getting curious about how I could get the same kind of data that Windows Explorer has about some RecordedTV.&amp;nbsp; Since I could find it using the Search dialog in Windows, I thought that Windows Desktop Search should have some way to get at it as well.&amp;nbsp; After a number of searches, I ran across &lt;A href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan07/hey0105.mspx" mce_href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/jan07/hey0105.mspx"&gt;this&lt;/A&gt; little snippet from &lt;A href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx" mce_href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx"&gt;Greg Stemp's "Hey, Scripting Guy!" column&lt;/A&gt;.&amp;nbsp; It walks through &lt;A href="http://www.microsoft.com/technet/scriptcenter/topics/desktop/wdsearch.mspx" mce_href="http://www.microsoft.com/technet/scriptcenter/topics/desktop/wdsearch.mspx"&gt;how to extract out the DateTaken information from a JPEG&lt;/A&gt;.&amp;nbsp; This article provides valuable code snippets from VBScript that I used to create a Windows PowerShell function (Search-WindowsDesktop).&amp;nbsp; The article also contained a small link to a reference of &lt;A href="http://www.microsoft.com/technet/scriptcenter/topics/desktop/wdsprops.mspx" mce_href="http://www.microsoft.com/technet/scriptcenter/topics/desktop/wdsprops.mspx"&gt;almost every special query field that Windows Desktop Search provides&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;That reference is the backbone of a number of scripts that I will post about here, but, in the interests of keeping it simple, I will post the final scripts in a later post.&amp;nbsp; It's also an example of how I go about solving problems.&amp;nbsp; When faced with a problem, my passion for programming partitions the problem.&amp;nbsp; I break each problem into a smaller set of individual problems with independent solutions.&amp;nbsp; This has a number of side-effects:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Increases the possibility that I might have a or know about a solution to a problem similar to the smaller problem &lt;/LI&gt;
&lt;LI&gt;Forces the mind to think of independent solutions to parts, which helps you build a number of reusable components instead of one throw away script &lt;/LI&gt;
&lt;LI&gt;Allows me to search for the answers to the unsolved problems more flexibly &lt;/LI&gt;
&lt;LI&gt;Opens the possibility to finding better answers for the independent problems later on, which can improve the flow and performance of the entire system &lt;/LI&gt;
&lt;LI&gt;Exposes me to potential other problems I could solve at reduced cost &lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;In the case above, I broke the original problem into a few problems:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Where can I find RecordedTV Metadata? 
&lt;UL&gt;
&lt;LI&gt;Where can I find the most metadata? Answer: (Windows Desktop Search) &lt;/LI&gt;
&lt;LI&gt;How do I get at it from scripts? 
&lt;UL&gt;
&lt;LI&gt;Where do I usually find scripts? (Answer: &lt;A href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx" mce_href="http://www.microsoft.com/technet/scriptcenter/resources/qanda/hsgarch.mspx"&gt;Technet&lt;/A&gt;) &lt;/LI&gt;
&lt;LI&gt;Is there a solution here for RecordedTV? (Answer: not that I can find) &lt;/LI&gt;
&lt;LI&gt;What other metadata could I look for? 
&lt;UL&gt;
&lt;LI&gt;Photos (Answer: &lt;A href="http://www.microsoft.com/technet/scriptcenter/topics/desktop/wdsearch.mspx" mce_href="http://www.microsoft.com/technet/scriptcenter/topics/desktop/wdsearch.mspx"&gt;Seek and Ye Shall Find - Scripting Windows Desktop Search 3.0&lt;/A&gt;) &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;How can I display the data? (Answer: Tediously, or I can use Windows PowerShell, which will display the properties on the object for free) &lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Since the example that I have searches for Photo Metadata, which might be fun to script, Instead of making a function that just gets my recorded TV, I'm going to make a function that can query Windows Desktop Search for any field that I want and can come back with data.&amp;nbsp; Then I will write a script to get out my DVR metadata, but I can always build more interesting stuff from this core component later.&amp;nbsp; By building many things that depend on this core script, and ensuring that they all continue to work, I can make a flexible solution that can be extended upon and improved later.&lt;/P&gt;
&lt;P&gt;Here's my function to pull data out of Windows Desktop Search:&lt;/P&gt;
&lt;P&gt;function Search-WindowsDesktop($fields, $filter) &lt;BR&gt;{ &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $connection = New-Object -comObject "ADODB.Connection" &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $recordSet = New-Object -comObject "ADODB.RecordSet" &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $null = $connection.Open("Provider=Search.CollatorDSO;Extended Properties='Application=Windows';") &amp;gt; $null &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $ofs = "," &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $query = "SELECT $fields" &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $query += " FROM SYSTEMINDEX $filter" &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $null = $recordSet.Open($query, $connection) &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ($recordSet.EOF) { return } &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $recordSet.MoveFirst() &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; while (-not $recordSet.EOF) {&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; $result = New-Object Object &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach ($field in $fields) { &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; $result | Add-Member NoteProperty $field $recordSet.Fields.Item($field).Value &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; $result &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $recordSet.MoveNext() &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; } &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $null = $recordSet.Close() &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $null = $connection.Close() &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $connection = $null &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $recordSet = $null &lt;BR&gt;}&lt;/P&gt;
&lt;P&gt;Here's a a few quick samples of using it that I'll expand upon later:&lt;/P&gt;
&lt;P&gt;Search-WindowsDesktop "System.Title", "System.RecordedTV.EpisodeName" "WHERE System.RecordedTV.ChannelNumber IS NOT NULL"&lt;/P&gt;
&lt;P&gt;Search-WindowsDesktop "System.Contact.FullName" "WHERE System.Contact.FullName IS NOT NULL"&lt;/P&gt;
&lt;P&gt;Search-WindowsDesktop "System.Photo.CameraModel", "System.Photo.ProgramModeText", "System.Photo.OrientationText" "WHERE System.Photo.DateTaken IS NOT NULL"&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=8729498" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Windows+Media+Center/default.aspx">Windows Media Center</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/MetaData/default.aspx">MetaData</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/TechNet/default.aspx">TechNet</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Windows+Desktop+Search/default.aspx">Windows Desktop Search</category><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/DVR/default.aspx">DVR</category><category domain="http://blogs.msdn.com/mediaandmicrocode/archive/tags/Search-WindowsDesktop/default.aspx">Search-WindowsDesktop</category></item></channel></rss>