<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://powershell.com/cs/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>Search results for 'app:weblogs' matching tags 'Weekend Scripter', 'XML', and 'Scripting Guy!'</title><link>http://powershell.com/cs/search/SearchResults.aspx?q=app:weblogs&amp;tag=Weekend+Scripter,XML,Scripting+Guy!&amp;orTags=0&amp;o=DateDescending</link><description>Search results for 'app:weblogs' matching tags 'Weekend Scripter', 'XML', and 'Scripting Guy!'</description><dc:language>en-US</dc:language><generator>CommunityServer 2008.5 (Build: 30929.2835)</generator><item><title>The Scripting Wife Learns to Use PowerShell to Work with XML</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2012/03/25/the-scripting-wife-learns-to-use-powershell-to-work-with-xml.aspx</link><pubDate>Sun, 25 Mar 2012 05:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:15526</guid><dc:creator>Anonymous</dc:creator><description>&lt;p&gt;&lt;b&gt;Summary&lt;/b&gt;: In this blog, the Scripting Wife learns how to use Windows PowerShell to work with an XML file.&lt;/p&gt;
&lt;p&gt;Microsoft Scripting Guy, Ed Wilson, is here. It is only eight days until the kickoff of the 2012 Scripting Games. Tomorrow the signup for the 2012 Scripting Games goes live. I have finished all the meetings, and everything is now in readiness state for the big event. I am sitting in the kitchen sipping a cup of English Breakfast tea, and looking over the chapter that I completed last night in my &lt;a href="http://shop.oreilly.com/product/0790145337382.do" target="_blank"&gt;Windows PowerShell 3.0 Step by Step&lt;/a&gt; book. I close my eyes to think about one particular sentence when all of a sudden I feel a presence come into the room.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;If you are going to sleep, then you should get up from the table,&amp;rdquo; the Scripting Wife chided.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;I am not sleeping, I am deep in thought,&amp;rdquo; I replied.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Then I am in deep trouble,&amp;rdquo; the Scripting Wife rejoined.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;What are you doing in here? The sun is still up,&amp;rdquo; I joked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Very funny. In fact, it is so funny I forgot to laugh,&amp;rdquo; she said. &amp;ldquo;Actually, since you are not doing anything, I need to you tell me about XML.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Say what?&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;XML. I need to know how to read an XML file,&amp;rdquo; she repeated.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;You are kidding.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Nope. I exported my book database, and it saved as an XML file. I need to know how to read it,&amp;rdquo; the Scripting Wife explained.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;OK. That makes sense. In Windows PowerShell, it is really easy. How do you read a plain text file?&amp;rdquo; I asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;I use the &lt;b&gt;Get-Content &lt;/b&gt;cmdlet,&amp;rdquo; she said.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;It is the same thing, except that you use the letters XML inside square brackets. Open up Windows PowerShell on your computer, and then use &lt;b&gt;Get-Content &lt;/b&gt;to read the XML file.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The Scripting Wife stores her books.xml file in the FSO directory on her C:\ drive. Therefore, her command looks like this:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;[xml]$books = Get-Content C:\fso\books.xml&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Now look at what is contained in the &lt;b&gt;$books&lt;/b&gt; variable,&amp;rdquo; I suggested.&lt;/p&gt;
&lt;p&gt;The Scripting Wife typed the &lt;b&gt;$books&lt;/b&gt; variable on its own line in the Windows PowerShell console. The command and its associated output are shown in the image that follows.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1440.HSG_2D00_3_2D00_25_2D00_12_2D00_01.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/1440.HSG_2D00_3_2D00_25_2D00_12_2D00_01.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Now look at the &lt;b&gt;XML&lt;/b&gt; property,&amp;rdquo; I suggested.&lt;/p&gt;
&lt;p&gt;The Scripting Wife typed the following command.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.xml&lt;/p&gt;
&lt;p&gt;&amp;ldquo;OK. Now look at the &lt;b&gt;BookInfo&lt;/b&gt; property.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;She typed the command that appears here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.&lt;/p&gt;
&lt;p&gt;The command to examine the &lt;b&gt;XML&lt;/b&gt; property and the command to look at the &lt;b&gt;BookInfo&lt;/b&gt; property are shown in the image that follows, along with the associated output.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2625.HSG_2D00_3_2D00_25_2D00_12_2D00_02.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/2625.HSG_2D00_3_2D00_25_2D00_12_2D00_02.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;What is that booklist?&amp;rdquo; the Scripting Wife asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;I don&amp;rsquo;t know. Why don&amp;rsquo;t you access it and see.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The Scripting Wife used the Up arrow to retrieve the previous command, and added &lt;b&gt;BookList&lt;/b&gt;&lt;i&gt; &lt;/i&gt;to the end of the command and pressed ENTER. Here is her command:&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Well, it looks like a bunch of books,&amp;rdquo; she replied as she turned her monitor to me so I could see. The image that follows shows her Windows PowerShell console.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7607.HSG_2D00_3_2D00_25_2D00_12_2D00_03.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/7607.HSG_2D00_3_2D00_25_2D00_12_2D00_03.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Why don&amp;rsquo;t you keep going&amp;hellip;But this time, pipe the output to &lt;b&gt;More&lt;/b&gt;&lt;i&gt; &lt;/i&gt;just in case you get all of your books rolling by,&amp;rdquo; I suggested.&lt;/p&gt;
&lt;p&gt;The Scripting Wife once again used the Up arrow to retrieve her previous command, added &lt;b&gt;Book&lt;/b&gt;&lt;i&gt; &lt;/i&gt;to the end of the command, and piped the output to &lt;b&gt;More&lt;/b&gt;&lt;i&gt;. &lt;/i&gt;The command is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book | more&lt;/p&gt;
&lt;p&gt;Sure enough, after a few seconds, the book information began to scroll. The first little bit is shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3010.HSG_2D00_3_2D00_25_2D00_12_2D00_04.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/3010.HSG_2D00_3_2D00_25_2D00_12_2D00_04.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Well that looks interesting, but how can I find more information about a book?&amp;rdquo; she asked.&lt;/p&gt;
&lt;p&gt;&amp;ldquo;Why don&amp;rsquo;t you index into the collection? Choose the first book,&amp;rdquo; I suggested.&lt;/p&gt;
&lt;p&gt;The Scripting Wife thought for a few seconds, and then she used the Up arrow to retrieve her previous command and then added the index operator. Her command is shown here.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book[0]&lt;/p&gt;
&lt;p&gt;The output from the previous command is shown here.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6327.HSG_2D00_3_2D00_25_2D00_12_2D00_05.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/6327.HSG_2D00_3_2D00_25_2D00_12_2D00_05.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;ldquo;You can use the same techniques to find information about the subjects of the book, and to find information about the title, plot, and other information.&amp;rdquo;&lt;/p&gt;
&lt;p&gt;The Scripting Wife typed the commands that follow. As she examined the output from each command she continued to burrow deeper and deeper into the data structure of the first book.&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book[0].subjects&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book[0].subjects.subject&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book[0].mainsection&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book[0].mainsection.authors&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book[0].mainsection.authors.author&lt;/p&gt;
&lt;p style="padding-left:30px;"&gt;$books.bookinfo.booklist.book[0].mainsection.authors.author.person&lt;/p&gt;
&lt;p&gt;Finally, she sat back and examined her handiwork. The output from these commands are shown in the image that follows.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.technet.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8032.HSG_2D00_3_2D00_25_2D00_12_2D00_06.png"&gt;&lt;img src="http://blogs.technet.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-76-18/8032.HSG_2D00_3_2D00_25_2D00_12_2D00_06.png" alt="Image of command output" title="Image of command output" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I invite you to follow me on &lt;a href="http://bit.ly/scriptingguystwitter" target="_blank"&gt;Twitter&lt;/a&gt; and &lt;a href="http://bit.ly/scriptingguysfacebook" target="_blank"&gt;Facebook&lt;/a&gt;. If you have any questions, send email to me at &lt;a href="mailto:scripter@microsoft.com" target="_blank"&gt;scripter@microsoft.com&lt;/a&gt;, or post your questions on the &lt;a href="http://bit.ly/scriptingforum" target="_blank"&gt;Official Scripting Guys Forum&lt;/a&gt;. See you tomorrow. Until then, peace.&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Ed Wilson, Microsoft Scripting Guy&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3488316" width="1" height="1" alt="" /&gt;</description></item><item><title>Weekend Scripter: Easily Explore XML Files with PowerShell</title><link>http://powershell.com/cs/blogs/hey-scriptingguy/archive/2011/01/09/weekend-scripter-easily-explore-xml-files-with-powershell.aspx</link><pubDate>Sun, 09 Jan 2011 06:00:00 GMT</pubDate><guid isPermaLink="false">f421715f-7aba-45f0-8a8d-44de5318a3a7:8973</guid><dc:creator>Anonymous</dc:creator><description>Summary: Guest blogger and Microsoft MVP, Sean Kearney, shows how to explore XML files with Windows PowerShell in this beginner how-to article. Microsoft Scripting Guy Ed Wilson here. We have another guest blogger this weekend. Sean Kearney has been working...(&lt;a href="http://blogs.technet.com/b/heyscriptingguy/archive/2011/01/09/weekend-scripter-easily-explore-xml-files-with-powershell.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3379122" width="1" height="1" alt="" /&gt;</description></item></channel></rss>