<?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>The Geekery &#187; Microsoft</title>
	<atom:link href="http://jon.netdork.net/category/technology/microsoft/feed" rel="self" type="application/rss+xml" />
	<link>http://jon.netdork.net</link>
	<description>The Usual Stuff...</description>
	<lastBuildDate>Sun, 18 Jul 2010 16:53:23 +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>Windows 2008, and Hibernation</title>
		<link>http://jon.netdork.net/2010/07/06/windows-2008-and-hibernation?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=windows-2008-and-hibernation</link>
		<comments>http://jon.netdork.net/2010/07/06/windows-2008-and-hibernation#comments</comments>
		<pubDate>Wed, 07 Jul 2010 01:51:18 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Sys Admin]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=903</guid>
		<description><![CDATA[Whilst driving back from our 4th of July celebrations in San Antonio, I got alerted to a server running low on disk space.&#160; As it hadn’t hit critical, and there was still a fair bit of space left, I decided to wait until I got home.&#160; When I looked at the server, I pulled up [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F07%2F06%2Fwindows-2008-and-hibernation">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F07%2F06%2Fwindows-2008-and-hibernation&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly" height="61" width="50" />
			</a>
		</div><p></p><p>Whilst driving back from our 4th of July celebrations in San Antonio, I got alerted to a server running low on disk space.&#160; As it hadn’t hit critical, and there was still a fair bit of space left, I decided to wait until I got home.&#160; When I looked at the server, I pulled up my trusted space analyzer, <a href="http://www.jam-software.com/treesize_free/" target="_blank">TreeSize</a>.</p>  <span id="more-903"></span>  <p><a href="http://jon.netdork.net/wp-content/uploads/2010/07/image.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" class="wlDisabledImage" title="image" border="0" alt="image" align="right" src="http://jon.netdork.net/wp-content/uploads/2010/07/image_thumb.png" width="244" height="72" /></a>A quick analysis of the drive, and a report showed that there was a hefty chunk of space lost to the WinSXS directory, and 8GB of <em>Files</em> in the root of C:.&#160; This was a little odd, I know I usually use c:\temp from time to time, but never the root.&#160; To find out what was there, I first had to show hidden and system files.&#160; To do this, go to Tools, then Folder Options, then onto the View tab.&#160; There are 3 options there that we need to change.</p>  <ol>   <li>Change “Hidden files and folders” to “Show hidden files and folders”</li>    <li>Uncheck “Hide extensions for known file types”</li>    <li>Uncheck “Hide protected operating system files (Recommended)”</li> </ol>  <p>I <strong><em>highly</em></strong> recommend doing 2 all the time, you never know when somebody might sent a .txt.exe file.&#160; Changing 3 will prompt that it isn’t recommended, but do it anyway, the files I was having issues with were still hidden after changing the first two.</p>  <p>After making these changes, two files appeared that were the culprits to the lost disk space.&#160; <em>Pagefile.sys</em> and <em>Hiberfil.sys</em>.&#160; I’ll leave the explanation of the <em><a title="TechNet; What is the Page File for Anyway?" href="http://blogs.technet.com/b/askperf/archive/2007/12/14/what-is-the-page-file-for-anyway.aspx" target="_blank">Pagefile</a></em> to the experts.&#160; <em>Hiberfil.sys</em> is a file that is used to handle the state of memory, and running applications when you hibernate your computer.&#160; </p>  <h2>What is hibernation?</h2>  <p>Hibernation is a heavy sleep state for computers where all the running processes are frozen, the memory is locked, and all the states are saved into that file, then the computer is powered down.&#160; When the computer is turned back on, the operating system sees this <em>state</em> file, and starts to reload everything from there.&#160; This makes it appear like the computer was never even turned off.&#160; The applications are resumed, everything is back to the state it was before hibernation was kicked off.</p>  <h2>Why is that bad?</h2>  <p>Generally speaking, it isn’t.&#160; In fact, it’s a great thing for home computers.&#160; When you’re done reading your email at night, if you hibernate your computer, and hop into bed, your computer will be off, saving power.&#160; However this isn’t so good for servers.&#160; In 95% of cases, servers don’t ever need to hibernate.&#160; They usually have tasks, and operations that they need to run all the time, which means putting them in a state of hibernation is a bad thing as the tasks won’t be run.</p>  <h2>How do you stop this?</h2>  <p>Usually, servers have this feature turned off, but for some reason this particular one had it enabled.&#160; I’ve done some looking around, and it seems it’s may have actually been a default option to have it enabled, but for some (<em>lucky</em>) reason a handful of our other servers don’t have it on.&#160; In earlier versions of Windows, disabling the hibernation option was a case of removing a check mark from a box.&#160; This was done in the <em>Control Panel</em> under <em>Power Options</em>, and the <em>Hibernate</em> tab.&#160; However, in Windows 2008 this option was removed, and you now have to use a command line to manage this advanced option.</p>  <p></p>

<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp;powercfg –hibernate off</div></div>

<p></p>  <p>Within about 10 seconds of issuing that command, the <em>Hiberfil.sys </em>file disappeared, and I recovered 4GB of disk space.&#160; You can read more about the <em>powercfg</em> command <a title="TechNet; Powercfg Command-Line options" href="http://technet.microsoft.com/en-us/library/cc748940%28WS.10%29.aspx" target="_blank">here</a>.</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/07/06/windows-2008-and-hibernation/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	<!-- google ad injected by adsense-optimizer http://www.adsenseoptimizer.de -->
			<div  style="padding:7px; display: block; margin-left: auto; margin-right: auto; text-align: center;"><!-- Linkblock number: 1 --><script type="text/javascript"><!--
	 
google_ad_client = "pub-5380792458095798";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al"; google_ad_channel ="";
google_color_border = "CCCCCC";
google_color_bg = "F7F7F7";
google_color_link = "2970A6";
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>	<item>
		<title>IIS and unknown file types</title>
		<link>http://jon.netdork.net/2010/06/17/iis-and-unknown-file-types?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=iis-and-unknown-file-types</link>
		<comments>http://jon.netdork.net/2010/06/17/iis-and-unknown-file-types#comments</comments>
		<pubDate>Thu, 17 Jun 2010 20:01:34 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=867</guid>
		<description><![CDATA[Since IIS6, or there abouts, IIS will not host a file that it does not understand, or doesn&#8217;t have a MIME handler for. This is a security feature, but can cause some unknown issues&#8230; We use some customer facing training software by Skillsoft. They produce a Java application which allows you to record voice, and [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F06%2F17%2Fiis-and-unknown-file-types">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F06%2F17%2Fiis-and-unknown-file-types&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=IIS,SysAdmin" height="61" width="50" />
			</a>
		</div><p>Since IIS6, or there abouts, <acronym title="Internet Information Services">IIS</acronym> will not host a file that it does not understand, or doesn&#8217;t have a <acronym title="Multipurpose Internet Mail Extension">MIME</acronym> handler for.  This is a security feature, but can cause some unknown issues&#8230;</p>

<p><span id="more-867"></span></p>

<p>We use some customer facing training software by Skillsoft.  They produce a Java application which allows you to record voice, and screen shows for training, and follow up with a questionnaire after.  Unfortunately because it&#8217;s Java, when something goes wrong, it&#8217;s very <em>blackbox</em>((A term coined to explain that you can see the outsides, but have no idea what&#8217;s going on inside)) like, making it hard to diagnose any issues.  In this case, the splash screen would load, and that&#8217;s where it&#8217;d stop.</p>

<p>Fortunately, the Java console does provide enough information to give us a hint as to what might be wrong.  When opening a Java application, the little console app appears in the notification area next to the clock.  This allows you to see if the app throws any errors.  In our case, it was complaining that a file with the extension .properties was missing from the server (<acronym title="Internet Information Services">IIS</acronym> was throwing a 404 message).  A quick showed it existed in the directory structure.</p>

<p>This is because <acronym title="Internet Information Services">IIS</acronym> doesn&#8217;t know what a <em>.properties</em> file is, or how it should be treated.  This is easily remedied.  In <acronym title="Internet Information Services">IIS</acronym> manager, either under the site, or at the root level, go to the <acronym title="Multipurpose Internet Mail Extension">MIME</acronym> option, and add it.  In this case, the file extension was .properties, and the <acronym title="Multipurpose Internet Mail Extension">MIME</acronym> Type was specified as <em>application/octet-stream</em>. If it&#8217;s done at the root server level, it applies to all sites.  If you do it on a site, it only applies to the site you changed it on.  No resets, or such, required.  Now the file is served properly.</p>

<p>Microsoft has this documented on <a href="http://support.microsoft.com/kb/326965" title="Microsoft; KB326965">KB326965</a>.  Whilst this applies to IIS6, the same applies to IIS7 as well.  To save some waiting in IIS7, you can use the appcmd to add the type for you&#8230;</p>

<div class="codecolorer-container dos default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">appcmd <a href="http://www.ss64.com/nt/set.html"><span style="color: #b1b100; font-weight: bold;">set</span></a> config /section:staticContent /+&quot;<span style="color: #66cc66;">&#91;</span>fileExtension='.properties',mimeType='application/octet-stream'<span style="color: #66cc66;">&#93;</span>&quot;</div></div>

<p>This applies the setting at the root server level, and is usually inherited down to all sites.</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/06/17/iis-and-unknown-file-types/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cleaning up remote directories with PowerShell</title>
		<link>http://jon.netdork.net/2010/05/24/cleaning-up-remote-directories-with-powershell?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cleaning-up-remote-directories-with-powershell</link>
		<comments>http://jon.netdork.net/2010/05/24/cleaning-up-remote-directories-with-powershell#comments</comments>
		<pubDate>Tue, 25 May 2010 02:19:41 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[File Management]]></category>
		<category><![CDATA[WMI]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=822</guid>
		<description><![CDATA[Part of our application at work sends email notifications to various uses when certain criteria are met. This is great, except testing is difficult as you really don&#8217;t want to send out mails to valid customers, so we disable relaying outbound, and the local mail server just chomps on it a bit, then decides to [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F05%2F24%2Fcleaning-up-remote-directories-with-powershell">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F05%2F24%2Fcleaning-up-remote-directories-with-powershell&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=File+Management,PowerShell,WMI" height="61" width="50" />
			</a>
		</div><p>Part of our application at work sends email notifications to various uses when certain criteria are met.  This is great, except testing is difficult as you really don&#8217;t want to send out mails to valid customers, so we disable relaying outbound, and the local mail server just chomps on it a bit, then decides to not deliver it and drops it to the local file system.  This is great, except in a the matter of days, we have 100k message files.  This becomes entirely unmanageable with Windows, so PowerShell is here to help&#8230;</p>

<p><span id="more-822"></span></p>

<p>There are plenty of articles on file management with PowerShell, pretty much all of them revolving around the <strong><a href="http://technet.microsoft.com/en-us/library/ee176841.aspx" title="Microsoft TechNet; Get-ChildItem">Get-ChildItem</a></strong> function.  This usually works pretty well, but is terrible on memory when it comes to handling this many files, and working with filters (only selecting files that are X days old).</p>

<p>This is when my brain clicked to a <a href="http://powershell.com" title="PowerShell.com">PowerShell.com</a> tip a few weeks back about <a href="http://powershell.com/cs/blogs/tips/archive/2010/04/15/wmi-server-side-filtering.aspx" title="PowerShell.com; WMI Server Side Filtering">Windows Management Instrumentation (<acronym title="Windows Management Instrumentation">WMI</acronym>) based filters</a>.  I won&#8217;t go into the dark recesses of my brain, and try an explain why I have a weird ability to remember some weird function that I used 5 years ago, but I&#8217;ll save you some work and introduce you to the <acronym title="Windows Management Instrumentation">WMI</acronym> class <a href="http://msdn.microsoft.com/en-us/library/aa387236(v=VS.85).aspx" title="MSDN; CIM_DataFile">CIM_DataFile</a>.  The cool thing about using <acronym title="Windows Management Instrumentation">WMI</acronym> to do this, you can use the server side filters to do most of the dirty work for you.  So lets see the example:</p>

<div class="codecolorer-container posh default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="posh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> CIM_DataFile <span style="color: pink;">-</span>Computer yourremoteserver `<br />
&nbsp; &nbsp; <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #800000;">&quot;Drive='C:' and Path='\\InetPub\\MailRoot\\BadMail\\'&quot;</span></div></div>

<p>Okay, that was pretty easy&#8230; right?  That just gets all the files in the folder C:\inetpub\mailroot\badmail on the server yourremoteserver.  Now we want to limit it to just keeping the mail from the last 3 days.  Before I did into the code that does this, the date format on CIM_DataFile through PowerShell is a little &#8216;odd&#8217;.  Don&#8217;t believe me?  Try this:</p>

<div class="codecolorer-container posh default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="posh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> CIM_DataFile `<br />
&nbsp; &nbsp; <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #800000;">&quot;Drive='C:' and Path='\\Temp\\'&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> FileName<span style="color: pink;">,</span>CreationDate</div></div>

<p>You will probably end up with something that looks like this:</p>

<div class="codecolorer-container posh default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="posh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">FileName &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; CreationDate<br />
<span style="color: pink;">--------</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">------------</span><br />
process_usage &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #804000;">20100407083839.775225</span><span style="color: pink;">-</span><span style="color: #804000;">300</span><br />
proxy1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">20100517150112.509957</span><span style="color: pink;">-</span><span style="color: #804000;">300</span><br />
proxy2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">20100517150105.506804</span><span style="color: pink;">-</span><span style="color: #804000;">300</span><br />
Registration &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">20100131221914.239533</span><span style="color: pink;">-</span><span style="color: #804000;">360</span><br />
sql_job_status &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">20100401160936.442674</span><span style="color: pink;">-</span><span style="color: #804000;">300</span></div></div>

<p>Okay, not too odd, it&#8217;s really just the date in the format YYYYmmddhhmmss.nnnnnn-tzo. n is milliseconds, and tzo is the timezone offset in minutes.  In the above example, 300 would be 5 hours, 360 is 6 hours.  This means, for the query, we have to modify slightly.</p>

<div class="codecolorer-container posh default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="posh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span><br />
<span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #800080;">$date</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$sDate</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0:00}{1:00}{2:00}000000.000000-000&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$date</span>.Year<span style="color: pink;">,</span> <span style="color: #800080;">$date</span>.Month<span style="color: pink;">,</span> <span style="color: #800080;">$date</span>.Day<br />
<span style="color: #008080; font-weight: bold;">Get-WmiObject</span> CIM_DataFile <span style="color: pink;">-</span>Computer yourremoteserver `<br />
&nbsp; &nbsp; <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #800000;">&quot;Drive='C:' and Path='\\InetPub\\MailRoot\\BadMail\\' and CreationDate &lt;= '$sDate'&quot;</span></div></td></tr></tbody></table></div>

<p>You might be wondering what that weird stuff on line 3 is, it&#8217;s the PowerShell equivalent to C#&#8217;s <a href="http://msdn.microsoft.com/en-us/library/system.string.format(v=VS.71).aspx" title="MSDN; c# string.format">string.Format</a>.  This takes the date we had, and reformats it nicely for <acronym title="Windows Management Instrumentation">WMI</acronym> to use.  This is much nicer, gets <acronym title="Windows Management Instrumentation">WMI</acronym> to do all the grunt work, and is much more friendly on the server (memory/CPU).  Next, the delete&#8230;</p>

<div class="codecolorer-container posh default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="posh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span><br />
<span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #800080;">$date</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$sDate</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0:00}{1:00}{2:00}000000.000000-000&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$date</span>.Year<span style="color: pink;">,</span> <span style="color: #800080;">$date</span>.Month<span style="color: pink;">,</span> <span style="color: #800080;">$date</span>.Day<br />
<span style="color: #008080; font-weight: bold;">Get-WmiObject</span> CIM_DataFile <span style="color: pink;">-</span>Computer yourremoteserver `<br />
&nbsp; &nbsp; <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #800000;">&quot;Drive='C:' and Path='\\InetPub\\MailRoot\\BadMail\\' and CreationDate &lt;= '$sDate'&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span><span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Delete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span></div></div>

<p>As I mentioned at the beginning, it&#8217;s possible to use the <strong>Get-ChildItem</strong> function to do the same thing (except it&#8217;s not remote), so I figured I&#8217;d show how too&#8230;</p>

<div class="codecolorer-container posh default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="posh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span><br />
<span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #800080;">$date</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008080; font-weight: bold;">Get-ChildItem</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800000;">'C:\inetpub\mailroot\badmail'</span> <span style="color: pink;">|</span> `<br />
&nbsp; &nbsp; <span style="color: pink;">?</span> <span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.CreationDate <span style="color: #FF0000;">-le</span> <span style="color: #800080;">$date</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> `<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">ForEach-Object</span><span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Delete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span></div></div>

<p>The problem you can see here, the filtering is done <em>after</em> all the items are fetched, rather than restricting the fetched list to begin with.  This cannot be executed remotely either (unless using network shares), so running this from a central job server is a little more tricky.</p>

<p>I&#8217;m sticking with the <acronym title="Windows Management Instrumentation">WMI</acronym> method for now, it&#8217;s fast, memory and CPU friendly, and does the job just as nicely.  How do you guys manage remote files with PowerShell? Any hints and tips?</p>

<p><strong>Edit:</strong> Thanks to <a href="http://www.stevenklassen.com/" title="Steven Klassen; Knowledge exists to be imparted.">Steven Klassen</a>, I edited some of the code.  Apparently the CodeColorer plugin was escaping my escape and only showing a single backslash on the end of some of the commands.</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/05/24/cleaning-up-remote-directories-with-powershell/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>SQL 2008 and MERGE</title>
		<link>http://jon.netdork.net/2010/05/14/sql-2008-and-merge?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sql-2008-and-merge</link>
		<comments>http://jon.netdork.net/2010/05/14/sql-2008-and-merge#comments</comments>
		<pubDate>Sat, 15 May 2010 01:08:35 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[TSQL]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=808</guid>
		<description><![CDATA[A feature I&#8217;ve long awaited in Microsoft SQL (TSQL) has been a function similar to MySQL&#8217;s REPLACE function. For those that haven&#8217;t used it, the REPLACE function allows you to do an insert of a new record, or replace an existing record if one matches the primary key. In SQL 2008, Microsoft introduced a function [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F05%2F14%2Fsql-2008-and-merge">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F05%2F14%2Fsql-2008-and-merge&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=Microsoft,SQL,TSQL" height="61" width="50" />
			</a>
		</div><p>A feature I&#8217;ve long awaited in Microsoft <acronym title="Structured Query Language">SQL</acronym> (TSQL) has been a function similar to MySQL&#8217;s <a href="http://dev.mysql.com/doc/refman/5.0/en/replace.html" title="MySQL Documentation; REPLACE">REPLACE</a> function.  For those that haven&#8217;t used it, the REPLACE function allows you to do an insert of a new record, or replace an existing record if one matches the primary key.  In <acronym title="Structured Query Language">SQL</acronym> 2008, Microsoft introduced a function called MERGE.  This is like REPLACE, but a whole bunch of extra goodies&#8230;</p>

<p><span id="more-808"></span></p>

<h2>About MySQL Replace</h2>

<p>Before I get into the fun stuff of MERGE, lets look at an example of MySQL&#8217;s REPLACE function.  We&#8217;ll do this by example, as everybody loves a good sample.  We&#8217;ll take a company that has a ticket tracking system, with a table containing the employee ID number, and their names.  We have an employee, Susan Johnson, who is about to get married to her long time high-school sweetheart, Scott Drew.  Susan&#8217;s employee ID is 55458.  There are two ways which we could update her last name in the database, the basic UPDATE statement, which will look like this:</p>

<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=UPDATE"><span style="color: #990099; font-weight: bold;">UPDATE</span></a> employees <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=SET"><span style="color: #990099; font-weight: bold;">set</span></a> last_name <span style="color: #CC0099;">=</span> <span style="color: #008000;">'Drew'</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=WHERE"><span style="color: #990099; font-weight: bold;">where</span></a> employee_id <span style="color: #CC0099;">=</span> <span style="color: #008080;">55458</span></div></div>

<p>Then there is the REPLACE method, which looks similar to an <a href="http://dev.mysql.com/doc/refman/5.0/en/insert.html" title="MySQL Documentation; INSERT">INSERT</a>:</p>

<div class="codecolorer-container mysql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="mysql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=REPLACE"><span style="color: #990099; font-weight: bold;">REPLACE</span></a> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=INTO"><span style="color: #990099; font-weight: bold;">INTO</span></a> employees <span style="color: #FF00FF;">&#40;</span>employee_id<span style="color: #000033;">,</span> last_name<span style="color: #FF00FF;">&#41;</span> <a href="http://search.mysql.com/search?site=refman-%35%31&amp;q=VALUES"><span style="color: #990099; font-weight: bold;">VALUES</span></a> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">55458</span><span style="color: #000033;">,</span> <span style="color: #008000;">'Drew'</span><span style="color: #FF00FF;">&#41;</span></div></div>

<p>In the event that HR had not done a good job, the REPLACE into statement would create a record if one did not exist for Susan, or if a record did exist for her, it would update her last name. Pretty cool huh?  There are some caveats to this function, so take a look at the <a href="http://dev.mysql.com/doc/refman/5.0/en/replace.html" title="MySQL Documentation; REPLACE">documentation</a>, and the user comments.</p>

<h2>T-<acronym title="Structured Query Language">SQL</acronym> MERGE</h2>

<p>Microsoft did a good job with this new function, making it quite flexible.  For a detailed look into it, you should read the <a href="http://technet.microsoft.com/en-us/library/bb510625.aspx" title="Microsoft Transact-SQL; MERGE">documentation</a>, it&#8217;s quite extensive, and gives a complex example, but for us, we&#8217;ll stick with our simple example of Susan  Johnson.</p>

<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MERGE employees <span style="color: #0000FF;">AS</span> target<br />
&nbsp; <span style="color: #0000FF;">USING</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">55458</span>, <span style="color: #FF0000;">'Drew'</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">AS</span> source <span style="color: #808080;">&#40;</span>employee_id, last_name<span style="color: #808080;">&#41;</span><br />
&nbsp; <span style="color: #0000FF;">ON</span> <span style="color: #808080;">&#40;</span>target.<span style="color: #202020;">employee_id</span> <span style="color: #808080;">=</span> source.<span style="color: #202020;">employee_id</span><span style="color: #808080;">&#41;</span><br />
&nbsp; <span style="color: #0000FF;">WHEN</span> MATCHED <span style="color: #0000FF;">THEN</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">UPDATE</span> <span style="color: #0000FF;">SET</span> last_name <span style="color: #808080;">=</span> source.<span style="color: #202020;">last_name</span><br />
&nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">NOT</span> MATCHED <span style="color: #0000FF;">THEN</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span> <span style="color: #808080;">&#40;</span>employee_id, last_name<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span>source.<span style="color: #202020;">employee_id</span>, source.<span style="color: #202020;">last_name</span><span style="color: #808080;">&#41;</span></div></div>

<p>Okay, that&#8217;s an awful lot of code that you managed to do with a single line in MySQL, but unlike MySQL the T-<acronym title="Structured Query Language">SQL</acronym> code allows you to match on <strong>any</strong> field, not just a primary key like employee ID.  Lets boost up the example, and show you what we can really do here&#8230;</p>

<p>For this, I&#8217;m going to use a sample of what I do nearly every day.  We get requests to add vehicles to a store&#8217;s data, or update data if it already exists.  Originally this would require two separate runs, an insert (using LEFT JOINs to find the missing target data), and an update.</p>

<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">MERGE vehicle_data <span style="color: #0000FF;">AS</span> target<br />
&nbsp; <span style="color: #0000FF;">USING</span> new_customer_vehicles <span style="color: #0000FF;">AS</span> source<br />
&nbsp; <span style="color: #0000FF;">ON</span> <span style="color: #808080;">&#40;</span>target.<span style="color: #202020;">vin</span> <span style="color: #808080;">=</span> source.<span style="color: #202020;">vin</span> and target.<span style="color: #202020;">stock_number</span> <span style="color: #808080;">=</span> source.<span style="color: #202020;">stock_number</span> and target.<span style="color: #202020;">in_date</span> <span style="color: #808080;">=</span> source.<span style="color: #202020;">in_date</span><span style="color: #808080;">&#41;</span><br />
&nbsp; <span style="color: #0000FF;">WHEN</span> MATCHED <span style="color: #0000FF;">THEN</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">UPDATE</span> <span style="color: #0000FF;">SET</span> target.<span style="color: #202020;">retail_price</span> <span style="color: #808080;">=</span> source.<span style="color: #202020;">retail_price</span><br />
&nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">NOT</span> MATCHED <span style="color: #0000FF;">THEN</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">INSERT</span> <span style="color: #808080;">&#40;</span>vin, stock_number, in_date, retail_price,status_id<span style="color: #808080;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">VALUES</span> <span style="color: #808080;">&#40;</span>source.<span style="color: #202020;">vin</span>, source.<span style="color: #202020;">stock_number</span>, source.<span style="color: #202020;">in_date</span>, source.<span style="color: #202020;">retail_price</span>,<span style="color: #000;">13</span><span style="color: #808080;">&#41;</span></div></div>

<p>Now with this example, we can see I do a lot more than match on the primary ID of the table (which in our case is actually vehicle_id).  This update would not have been possible with MySQL because it would have required you to use the vehicle_id from the vehicle_data table, which the new_customer_vehicles table did not have.  Whilst it still looks like a fair bit of code, it is now a single statement over 2 different statements to achieve the same thing.  There is something else handy about the MERGE function too, you get to do something with the unmatched data in the <em>target</em> side.  Taking the same as above, we&#8217;ll assume the customer sent us data straight from their system, and what they gave us must match, which means stuff we have showing, should no longer be showing.  We do this by changing the status ID.  Appending the following code allows us to tweak the records that don&#8217;t match&#8230;</p>

<div class="codecolorer-container tsql default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="tsql codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #0000FF;">WHEN</span> <span style="color: #808080;">NOT</span> MATCHED <span style="color: #0000FF;">BY</span> SOURCE<br />
&nbsp; &nbsp; <span style="color: #0000FF;">THEN</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">SET</span> target.<span style="color: #202020;">status_id</span> <span style="color: #808080;">=</span> <span style="color: #000;">48</span></div></div>

<p>Now that is a handy, and powerful function.  I dare say I&#8217;ll be using it a lot more now I&#8217;ve discovered it, and might even start poking our developers to start integrating it into places where it&#8217;d work better than what they are currently using.</p>

<p>This is just one of the cool things they added to <acronym title="Structured Query Language">SQL</acronym> 2008 that I like, what other things have they added that you like too?</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/05/14/sql-2008-and-merge/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Reverting a checkout from another workspace</title>
		<link>http://jon.netdork.net/2010/05/06/reverting-a-checkout-from-another-workspace?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=reverting-a-checkout-from-another-workspace</link>
		<comments>http://jon.netdork.net/2010/05/06/reverting-a-checkout-from-another-workspace#comments</comments>
		<pubDate>Thu, 06 May 2010 16:00:41 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[TFS]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=792</guid>
		<description><![CDATA[Every now and again, we have issues where a developer will have their laptop rebuilt, and forget they have files checked out in Team Foundation Server (TFS). This isn&#8217;t very helpful as sometimes they cannot undo their check outs. Visual Studio doesn&#8217;t give you access to undo a checkout in another workspace if it&#8217;s not [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F05%2F06%2Freverting-a-checkout-from-another-workspace">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F05%2F06%2Freverting-a-checkout-from-another-workspace&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=TFS" height="61" width="50" />
			</a>
		</div><p>Every now and again, we have issues where a developer will have their laptop rebuilt, and forget they have files checked out in Team Foundation Server (TFS).  This isn&#8217;t very helpful as sometimes they cannot undo their check outs.  Visual Studio doesn&#8217;t give you access to undo a checkout in another workspace if it&#8217;s not your workspace, however the TF.exe command does.  Here&#8217;s how:</p>

<div class="codecolorer-container dos default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">tf /undo /workspace:workspacename;username $/project/path/to/file</div></div>

<p>This will happily undo the change on that particular file.  If you have a whole directory to revert the changes on, that&#8217;s easy too&#8230;</p>

<div class="codecolorer-container dos default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">tf /undo /workspace:workspacename;username /recursive $/project/path/to/directory</div></div>

<p>You must remember when reverting somebody else&#8217;s change to use the project <acronym title="Uniform Resource Locator">URL</acronym>, not the physical path on your local machine, otherwise you&#8217;ll get an error like this:</p>

<div class="codecolorer-container dos default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">No pending changes were found <a href="http://www.ss64.com/nt/for.html"><span style="color: #00b100; font-weight: bold;">for</span></a> &lt;localpathname&gt;\file.aspx</div></div>

<p></p>

<p>For more details on the tf.exe undo command, see the Microsoft documentation <a href="http://msdn.microsoft.com/en-us/library/c72skhw4(VS.80).aspx" title="Microsoft; TF Undo command">here</a>.  Full details on arguments for the tf.exe command can be found <a href="http://msdn.microsoft.com/en-us/library/z51z7zy0(v=VS.80).aspx" title="Microsoft; TF Command">here</a> too.</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/05/06/reverting-a-checkout-from-another-workspace/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell: Top x Processes using CPU</title>
		<link>http://jon.netdork.net/2010/04/06/powershell-top-x-processes-using-cpu?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-top-x-processes-using-cpu</link>
		<comments>http://jon.netdork.net/2010/04/06/powershell-top-x-processes-using-cpu#comments</comments>
		<pubDate>Wed, 07 Apr 2010 01:31:38 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[Monitoring]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=733</guid>
		<description><![CDATA[This is a quick and handy one for server monitoring, and tracking down that process that is using all your CPU. It makes use of WMI counters. Get-WmiObject Win32_PerfFormattedData_PerfProc_Process &#124; ` &#160; where-object&#123; $_.Name -ne &#34;_Total&#34; -and $_.Name -ne &#34;Idle&#34;&#125; &#124; ` &#160; Sort-Object PercentProcessorTime -Descending &#124; ` &#160; select -First 5 &#124; ` &#160; [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F04%2F06%2Fpowershell-top-x-processes-using-cpu">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F04%2F06%2Fpowershell-top-x-processes-using-cpu&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=CPU,Monitoring,PowerShell" height="61" width="50" />
			</a>
		</div><p>This is a quick and handy one for server monitoring, and tracking down that process that is using all your CPU.  It makes use of <acronym title="Windows Management Instrumentation">WMI</acronym> counters.</p>

<p><span id="more-733"></span></p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> Win32_PerfFormattedData_PerfProc_Process <span style="color: pink;">|</span> `<br />
&nbsp; <span style="color: #008080; font-weight: bold;">where-object</span><span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Name <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;_Total&quot;</span> <span style="color: #FF0000;">-and</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Name <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;Idle&quot;</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> `<br />
&nbsp; <span style="color: #008080; font-weight: bold;">Sort-Object</span> PercentProcessorTime <span style="color: #008080; font-style: italic;">-Descending</span> <span style="color: pink;">|</span> `<br />
&nbsp; <span style="color: #008080; font-weight: bold;">select</span> <span style="color: #008080; font-style: italic;">-First</span> <span style="color: #804000;">5</span> <span style="color: pink;">|</span> `<br />
&nbsp; <span style="color: #008080; font-weight: bold;">Format-Table</span> Name<span style="color: pink;">,</span>IDProcess<span style="color: pink;">,</span>PercentProcessorTime <span style="color: #008080; font-style: italic;">-AutoSize</span></div></div>

<p>Okay, this one is a mouthful of pipes, and formatting to make it easier to see.  But the breakdown is pretty easy&#8230;</p>

<ul>
<li>Get the process information</li>
<li>Exclude _Total and Idle</li>
<li>Sort the output by descending processor usage</li>
<li>Only get the first 5 rows</li>
<li>Format the results into a table, with the columns Name, Process ID, and processor usage.</li>
</ul>

<p>Output looks something like this:</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Name &nbsp; &nbsp; &nbsp; IDProcess PercentProcessorTime<br />
<span style="color: pink;">----</span> &nbsp; &nbsp; &nbsp; <span style="color: pink;">---------</span> <span style="color: pink;">--------------------</span><br />
chrome<span style="color: #008000;">#2 &nbsp; &nbsp; &nbsp; &nbsp;3912 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 24</span><br />
System &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">4</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">12</span><br />
svchost<span style="color: #008000;">#12 &nbsp; &nbsp; &nbsp;4276 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0</span><br />
mobsync &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">5688</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #804000;">0</span><br />
wmpnetwk &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #804000;">3396</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #804000;">0</span></div></div>

<p>Another handy hint here, the back-tick is PowerShell&#8217;s way of allowing you to line-wrap.  This makes it a little easier to read, especially when giving it as samples like above.</p>

<p>I&#8217;ll be bundling parts of this for Nagios to return what processes are using the most processor when I get CPU alerts, allowing me to make quicker judgments on what I need to do to correct the issue.</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/04/06/powershell-top-x-processes-using-cpu/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	<!-- google ad injected by adsense-optimizer http://www.adsenseoptimizer.de -->
			<div  style="padding:7px; display: block; margin-left: auto; margin-right: auto; text-align: center;"><!-- Ad number: 1 --><script type="text/javascript"><!--
    	 
    	google_ad_client = "pub-5380792458095798"; google_alternate_color = "FFFFFF";
		google_ad_width = 468; google_ad_height = 60;
		google_ad_format = "468x60_as"; google_ad_type = "text";
		google_ad_channel =""; google_color_border = "CCCCCC";
		google_color_link = "2970A6"; google_color_bg = "F7F7F7";
		google_color_text = "555555"; google_color_url = "2970A6";
		google_ui_features = "rc:10"; //--></script>
		<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script></div>	<item>
		<title>PowerShell: Timing Commands</title>
		<link>http://jon.netdork.net/2010/04/06/powershell-timing-commands?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-timing-commands</link>
		<comments>http://jon.netdork.net/2010/04/06/powershell-timing-commands#comments</comments>
		<pubDate>Tue, 06 Apr 2010 15:07:12 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[General Ramblings]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=728</guid>
		<description><![CDATA[Curious about how long your script took to execute? How about just that cmdlet? Powershell has a built in function for you. Open Powershell command prompt Use the command Measure-Command like so: Measure-Command &#123;c:\scripts\yourscript.ps1&#125; Enjoy the output broken down by days, hours, minutes, seconds, milliseconds, and ticks. Days &#160; &#160; &#160; &#160; &#160; &#160; &#160;: [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F04%2F06%2Fpowershell-timing-commands">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F04%2F06%2Fpowershell-timing-commands&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly" height="61" width="50" />
			</a>
		</div><p>Curious about how long your script took to execute? How about just that cmdlet?  Powershell has a built in function for you.</p>

<ul>
<li>Open Powershell command prompt</li>
<li>Use the command <code>Measure-Command</code> like so:</li>
</ul>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">Measure-Command</span> <span style="color: #000000;">&#123;</span>c:\scripts\yourscript.ps1<span style="color: #000000;">&#125;</span></div></div>

<p>Enjoy the output broken down by days, hours, minutes, seconds, milliseconds, and ticks.</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Days &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">0</span><br />
Hours &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">0</span><br />
Minutes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">0</span><br />
Seconds &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">34</span><br />
Milliseconds &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">287</span><br />
Ticks &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">342873445</span><br />
TotalDays &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">0.000396844265046296</span><br />
TotalHours &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">0.00952426236111111</span><br />
TotalMinutes &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">0.571455741666667</span><br />
TotalSeconds &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">34.2873445</span><br />
TotalMilliseconds : <span style="color: #804000;">34287.3445</span></div></div>

<p>The same works for cmdlets too&#8230;</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">PS</span> C:\scripts<span style="color: pink;">&gt;</span> <span style="color: #008080; font-weight: bold;">Measure-Command</span> <span style="color: #000000;">&#123;</span><span style="color: #008080; font-weight: bold;">Get-Process</span><span style="color: #000000;">&#125;</span><br />
<br />
Days &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">0</span><br />
Hours &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">0</span><br />
Minutes &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">0</span><br />
Seconds &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">0</span><br />
Milliseconds &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">6</span><br />
Ticks &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #804000;">65919</span><br />
TotalDays &nbsp; &nbsp; &nbsp; &nbsp; : 7.62951388888889E<span style="color: pink;">-</span>08<br />
TotalHours &nbsp; &nbsp; &nbsp; &nbsp;: 1.83108333333333E<span style="color: pink;">-</span>06<br />
TotalMinutes &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">0.000109865</span><br />
TotalSeconds &nbsp; &nbsp; &nbsp;: <span style="color: #804000;">0.0065919</span><br />
TotalMilliseconds : <span style="color: #804000;">6.5919</span></div></div><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/04/06/powershell-timing-commands/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PowerShell: Cleaning up IIS Logs</title>
		<link>http://jon.netdork.net/2010/04/01/powershell-cleaning-up-iis-logs?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-cleaning-up-iis-logs</link>
		<comments>http://jon.netdork.net/2010/04/01/powershell-cleaning-up-iis-logs#comments</comments>
		<pubDate>Thu, 01 Apr 2010 14:44:22 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[IIS]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=720</guid>
		<description><![CDATA[This one is a quick and easy one. We have multiple IIS boxes, which each generate large usage logs on a daily basis. To save space, and for analytics off-server, we compress the log files. Having found Rar is one of the better compression algorithms, we simply shell out to rar, compress the logs, and [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F04%2F01%2Fpowershell-cleaning-up-iis-logs">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F04%2F01%2Fpowershell-cleaning-up-iis-logs&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=IIS,PowerShell" height="61" width="50" />
			</a>
		</div><p>This one is a quick and easy one.  We have multiple <acronym title="Internet Information Services">IIS</acronym> boxes, which each generate large usage logs on a daily basis.  To save space, and for analytics off-server, we compress the log files.  Having found <a href="http://www.rarlabs.com" title="RarLabs">Rar</a> is one of the better compression algorithms, we simply shell out to rar, compress the logs, and cleanup older logs.</p>

<p><span id="more-720"></span></p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$winrar</span> <span style="color: pink;">=</span> <span style="color: #800000;">'d:\program files\winrar\rar.exe'</span><br />
<br />
<span style="color: #800080;">$path</span> <span style="color: pink;">=</span> <a href="about:blank"><span style="color: #000080;">$args</span></a><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #008080; font-weight: bold;">Get-ChildItem</span> <span style="color: #800080;">$path</span> <span style="color: #008080; font-style: italic;">-recurse</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">where</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.Extension <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;log&quot;</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Foreach-Object</span> `<br />
<span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$log_name</span> <span style="color: pink;">=</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.FullName<br />
&nbsp; &nbsp; <span style="color: #800080;">$rar_name</span> <span style="color: pink;">=</span> <span style="color: #800080;">$log_name</span>.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.log&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;.rar&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <a href="about:blank"><span style="color: #000080;">$args</span></a> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;-ri1 m $rar_name $log_name&quot;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span>Diagnostics.Process<span style="color: #000000;">&#93;</span>::Start<span style="color: #000000;">&#40;</span><span style="color: #800080;">$winrar</span><span style="color: pink;">,</span> <a href="about:blank"><span style="color: #000080;">$args</span></a><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: pink;">-</span>s <span style="color: #804000;">5</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #800080;">$date</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span><br />
<span style="color: #800080;">$month</span> <span style="color: pink;">=</span> <span style="color: #800080;">$date</span>.Month<br />
<span style="color: #800080;">$year</span> <span style="color: pink;">=</span> <span style="color: #800080;">$date</span>.Year<br />
<br />
<span style="color: #800080;">$new_date</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span> <span style="color: #800000;">&quot;$month/01/$year&quot;</span><br />
<span style="color: #800080;">$log_date</span> <span style="color: pink;">=</span> <span style="color: #800080;">$new_date</span>.AddMonths<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #804000;">3</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008080; font-weight: bold;">Get-ChildItem</span> <span style="color: #800080;">$path</span> <span style="color: #008080; font-style: italic;">-recurse</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Extension <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;rar&quot;</span> <span style="color: #FF0000;">-and</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.LastWriteTime <span style="color: #FF0000;">-le</span> <span style="color: #800080;">$log_date</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #008080; font-weight: bold;">Remove-Item</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.FullName<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>

<p>This could probably do with some cleaning up as there are probably some slightly more efficient ways of doing some of this, but it works.</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/04/01/powershell-cleaning-up-iis-logs/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>PowerShell: Remote Registry, and fixing an Office 2007 install</title>
		<link>http://jon.netdork.net/2010/03/29/powershell-remote-registry-and-fixing-an-office-2007-install?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-remote-registry-and-fixing-an-office-2007-install</link>
		<comments>http://jon.netdork.net/2010/03/29/powershell-remote-registry-and-fixing-an-office-2007-install#comments</comments>
		<pubDate>Mon, 29 Mar 2010 16:10:33 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[KB928218]]></category>
		<category><![CDATA[Remote Registry]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=688</guid>
		<description><![CDATA[We&#8217;ve had a stubborn Windows 2003 server that we&#8217;ve been trying to get Office 2007 installed for a while. It has a couple of things wrong with it which have made the install substantially harder. The first being an MSI speed issue. Because the server plays host to about 120+ custom applications, all installed using [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F03%2F29%2Fpowershell-remote-registry-and-fixing-an-office-2007-install">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F03%2F29%2Fpowershell-remote-registry-and-fixing-an-office-2007-install&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=KB928218,Microsoft,PowerShell,Remote+Registry" height="61" width="50" />
			</a>
		</div><p>We&#8217;ve had a stubborn Windows 2003 server that we&#8217;ve been trying to get Office 2007 installed for a while.  It has a couple of things wrong with it which have made the install substantially harder.  </p>

<p><span id="more-688"></span></p>

<p>The first being an MSI speed issue.  Because the server plays host to about 120+ custom applications, all installed using MSI, any further MSI installs simply drag whilst it reads through all the keys, does its validation and backup checks, and then proceeds.</p>

<p>The second issue we have is that this box has a partially installed, corrupted Office 2007 install already on here.  Attempting to do &#8220;upgrades&#8221; fail, and uninstalling just barfs with a delightful error.  This resulted in some stumbling to figure out how to get it off, and start again.</p>

<p>Fortunately Microsoft do frequently document things like this, you just have to find the right search terms to find it, which luckily I did, in the form of <a href="http://support.microsoft.com/kb/928218/" title="Microsoft Support; KB928218; How to manually uninstall the 2007 Office system if you cannot uninstall it by using the 'Add or Remove Programs' feature">KB928218</a>.  This article gives you a list of the registry keys you have to go through and remove, and you should be all well and good.  Unfortunately, this list is over 200 registry keys on our count, and quite a list all over the place.  This is where Powershell comes in handy&#8230;</p>

<p>As the server itself doesn&#8217;t (yet) have Powershell installed, I ran the commands from my laptop, which required remote registry access.  Powershell makes use of the .Net libraries to do this:</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$server</span> <span style="color: pink;">=</span> <span style="color: #800000;">'MyRemoteServer'</span><br />
<span style="color: #800080;">$reg</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryKey<span style="color: #000000;">&#93;</span>::OpenRemoteBaseKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'LocalMachine'</span><span style="color: pink;">,</span> <span style="color: #800080;">$server</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>

<p>The <em>LocalMachine</em> reference here is the part of the registry we want to open, which is equivalent to HKEY_LOCAL_MACHINE.  This now gives us a registry object in the HKLM section of the registry.  From here, there are a bunch of functions we can use to fetch the keys we need.  The first is <em>OpenSubKey</em>.  This opens a subkey in the <em>$reg</em> object.</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>4<br />5<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800000;">&quot;Removing Office 12 Software Keys&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Office'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>

<p>This assigns <em>$regKey</em> to the subkey.  The boolean flag <em>$true</em> on the end is to make sure the key is opened in writable mode.  This will be required to modify the contents of the key.</p>

<p>Per the <acronym title="Kilobyte">KB</acronym> article, Microsoft say to delete all of the 12.0 subkey from under here.  I had originally used the following:</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>6<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$regKey</span>.DeleteSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'12.0'</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>

<p>This resulted in an error about not being allowed to delete subkeys.  Then I stumbled upon the much more suitable <em>DeleteSubKeyTree</em>, which, as the name hints, deletes the tree.  So the new code became:</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>6<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$regKey</span>.DeleteSubKeyTree<span style="color: #000000;">&#40;</span><span style="color: #800000;">'12.0'</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>

<p>This was repeated for the various other subkeys Microsoft recommended deleting.  It became more complex when it asks you to delete keys that match some of the characters below, and use a * as the match.  For example:</p>

<blockquote>
Note In the following registry keys, the asterisk character (*) represents one or more characters in the subkey name.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*0FF1CE*
</blockquote>

<p>Fortunately, Powershell is very good at string manipulation, and queries, so this was a bit of a case for a where, and foreach loop.</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>23<br />24<br />25<br />26<br />27<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*0FF1CE*&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #800080;">$regKey</span>.DeleteSubKeyTree<span style="color: #000000;">&#40;</span><a href="about:blank"><span style="color: #000080;">$_</span></a><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>

<p>It looks pretty messy, but it&#8217;s actually pretty easy if you understand pipes (the | character).  The above line 24 boils down to:</p>

<ul>
<li>Get the subkey names</li>
<li>Find only the ones that have 0FF1CE in them (yes I know that&#8217;s office with a zero and a one)</li>
<li>For each one that matches, go delete it, and its children</li>
</ul>

<p>See, not so hard.</p>

<p>There are some parts of this that venture <acronym title="Kilobyte">KB</acronym> into other areas of the registry, so the syntax changes in the opening command, for example:</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>67<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$reg</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryKey<span style="color: #000000;">&#93;</span>::OpenRemoteBaseKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'ClassesRoot'</span><span style="color: pink;">,</span> <span style="color: #800080;">$server</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>

<p>This opens HKEY_CLASSES_ROOT.  You can use CurrentUser to access HKEY_CURRENT_USER too.</p>

<p>That&#8217;s about it for remote registry access and fixing this blasted Office install.  As a side, the script saved me about 30 minutes of bashing through about 200+ registry keys for cleaning up.</p>

<p>Below is the full script, with the delete statements commented out.  If you have 2007 installed, give it a run, see what happens (<strong>please</strong> double check that all the deletes are in fact commented out, this script was used against a server to fix an install issue, and did have active delete statements in, and I cannot remember if I got all the deletes).</p>

<div class="codecolorer-container powershell default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br />93<br />94<br />95<br />96<br />97<br />98<br />99<br />100<br />101<br />102<br />103<br />104<br />105<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$server</span> <span style="color: pink;">=</span> <span style="color: #800000;">'MyRemoteServer'</span><br />
<span style="color: #800080;">$reg</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryKey<span style="color: #000000;">&#93;</span>::OpenRemoteBaseKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;LocalMachine&quot;</span><span style="color: pink;">,</span> <span style="color: #800080;">$server</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing Office 12 Software Keys&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Office\'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008000;">#$regKey.DeleteSubKeyTree('12.0')</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing 2003 shadow keys&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Office'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008000;">#$regKey.DeleteSubKeyTree('12.0')</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing office download references&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Office\Delivery\SourceEngine\Downloads'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span><span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*0FF1CE*&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_);</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing Office Uninstall keys&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*0FF1CE*&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_)</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing Office upgrade keys&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UpgradeCodes'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*F01FEC&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_)</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing Office product key references&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*F01FEC&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_)</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing Office services&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SYSTEM\CurrentControlSet\Services'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008000;">#$regKey.DeleteSubKeyTree('ose')</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800000;">&quot;Removing Uninstall keys&quot;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span><span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800080;">$subName</span> <span style="color: pink;">=</span> <a href="about:blank"><span style="color: #000080;">$_</span></a><br />
&nbsp; <span style="color: #800080;">$subKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$regKey</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800080;">$subName</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #800080;">$value</span> <span style="color: pink;">=</span> <span style="color: #800080;">$subKey</span>.GetValue<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;UninstallString&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$value</span> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*Office Setup Controller\Setup.*&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800000;">&quot;Deleting Uninstall key $subName&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($subName)</span><br />
&nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; <span style="color: #800080;">$subKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800080;">$reg</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800080;">$reg</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryKey<span style="color: #000000;">&#93;</span>::OpenRemoteBaseKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'ClassesRoot'</span><span style="color: pink;">,</span> <span style="color: #800080;">$server</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Installer\Features'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*F01FEC&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_)</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Installer\Products'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*F01FEC&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_)</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Installer\UpgradeCodes'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*F01FEC&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_)</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Installer\Win32Assemblies'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;*Office12*&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800000;">&quot;Deleting subkey $_&quot;</span><br />
&nbsp; <span style="color: #008000;">#$regKey.DeleteSubKeyTree($_)</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$reg</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<br />
<span style="color: #800000;">&quot;Deleting UserInfo&quot;</span><br />
<span style="color: #800080;">$reg</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryKey<span style="color: #000000;">&#93;</span>::OpenRemoteBaseKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'CurrentUser'</span><span style="color: pink;">,</span> <span style="color: #800080;">$server</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$regKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$reg</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Software\Microsoft\Office\Common'</span><span style="color: pink;">,</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #008000;">#$regKey.DeleteSubKeyTree('UserInfo')</span><br />
<span style="color: #800080;">$regKey</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #800080;">$reg</span>.Close<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/03/29/powershell-remote-registry-and-fixing-an-office-2007-install/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An error occurred while validating. HRESULT=80004005</title>
		<link>http://jon.netdork.net/2010/03/12/an-error-occurred-while-validating-hresult80004005?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=an-error-occurred-while-validating-hresult80004005</link>
		<comments>http://jon.netdork.net/2010/03/12/an-error-occurred-while-validating-hresult80004005#comments</comments>
		<pubDate>Fri, 12 Mar 2010 18:26:47 +0000</pubDate>
		<dc:creator>Jonathan Angliss</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://jon.netdork.net/?p=649</guid>
		<description><![CDATA[For the last day or so, we&#8217;ve been working on rolling out the next release of our code to our QA environment. When it came time to build a new set of solutions I stumbled across a weird validation error. An error occurred while validating. &#160;HRESULT=80004005 This error popped up on the setup applications for [...]]]></description>
			<content:encoded><![CDATA[<!-- google_ad_section_start --><div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F03%2F12%2Fan-error-occurred-while-validating-hresult80004005">
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fjon.netdork.net%2F2010%2F03%2F12%2Fan-error-occurred-while-validating-hresult80004005&amp;source=j_angliss&amp;style=normal&amp;service=bit.ly&amp;hashtags=Work" height="61" width="50" />
			</a>
		</div><p>For the last day or so, we&#8217;ve been working on rolling out the next release of our code to our QA environment.  When it came time to build a new set of solutions I stumbled across a weird validation error.</p>

<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">An error occurred while validating. &nbsp;HRESULT=80004005</div></div>

<p><a href="http://jon.netdork.net/wp-content/uploads/2010/03/broken_comment.png"><img src="http://jon.netdork.net/wp-content/uploads/2010/03/broken_comment-150x150.png" alt="" title="broken_comment" width="150" height="150" class="alignright size-thumbnail wp-image-651" /></a> This error popped up on the setup applications for several new programs. Doing some searching I stumbled across a couple of posts that hinted on removing the project output from the setup, and trying again.  This stopped the errors on the setup application, but not the actual application itself.</p>

<p>Then I saw a hint in the errors list&#8230;</p>

<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Application Configuration file &quot;App.config&quot; is invalid. '-' is an unexpected token.</div></div>

<p>Checking into the app.config file, I stumbled across the cause.  It looks like somebody had pasted code that had been &#8220;fixed&#8221; up by Outlook, or word, and broken a comment.  Fixing this, resolved both the app compilation, and the setup validation error.</p><!-- google_ad_section_end -->]]></content:encoded>
			<wfw:commentRss>http://jon.netdork.net/2010/03/12/an-error-occurred-while-validating-hresult80004005/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
