
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lead, Follow, or Move &#187; MSDN</title>
	<atom:link href="http://www.leadfollowmove.com/archives/tag/msdn/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leadfollowmove.com</link>
	<description>Adam Bell on Deployment, Automation, PowerShell et al</description>
	<lastBuildDate>Thu, 22 Apr 2010 14:34:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Listing your XML product keys from MSDN &#8211; Part 2</title>
		<link>http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn-part-2</link>
		<comments>http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn-part-2#comments</comments>
		<pubDate>Thu, 11 Oct 2007 11:14:41 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn-part-2</guid>
		<description><![CDATA[In the last post we we&#8217;re playing around with how to extract a Product Key from an MSDN exported XML document. We&#8217;ll take this a step further today and see if we turn it into something a little more useful. Building on the previous script, we want to list the products that match our search [...]]]></description>
			<content:encoded><![CDATA[<p>In the last post we we&#8217;re playing around with how to extract a Product Key from an MSDN exported XML document. We&#8217;ll take this a step further today and see if we turn it into something a little more useful.</p>
<p>Building on the previous script, we want to list the products that match our search criteria and then select the one we want the Product Key for. As well as displaying this information on screen, it would be useful if the key could be put into the clipboard, ready for use.</p>
<div class="quickcodenoclick"><code><br />
$msdn = Get-Content MSDN-Sample-ProdKeys.xml<br />
$msdn.Your_Product_Keys.Product_Key.Count<br />
# Initialise the Hash Table<br />
$lookup = @{}<br />
&nbsp;<br />
$product = read-host &quot;what product are you using?&quot;<br />
$i = 0<br />
foreach ($item in $msdn.Your_Product_Keys.Product_Key)<br />
{<br />
&nbsp;&nbsp;if ($item.name -like &quot;*$product*&quot;)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;$lookup = $lookup + @{$i=$item.name}<br />
&nbsp;&nbsp;&nbsp;&nbsp;write-host $i &quot;:&quot; $item.name<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;$i ++<br />
}<br />
$ID = read-host &quot;Please enter the number of the product you want&quot;<br />
$msdn.Your_Product_Keys.Product_Key[$ID].Key | clip<br />
write-host ($msdn.Your_Product_Keys.Product_Key[$ID].Name) &quot;(&quot;($msdn.Your_Product_Keys.Product_Key[$ID].Key)&quot;)&quot; -foregroundcolor &quot;cyan&quot;<br />
</code></div>
<p>The first thing, was to change where we increment the <em>$i</em> variable. I found during testing that we were returning the incorrect number to retrieve the details from the XML document. Incrementing at the end of the <em>foreach</em> corrected this oversight. We&#8217;ve also removed displaying the Product Key until the end of the script, to make things neater.</p>
<p>The main new feature has been to use an <a title="Wikipedia: PowerShell Associative Array" href="http://http://en.wikipedia.org/wiki/Associative_array#Windows_PowerShell">associative array</a>, or hash table,  to store our ID number and <em>Product Name</em>. The ID number identifies which node in the XML document our product is stored in.</p>
<p>Once, the hash table has been built with a list of potential products, the user is prompted to enter the ID number of the specific product.  The ID is then used to lookup the Product&#8217;s Name and Key form the XML document, which is then displayed on screen and put in the clipboard buffer by using the clip.exe utility available on Windows 2003 Server and Vista.</p>
<p><a href='http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn-part-2/attachment/show-msdnkeyps1-part-2-5/' rel='attachment wp-att-190' title='show-msdnkey.ps1 Part 2'><img src='http://www.leadfollowmove.com/wp-content/uploads/show-msdnkey21.thumbnail.png' alt='show-msdnkey.ps1 Part 2' /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn-part-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Listing your XML product keys from MSDN</title>
		<link>http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn</link>
		<comments>http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn#comments</comments>
		<pubDate>Tue, 09 Oct 2007 19:27:26 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[MSDN]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn</guid>
		<description><![CDATA[I&#8217;m lucky enough to have an MSDN subscription at work. If you&#8217;re familiar with this service, you will know that when you request a Product Key, there is an option to download it in XML format. One of my favourite things with PowerShell, is how it handles XML. $msdn = Get-Content MSDN-Sample-ProdKeys.xml $msdn.Your_Product_Keys.Product_Key.Count &#160; $product [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m lucky enough to have an MSDN subscription at work. If you&#8217;re familiar with this service, you will know that when you request a Product Key, there is an option to download it in XML format.<br />
<a href='http://www.leadfollowmove.com/wp-content/uploads/sample-msdn-xml.PNG' title='Sample MSDN Product Key Export to XML'><img src='http://www.leadfollowmove.com/wp-content/uploads/sample-msdn-xml.thumbnail.PNG' alt='Sample MSDN Product Key Export to XML' /></a></p>
<p>One of my favourite things with PowerShell, is how it handles XML.</p>
<div class="quickcodenoclick"><code><br />
$msdn = Get-Content MSDN-Sample-ProdKeys.xml<br />
$msdn.Your_Product_Keys.Product_Key.Count<br />
&nbsp;<br />
$product = read-host &quot;what product are you using?&quot;<br />
$i = 0<br />
foreach ($item in $msdn.Your_Product_Keys.Product_Key)<br />
{<br />
&nbsp;&nbsp;$i ++<br />
&nbsp;&nbsp;if ($item.name -like &quot;*$product*&quot;)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;write-host $i &quot;:&quot; $item.name &quot;(&quot; $item.key &quot;)&quot;<br />
&nbsp;&nbsp;}<br />
}<br />
</code></div>
<p>A quick look through the code shows how simple it really is. we define <em>$msdn</em> as an XML type and get the contents of our MSDN exported keys. As a quick sanity check we output how many nodes are under <em>Product_Key</em>.</p>
<p>We then prompt the user for some guidance on what product is of interest. Looping through the nodes any item that is <em>like</em> our supplied product is returned, along with the node number, and product key.<br />
<a href='http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn/attachment/show-msdnkeyps1/' rel='attachment wp-att-184' title='show-msdnkey.ps1'><img src='http://www.leadfollowmove.com/wp-content/uploads/show-msdnkey.thumbnail.PNG' alt='show-msdnkey.ps1' /></a></p>
<p>As you can see in the example above, the first time the script is run we provided no input, which returned us all the contents of the file. The second time we searched on the term <em>xp</em>.</p>
<p>If you&#8217;re wondering why we kept track of the node number, we&#8217;ll expand on this example next time to see if we can improve on the script to make it a bit more useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/powershell/listing-your-xml-product-keys-from-msdn/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
