<?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>Elegant Code &#187; Alex Mueller</title>
	<atom:link href="http://elegantcode.com/author/mueller/feed/" rel="self" type="application/rss+xml" />
	<link>http://elegantcode.com</link>
	<description></description>
	<lastBuildDate>Tue, 20 Jul 2010 12:52:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Split Personality of the Tester/Developer</title>
		<link>http://elegantcode.com/2009/06/30/the-split-personality-of-the-testerdeveloper/</link>
		<comments>http://elegantcode.com/2009/06/30/the-split-personality-of-the-testerdeveloper/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 03:39:27 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Esoterica]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/06/30/the-split-personality-of-the-testerdeveloper/</guid>
		<description><![CDATA[From the site, http://www.softwareqatest.com/qatfaq2.html, I came across this statement. There are many forms of software testing. What I am discussing herein is related to white-box testing, automation and framework development, performance, and security testing
What makes a good Software Test engineer? 

“A good test engineer has a &#8216;test to break&#8217; attitude, an ability to take the [...]]]></description>
			<content:encoded><![CDATA[<p>From the site, <a href="http://www.softwareqatest.com/qatfaq2.html">http://www.softwareqatest.com/qatfaq2.html</a>, I came across this statement. There are many forms of software testing. What I am discussing herein is related to white-box testing, automation and framework development, performance, and security testing</p>
<blockquote><p>What makes a good Software Test engineer? </p>
</blockquote>
<blockquote><p>“A good test engineer has a &#8216;test to break&#8217; attitude, an ability to take the point of view of the customer, a strong desire for quality, and an attention to detail. Tact and diplomacy are useful in maintaining a cooperative relationship with developers, and an ability to communicate with both technical (developers) and non-technical (customers, management) people is useful. <strong><em>Previous software development experience can be helpful as it provides a deeper understanding of the software development process, gives the tester an appreciation for the developers&#8217; point of view, and reduce the learning curve in automated test tool programming.</em></strong> Judgment skills are needed to assess high-risk or critical areas of an application on which to focus testing efforts when time is limited.”</p>
</blockquote>
<p>In my opinion, more emphasis should be placed on the statement italicized above. Taking it a step further, I would say a developer with previous development knowledge of the product under test is even more valuable. Obviously domain knowledge is what increases this value. From previous experiences with organizations, the development skills of the tester are often largely ignored. </p>
<p>“Writing code? That’s what our developers do, not our testers.”</p>
<p>If we are not placing a greater emphasis on the development skills of the tester, we are missing opportunities to fully test the product. Testers with a development background are more familiar with the developer&#8217;s perspective. They know the tricks developers do when writing code, they know their shortcuts and tendencies. These testers can also provide developers with insight into defensive coding, adding hooks to make automation easier, securing the product from attacks, ect. </p>
<p>I would argue the inverse is true as well, that having previous testing experience of the product would add value to the transition of a tester into development. A developer with a testing background should improve the testability and security of the product, because they, too, understand the importance and impact of test.</p>
<p>To me, test and development should be shared responsibilities. If a developer is out sick, on vacation, or the team needs a resource, a tester should be able to fill in, developing product code. If a tester is needed for similar reasons, a developer should be able to switch gears and fulfill that need as well. Neither should be more exciting nor glamorous. The organization should respect both disciplines equally. Testing is the last line of defense.&#160; </p>
<p>The software engineer should have two personae, constructive and destructive. Perhaps this is similar to Dr. Jekyll and Mr. Hyde, where we replace the “evil” in Mr. Hyde with “destructive product testing.” </p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/06/30/the-split-personality-of-the-testerdeveloper/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cross Site Scripting (XSS)</title>
		<link>http://elegantcode.com/2009/05/28/cross-site-scripting-xss/</link>
		<comments>http://elegantcode.com/2009/05/28/cross-site-scripting-xss/#comments</comments>
		<pubDate>Thu, 28 May 2009 21:43:32 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools and Utilities]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/05/28/cross-site-scripting-xss/</guid>
		<description><![CDATA[Think your web applications are safe from cross site scripting? Maybe, maybe not. Why take a chance? 
I recently put together some notes for a presentation on cross site scripting, or XSS for short. I have decided to share some of the information, because I believe keeping a few thoughts in mind as we develop [...]]]></description>
			<content:encoded><![CDATA[<p>Think your web applications are safe from cross site scripting? Maybe, maybe not. Why take a chance? </p>
<p>I recently put together some notes for a presentation on cross site scripting, or XSS for short. I have decided to share some of the information, because I believe keeping a few thoughts in mind as we develop and test will go a long way when it comes to preventing attacks.</p>
<p><strong></strong></p>
<p><strong>Cross Site Scripting – What is it?</strong></p>
<p>Cross site scripting occurs when a web application gathers malicious data entered from a user, with or without negative intent. XSS can be achieved by exploiting locations in source code where users are able to input data, and the proper preventative measures have not been implemented to format and validate the inputted data. In other situations, session cookies and other sensitive data can be accessed by injecting malicious data and ultimately hijacking or impersonating a user’s account.</p>
<p>There are three main types of XSS according to Wikipedia, so I won’t bother rephrasing. Visit <a href="http://en.wikipedia.org/wiki/Cross-site_scripting">http://en.wikipedia.org/wiki/Cross-site_scripting</a> for more information. </p>
<p>The most common technologies and languages used for XSS are JavaScript, VBScript, ActiveX, HTML, or Flash’s ActionScript. Not only do we need to protect our server code, but we need to think about our client code as well.</p>
<p><strong></strong></p>
<p><strong>Prevention of Cross Site Scripting</strong></p>
<p>The vast of majority of XSS attacks can be prevented by identifying the user input locations within the web application and ensuring the source code handling these has proper measures in place. From a developer’s perspective, this means ensuring all data inputted from a user is properly encoded to remove HTML and script markup to be replaced with text that all browsers can process. </p>
<p>A simple example in C# is to use the HttpServerUtility.HtmlEncode method to convert all HTML markup characters into their text equivalent. For example, if a user were to supply the input for a textbox with the following, “This is my &lt;b&gt;bolded text&lt;/b&gt;.” The end result of the HtmlEncode method would result in the following, “This is my lt;bolded textgt;.” This is important because it removes HTML markup, which could be malicious. For example, “This is my text. &lt;script&gt;alert(‘This is an attack’);&lt;/script&gt;.” This example is passing a JavaScript alert to open a modal popup on the screen to display to the user. </p>
<p>In addition to HTML inputted data encoded on the server, encoding data on the client can be equally important. JavaScript HTML elements can have two attributes, InnerHTML and InnerText. InnerText will render text, not HTML, so it is the safe option. InnerHTML can be used to inject an XSS attack because it can render user inputted HTML, including script. Ensure InnerHTML has the necessary string formatting to protect against this vulnerability. </p>
<p>Cookies are another vulnerability to XSS attacks. If any part of the website issues cookies and an XSS access point is discovered, it is now possible to steal cookies and private information from the application’s users. If the cookie can be accessed, so can the information with it. Users can be impersonated, and site credibility will be lost. </p>
<p>Encrypted web sites (SSL, HTTPS) are at risk just like their public counterparts. SSL sites appear to be protected, but it is possible to execute the same XSS attacks, they just happen over an encrypted connection. </p>
<p>To protect our web applications, we need to be aware of the XSS vulnerabilities common to attackers and place defensive measures to ensure user confidentiality and confidence. Without becoming an expert on XSS and security, it is possible to develop safe, reliable applications by understanding XSS and the vulnerabilities exposed by our applications. </p>
<p><strong></strong></p>
<p><strong>What to Look for in Source Code</strong></p>
<p>Execute a simple search in source code looking for certain keywords is a good starting point. Many of the XSS bugs I have seen reported could have been prevented with the simple measures. Ensure HTML input is properly encoded on the server using HtmlEncode. Ensure HTML input is properly formatted on the client using string.Format and InnerText. </p>
<p>In source code and wherever, look for the following vulnerabilities. </p>
<ul>
<li>InnerHTML
<ul>
<li>InnerText is not supported by all browsers but the two can be found together. Look for where the strings are originating and if they are properly formatted/encoded. </li>
</ul>
</li>
<li>SetInnerText() </li>
<li>JavaScript’s Eval()
<ul>
<li>Don’t be Eval &#8211; <a href="http://24ways.org/2005/dont-be-eval">http://24ways.org/2005/dont-be-eval</a> </li>
</ul>
</li>
<li>Assigning of strings to page titles, control titles, ect.
<ul>
<li>Sometimes we take request object data and immediately process it and render it on the client. </li>
<li>Check the URL parameters passed in. </li>
</ul>
</li>
<li>The Request object
<ul>
<li>Request.Params </li>
<li>Request.Forms </li>
<li>Request.QueryString </li>
</ul>
</li>
<li>Using HtmlTextWriter or any variation
<ul>
<li>RenderBeginTag() </li>
<li>AddAttribute() </li>
<li>RenderEndTag() </li>
<li>HtmlWriter.Write() </li>
</ul>
</li>
<li>Cookies
<ul>
<li>Where are we using them and how are we handling them </li>
</ul>
</li>
</ul>
<p>Searching for these keywords within source will be a decent starting point for discovering XSS vulnerabilities</p>
<p><strong></strong></p>
<p><strong>Microsoft Anti-Cross Site Scripting Library V3.0 Beta</strong></p>
<p>Feel free to use a Microsoft API designed for XSS prevention within your code.</p>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;displaylang=en">http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&amp;displaylang=en</a></p>
<p>&#160;</p>
<p><strong>Closing Notes – because this topic can go on forever</strong></p>
<p>There are tools to help assess if your site is vulnerable. Search for them online. Whether or not you think you need third party APIs to help you write defensive code is entirely up to you. You can always write the code yourself.</p>
<p>Cross-site scripting (XSS) can be damaging to a company’s credibility and can cause myriad undesirable effects for individual users. XSS is preventable. Familiarizing oneself with the smells of XSS is a valuable tool to posses as a developer and a tester. At a minimum, educate your developers and testers on the target hot-spots mentioned within this post. </p>
<p>&#160;</p>
<p><strong>References and Resources</strong></p>
<p><a href="http://en.wikipedia.org/wiki/Cross-site_scripting">http://en.wikipedia.org/wiki/Cross-site_scripting</a></p>
<p><a href="http://www.cgisecurity.com/xss-faq.html">http://www.cgisecurity.com/xss-faq.html</a></p>
<p><a href="http://ha.ckers.org/xss.html">http://ha.ckers.org/xss.html</a></p>
<p><a href="http://www.owasp.org/index.php/Cross_site_scripting">http://www.owasp.org/index.php/Cross_site_scripting</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/05/28/cross-site-scripting-xss/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating files with FSUTIL</title>
		<link>http://elegantcode.com/2009/04/30/creating-files-with-fsutil/</link>
		<comments>http://elegantcode.com/2009/04/30/creating-files-with-fsutil/#comments</comments>
		<pubDate>Fri, 01 May 2009 00:31:01 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tools and Utilities]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/04/30/creating-files-with-fsutil/</guid>
		<description><![CDATA[While investigating the file size limitations of Live Mesh, I came across this utility as a means of quickly creating files of specified sizes. FSUTIL is an administrative tool that can be used for managing files, mounting and dismounting volumes, and other file and disk related tasks on Windows XP and later.
To create a new [...]]]></description>
			<content:encoded><![CDATA[<p>While investigating the file size limitations of <a title="Live Mesh" href="http://www.livemesh.com" target="_blank">Live Mesh</a>, I came across this utility as a means of quickly creating files of specified sizes. FSUTIL is an administrative tool that can be used for managing files, mounting and dismounting volumes, and other file and disk related tasks on Windows XP and later.</p>
<p>To create a new file that is 100 MB, we have this command.</p>
<p><a href="http://elegantcode.com/wp-content/uploads/2009/04/image4.png"><img style="display: inline" title="image" alt="image" src="http://elegantcode.com/wp-content/uploads/2009/04/image-thumb4.png" width="463" height="40" /></a> </p>
<p>A quick and easy way to generate files of various sizes. </p>
<p>Back to my original investigation, <a title="Live Mesh" href="http://www.livemesh.com" target="_blank">Live Mesh</a>, while it says it supports files of up to 2 GB, the actual uploading of movies (avi, wmv, mpg) greater than 50 MB appear to timeout. I was hoping to share video with family and friends. Hopefully there will be a resolution in the near future.</p>
<p>Read more on FSUTIL.</p>
<p><a title="FSUTIL.exe (Win XP/2003 server)" href="http://www.ss64.com/nt/fsutil.html" target="_blank">FSUTIL.exe (Win XP/2003 server)</a></p>
<p><a href="http://technet.microsoft.com/en-us/library/cc753059.aspx" target="_blank">FSUTIL on TechNet</a></p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/04/30/creating-files-with-fsutil/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell Management Library for Hyper-V</title>
		<link>http://elegantcode.com/2009/03/25/powershell-management-library-for-hyper-v/</link>
		<comments>http://elegantcode.com/2009/03/25/powershell-management-library-for-hyper-v/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 21:46:16 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Hyper-V]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Tools and Utilities]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/03/25/powershell-management-library-for-hyper-v/</guid>
		<description><![CDATA[I am always looking for tools to allow me to do more by doing less. Administering Hyper-V with PowerShell can be tedious. James O’Neill’s PowerShell Management Library for Hyper-V is a great tool to improve automation of Hyper-V management using PowerShell.
As a tester, I am constantly creating new environments, installing our product, taking snapshots, ect. [...]]]></description>
			<content:encoded><![CDATA[<p>I am always looking for tools to allow me to do more by doing less. Administering Hyper-V with PowerShell can be tedious. James O’Neill’s <a href="http://pshyperv.codeplex.com/" target="_blank">PowerShell Management Library for Hyper-V</a> is a great tool to improve automation of Hyper-V management using PowerShell.</p>
<p>As a tester, I am constantly creating new environments, installing our product, taking snapshots, ect. Doing this by hand is a waste of time in my opinion. Doing this with a script makes life easier and frees up my time. </p>
<p>Typically, I prefer to create is to create one VM and to have other VMs inherit from that base image. My second VM (the first child to inherit from the base), I will install daily builds of our product. I will then create a third child, which I use a sandbox. I can easily delete it and recreate as needed without having to install our product over again. I have not consistently found success with using snapshots, so I prefer to use differencing disks. The examples below use differencing disks. </p>
<p>This first code block shows how I am using the PowerShell management library to simply the creation of a base VM. There is nothing magic about it. It’s pretty strait-forward. I create a VM, give it a name, set the CPU count, memory size, network adapters, hard drive, and DVD drive.</p>
<pre class="code"><span style="color: purple">$server </span><span style="color: red">= </span><span style="color: maroon">&quot;my-dev-server&quot;
</span><span style="color: purple">$vmName </span><span style="color: red">= </span><span style="color: maroon">&quot;TestParentVM&quot;
</span><span style="color: purple">$vmVirtualSwitch </span><span style="color: red">= </span><span style="color: maroon">&quot;My Virtual Network&quot;

</span><span style="color: green"># create a new virtual machine
</span><span style="color: purple">$vm </span><span style="color: red">= </span><span style="color: black">New-VM </span><span style="color: purple">$vmName </span><span style="color: black">-server </span><span style="color: purple">$server

</span><span style="color: green"># set cpu count
</span><span style="color: black">Set-VMCPUCount </span><span style="color: purple">$vm </span><span style="color: black">2 -server </span><span style="color: purple">$server

</span><span style="color: green"># set memory size
</span><span style="color: black">Set-VMMemory </span><span style="color: purple">$vm </span><span style="color: black">2 -memory 4GB -server </span><span style="color: purple">$server

</span><span style="color: green"># add a legacy network adapter
</span><span style="color: black">Add-VMNIC -vm </span><span style="color: purple">$vm </span><span style="color: black">-VirtualSwitch </span><span style="color: purple">$vmVirtualSwitch </span><span style="color: black">-legacy

</span><span style="color: green"># add a default VMBus (non-legacy) network adapter
</span><span style="color: black">Add-VMNIC -vm </span><span style="color: purple">$vm </span><span style="color: black">-VirtualSwitch </span><span style="color: purple">$vmVirtualSwitch

</span><span style="color: green"># add the hard drive to the VM
</span><span style="color: black">Add-VMNewHardDisk –vm </span><span style="color: purple">$vm </span><span style="color: black">-controllerID 0 -lun 0 -vhdpath </span><span style="color: maroon">&quot;$(get-VHDdefaultPath)\$vmName.vhd&quot; </span><span style="color: black">-size 20GB

</span><span style="color: green"># add the DVD with bootup ISO
</span><span style="color: black">Add-VMDRIVE –vm </span><span style="color: purple">$vm </span><span style="color: black">1 1 -server </span><span style="color: purple">$server </span><span style="color: black">-DVD 

</span><span style="color: #5f9ea0">Write-Host </span><span style="color: maroon">&quot;Operation complete.&quot;</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The next code block will create a differencing disk pointing to the parent created in the previous example. I create the usual, VM, CPU count, ect. What makes this a differencing disk is how the VHD is created by specifying the parent. I do some cleanup in this routine by deleting any previously created VMs or VHDs, and I loop through the creation a failure preventative. </p>
<pre class="code"><span style="color: purple">$server </span><span style="color: red">= </span><span style="color: maroon">&quot;my-dev-server&quot;
</span><span style="color: purple">$vmName </span><span style="color: red">= </span><span style="color: maroon">&quot;TestChildVM&quot;
</span><span style="color: purple">$vmParent </span><span style="color: red">= </span><span style="color: maroon">&quot;TestParentVM&quot;
</span><span style="color: purple">$vmVirtualSwitch </span><span style="color: red">= </span><span style="color: maroon">&quot;My Virtual Network&quot;

</span><span style="color: blue">#region </span><span style="color: black">functions - feel free to move to a separate file

</span><span style="color: blue">Function </span><span style="color: #5f9ea0">DeleteVhd
</span><span style="color: black">{
    </span><span style="color: blue">Param </span><span style="color: black">(</span><span style="color: purple">$pathToVhd</span><span style="color: black">)
    </span><span style="color: green"># delete the disk that was added if it exists
    </span><span style="color: blue">if </span><span style="color: black">(</span><span style="color: #5f9ea0">test-path -path </span><span style="color: purple">$pathToVhd</span><span style="color: black">)
    {
        </span><span style="color: #5f9ea0">Remove-Item -Path </span><span style="color: purple">$pathToVhd </span><span style="color: #5f9ea0">-Force
    </span><span style="color: black">}
}

</span><span style="color: blue">#endregion

</span><span style="color: green"># delete the VHD if it already exists
</span><span style="color: #5f9ea0">DeleteVhd </span><span style="color: maroon">&quot;$(get-VHDdefaultPath)\$vmName.vhd&quot;

</span><span style="color: green"># delete the VM if it already exists
</span><span style="color: black">Remove-VM -vm </span><span style="color: purple">$vmName </span><span style="color: black">-server </span><span style="color: purple">$server

</span><span style="color: green"># create a new virtual machine
</span><span style="color: purple">$vm </span><span style="color: red">= </span><span style="color: black">New-VM </span><span style="color: purple">$vmName </span><span style="color: black">-server </span><span style="color: purple">$server

</span><span style="color: green"># get the vm
</span><span style="color: purple">$vm </span><span style="color: red">= </span><span style="color: black">Get-VM </span><span style="color: purple">$vmName

</span><span style="color: green"># set cpu count
</span><span style="color: black">Set-VMCPUCount </span><span style="color: purple">$vm </span><span style="color: black">2 -server </span><span style="color: purple">$server

</span><span style="color: green"># set memory size
</span><span style="color: black">Set-VMMemory </span><span style="color: purple">$vm </span><span style="color: black">2 -memory 4GB -server </span><span style="color: purple">$server

</span><span style="color: green"># get VM Nics available
</span><span style="color: purple">$vmNics </span><span style="color: red">= </span><span style="color: black">Get-VMNic -server </span><span style="color: purple">$server </span><span style="color: black">-vmbus -legacy
</span><span style="color: purple">$vmNicSwitchList </span><span style="color: red">= </span><span style="color: #5f9ea0">New-Object </span><span style="color: maroon">System.Collections.ArrayList

</span><span style="color: green"># get VM Nic Switch available for each VM Nic and add it to our list
</span><span style="color: blue">foreach </span><span style="color: black">(</span><span style="color: purple">$vmNic </span><span style="color: blue">in </span><span style="color: purple">$vmNics</span><span style="color: black">)
{
    </span><span style="color: purple">$vmSwitchElementName </span><span style="color: red">= </span><span style="color: black">(Get-VMNicSwitch </span><span style="color: purple">$vmNic</span><span style="color: black">).ElementName
    </span><span style="color: blue">if </span><span style="color: black">(</span><span style="color: purple">$vmNicSwitchList</span><span style="color: black">.Contains(</span><span style="color: purple">$vmSwitchElementName</span><span style="color: black">) </span><span style="color: red">-ne </span><span style="color: blue">$true</span><span style="color: black">)
    {
        </span><span style="color: purple">$vmNicSwitchList</span><span style="color: black">.Add(</span><span style="color: purple">$vmSwitchElementName</span><span style="color: black">)
    }
}

</span><span style="color: green"># Use the first available VM Nic Switch - this assumes
# I do not create more than on per each environment.
</span><span style="color: blue">if </span><span style="color: black">(</span><span style="color: purple">$vmNicSwitchList</span><span style="color: black">.Count </span><span style="color: red">-gt </span><span style="color: black">0)
{
    </span><span style="color: purple">$vmVirtualSwitch </span><span style="color: red">= </span><span style="color: purple">$vmNicSwitchList</span><span style="color: black">[0]
}

</span><span style="color: green"># add a legacy network adapter
</span><span style="color: black">Add-VMNIC -vm </span><span style="color: purple">$vm </span><span style="color: black">-VirtualSwitch </span><span style="color: purple">$vmVirtualSwitch </span><span style="color: black">-legacy

</span><span style="color: green"># add a default VMBus (non-legacy) network adapter
</span><span style="color: black">Add-VMNIC -vm </span><span style="color: purple">$vm </span><span style="color: black">-VirtualSwitch </span><span style="color: purple">$vmVirtualSwitch

</span><span style="color: green"># add the hard drive to the VM
</span><span style="color: purple">$parent </span><span style="color: red">= </span><span style="color: maroon">&quot;$(get-VHDdefaultPath)\$vmParent.vhd&quot;
</span><span style="color: purple">$vhdPath </span><span style="color: red">= </span><span style="color: maroon">&quot;$(get-VHDdefaultPath)\$vmName.vhd&quot;
</span><span style="color: black">Add-VMNewHardDisk –vm </span><span style="color: purple">$vm </span><span style="color: black">-controllerID 0 -lun 0 -vhdpath </span><span style="color: purple">$vhdPath </span><span style="color: black">-parent </span><span style="color: purple">$parent

</span><span style="color: green"># get the VM to see if a disk is attached to it, if it is not, then it failed
</span><span style="color: purple">$disks </span><span style="color: red">= </span><span style="color: black">Get-VMDisk -vm </span><span style="color: purple">$vm
$count </span><span style="color: red">= </span><span style="color: black">1

</span><span style="color: green"># if the disk was not successfully added, try and add it again
</span><span style="color: blue">while </span><span style="color: black">(</span><span style="color: purple">$disks </span><span style="color: red">-eq </span><span style="color: purple">$null </span><span style="color: red">-and </span><span style="color: purple">$count </span><span style="color: red">-le </span><span style="color: black">5)
{
    </span><span style="color: #5f9ea0">Write-Host </span><span style="color: maroon">&quot;RETRY $count - The disk was not properly added. Attempting to retry.&quot;

    </span><span style="color: green"># delete the disk that was added
    </span><span style="color: #5f9ea0">DeleteVhd </span><span style="color: maroon">&quot;$(get-VHDdefaultPath)\$vmName.vhd&quot;

    </span><span style="color: black">Add-VMNewHardDisk –vm </span><span style="color: purple">$vm </span><span style="color: black">-controllerID 0 -lun 0 -vhdpath </span><span style="color: purple">$vhdPath </span><span style="color: black">-parent </span><span style="color: purple">$parent

    $disks </span><span style="color: red">= </span><span style="color: black">Get-VMDisk -vm </span><span style="color: purple">$vm
    $count</span><span style="color: red">++
</span><span style="color: black">}

</span><span style="color: blue">if </span><span style="color: black">(</span><span style="color: purple">$disks </span><span style="color: red">-eq </span><span style="color: purple">$null</span><span style="color: black">)
{
    </span><span style="color: #5f9ea0">Write-Host </span><span style="color: maroon">&quot;Operation failed to create this virtual machine. Contact an admin.&quot;
</span><span style="color: black">}
</span><span style="color: blue">else
</span><span style="color: black">{
    </span><span style="color: #5f9ea0">Write-Host </span><span style="color: maroon">&quot;Operation completed successfully. Attempting to start the VM.&quot;
    </span><span style="color: black">Start-VM -vm </span><span style="color: purple">$vm </span><span style="color: black">-wait
}</span></pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>I have found that the VM creation is not consistently successful on the first pass, so I have added the while loop. Since adding that, I have not had any issues.</p>
<p>I hope these help. They should be easy to change if you prefer snapshots versus differencing disks. Thanks to James O’Neill for creating this library. It makes administering Hyper-V much easier. It is available via <a title="CodePlex" href="http://www.codeplex.com/" target="_blank">CodePlex</a>, where the latest release, updates, and forum support can be found. </p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/03/25/powershell-management-library-for-hyper-v/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Windows 7</title>
		<link>http://elegantcode.com/2009/02/09/installing-windows-7/</link>
		<comments>http://elegantcode.com/2009/02/09/installing-windows-7/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 21:14:36 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/02/09/installing-windows-7/</guid>
		<description><![CDATA[The short story is this. If you are accessing Windows 7 from your MSDN subscriptions, save yourself time and frustration by installing the Windows 7 Beta, not the Windows 7 Beta Checked Build. See available downloads here.
This past weekend, I decided to upgrade my work laptop from Vista Enterprise to Windows 7 Ultimate Beta. I [...]]]></description>
			<content:encoded><![CDATA[<p>The short story is this. If you are accessing Windows 7 from your MSDN subscriptions, save yourself time and frustration by installing the Windows 7 Beta, not the Windows 7 Beta Checked Build. <a href="http://msdn.microsoft.com/en-us/subscriptions/cc137115.aspx" target="_blank">See available downloads here</a>.</p>
<p>This past weekend, I decided to upgrade my work laptop from Vista Enterprise to Windows 7 Ultimate Beta. I was unable to upgrade from Vista Enterprise to 7 Ultimate because that action is not supported. I then tried to upgrade from Enterprise to 7 Enterprise, but I was unable to upgrade from a staged build to a non-staged build. I decided to repave entirely, choosing Windows 7 Ultimate Beta, and I tried to do all of this on a Friday afternoon, two hours before leaving.</p>
<p>I installed Windows 7 Beta Checked Build (x86) &#8211; DVD (English), last updated on January 14, 2009,&#160; from my MSDN subscription. I did not install an internal build. Instead, I decided to go with what is publicly available via MSDN. </p>
<p>Why did I go with a <a href="http://msdn.microsoft.com/en-us/library/ms792442.aspx" target="_blank">Checked Build</a>? Because I failed to read the details describing it. What it cost me in time and frustration, I gain in valuable learning experiences. So it was not a total loss. I received a number of buggy issues with the checked build, mainly the inability for Windows Update to properly download all of my necessary updates, including my video drivers and smart card reader, where the latter enables me to remotely access my work domain. </p>
<p>I gave up and decided to download and install the Windows 7 Beta – DVD (English). Everything works great. I was able to get online, download all of my updates, and connect to my work domain. No issues found so far, and no annoying assertion error popups. </p>
<p>My favorite Windows 7 feature so far (non-UI related) is that PowerShell 2.0 is installed by default. PowerShell 2.0 provides more functionality for remoting, among other enhancements.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/02/09/installing-windows-7/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Linux in Hyper-V</title>
		<link>http://elegantcode.com/2009/02/05/installing-linux-in-hyper-v/</link>
		<comments>http://elegantcode.com/2009/02/05/installing-linux-in-hyper-v/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 23:42:09 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Esoterica]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/02/05/installing-linux-in-hyper-v/</guid>
		<description><![CDATA[I needed to run some exploratory testing of a web application using FireFox on a Linux OS. In my environment, using anything but a Window&#8217;s OS requires permission and several hoops through which to jump. I find myself using Hyper-V to avoid these issues, and because it is so easy.
There are so many versions of [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to run some exploratory testing of a web application using FireFox on a Linux OS. In my environment, using anything but a Window&#8217;s OS requires permission and several hoops through which to jump. I find myself using Hyper-V to avoid these issues, and because it is so easy.</p>
<p>There are so many versions of Linux, so which one should I choose? </p>
<p>I feel like a kid in a candy store when it comes to selecting one, or maybe two operating systems. I began with Ubuntu, essentially, picking up from the last chapter where I grew tired and put down the book that is Linux. Ubuntu worked well, or at least, it did not leave a bad taste in my mouth. Last time I installed Ubuntu, I was using Virtual PC 2004, and it worked successfully. </p>
<p>Installing Ubuntu 8.10 in Hyper-V was incredibly easy. A full installation required 3-4 screens of user interaction. After downloading the ISO image to my server, I fired it up in Hyper-V. First, select a language. Second, choose to try, install, check for defects, test memory, ect. I chose to &#8220;install&#8221; versus &#8220;try&#8221; a live version. Third, user input screen, answer some install configuration questions such as language, time zone, keyboard layout, disk space partition, and login information. Finally, after installing, I am prompted for my login and password. Total time was less than thirty minutes, and perhaps it could have been faster, but I was multitasking. After installing Ubuntu and configuring FireFox to work with my network, I was testing my web application. </p>
<p>Still in awe of how easy the installation was, I decided to try out other flavors of Linux. Like Microbrews, Linux distros seem to be a dime-a-dozen. I found some online articles to help me narrow down what distros other seems to like, and so I arrived at the following.</p>
<p>The distros I downloaded and installed (or tried to install) as a Hyper-V Virtual Machine.</p>
<ul>
<li><a title="Ubuntu 8.10" href="http://www.ubuntu.com/getubuntu/download" target="_blank">Ubuntu 8.10</a></li>
<li><a title="Fedora 10" href="http://fedoraproject.org/en/get-fedora" target="_blank">Fedora 10</a></li>
<li><a title="Linux Mint 6" href="http://www.linuxmint.com/download.php" target="_blank">Linux Mint 6</a></li>
<li><a title="Mandriva Linux One 2009 (Gnome and KDE)" href="http://www.mandriva.com/" target="_blank">Mandriva Linux One 2009 (Gnome and KDE)</a> &#8211; tried both</li>
<li><a title="Open SuSe 11.1 KDE" href="http://software.opensuse.org/" target="_blank">Open SuSe 11.1 KDE</a></li>
<li><a title="SimplyMepis 7.0" href="http://www.mepis.org/" target="_blank">SimplyMEPIS 7.0</a></li>
</ul>
<p>In Hyper-V, installing Fedora, Linux Mint, and Open Suse were strait-forward and successful on my first run, just like Ubuntu. I had trouble with Mandriva and SimplyMEPIS. Both of them would hang as they tried to load the ISO image, so I gave up. At this point, I have four working Linux VMs enabling me to test my web applications, so the incentive to get Mandriva and SimplyMEPIS working just is not there right now. I do believe Mandriva and SimplyMEPIS will work with Hyper-V. I must have some configurations incorrect. </p>
<p>One thing I thought was funny about SimplyMEPIS is their website poses a question as part of their advertising, &#8220;Why SimplyMEPIS?&#8221; They respond with, &#8220;SimplyMEPIS just works!&#8221; It is sad that to have to advertise that &#8220;it just works,&#8221; because to me, that implies the inverse was the rule rather than the exception with previous versions, or with the technology &#8211; in this case, Linux. </p>
<p>I have fought Linux installs in the past, getting my onboard sound card to work, locating other device drivers, and even upgrading browsers. When I see, &#8220;it simply works,&#8221; I am still skeptical. It is unfortunate in my case with Hyper-V, that SimplyMEPIS did not work within the time limits I cared to allow for each distro. I will give it and Mandriva a fair shake by trying other configurations to get them working.</p>
<p>From my experiences, virtual machines are a great place to start getting familiar with operating systems. Having access to Hyper-V certainly made this experience successful and enjoyable. VMware and Virtual PC are two other virtualization software applications I have used as well for similar situations. VMware&#8217;s support for Linux operation systems is great. I have been able to install Fedora Core and Ubuntu in Virtual PC, but not without swearing at my screen.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/02/05/installing-linux-in-hyper-v/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Internet Explorer 8 Release Candidate 1</title>
		<link>http://elegantcode.com/2009/01/27/internet-explorer-8-release-candidate-1/</link>
		<comments>http://elegantcode.com/2009/01/27/internet-explorer-8-release-candidate-1/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 16:42:04 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Esoterica]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2009/01/27/internet-explorer-8-release-candidate-1/</guid>
		<description><![CDATA[Just released today, IE 8 RC 1, install it here. 
Faster, easier, safer and more reliable. Check it out for yourself. 
Strait from the mouth of marketing.
Internet Explorer 8 RC1 is much faster than previous versions of Internet Explorer, so you’ll notice that difference right away.&#160; But you’ll also notice some cool new features that [...]]]></description>
			<content:encoded><![CDATA[<p>Just released today, IE 8 RC 1, <a title="IE 8 RC 1" target="_blank" href="http://www.microsoft.com/ie">install it here</a>. </p>
<p>Faster, easier, safer and more reliable. Check it out for yourself. </p>
<p>Strait from the mouth of marketing.</p>
<blockquote><p>Internet Explorer 8 RC1 is much faster than previous versions of Internet Explorer, so you’ll notice that difference right away.&nbsp; But you’ll also notice some cool new features that will make your surfing experience faster and easier—not mention a whole lot safer.</p>
<ul>
<li>Highlight a street address in your Hotmail, Yahoo Mail, or other web mail account, right-click on the blue button that appears, and hover over “Map with Live Search.”&nbsp; Presto!&nbsp; You’ll see the map with the location right there—no more copying and pasting street addresses from web mail to a mapping site.&nbsp; Plus, you can choose what mapping service you want to use.
<li>Go to the search box in the top right, and type a search item—see how the enhanced Instant Search Box is more helpful, providing real-time search suggestions, including images, from your chosen search provider.
<li>Click on a new tab, and see the options that are presented there, including “InPrivate Browsing.”&nbsp; Click InPrivate Browsing and watch what happens—you are now in a browser session that is leaving no trail behind, so research gift suggestions for your significant other to your heart’s content without worrying about who might pick up the crumbs after you. </li>
</ul>
<p>Harder to see are the many security enhancements that will help keep you protected against the ever-evolving online threats—things like protection from cross-site scripting attacks that no other browser offers.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2009/01/27/internet-explorer-8-release-candidate-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PowerShell Documentation</title>
		<link>http://elegantcode.com/2008/12/17/powershell-documentation/</link>
		<comments>http://elegantcode.com/2008/12/17/powershell-documentation/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 20:36:54 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/12/17/powershell-documentation/</guid>
		<description><![CDATA[PowerShell documentation, you are too honest. 


Get-Help Remove-Item -Full


As I was retrieving information on &#8220;Remove-Item,&#8221; this is what I came across. There is more detail beyond what I am showing, but pay attention to what is bolded. 

NAME&#160;&#160;&#160; Remove-Item 
SYNOPSIS&#160;&#160;&#160; Deletes the specified items. 
SYNTAX&#160;&#160;&#160; Remove-Item [-path] &#60;string[]&#62; [-recurse] [-force] [-include &#60;string[]&#62;] [-&#160;&#160;&#160; exclude &#60;string[]&#62;] [...]]]></description>
			<content:encoded><![CDATA[<p>PowerShell documentation, you are too honest. </p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:2ed0ad7a-f3da-498d-a817-1bb0c8b8f8c3" class="wlWriterSmartContent">
<pre  style="width:100%;;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #000000;">Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Help Remove</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #000000;">-</span><span style="color: #000000;">Full</span></div>
</pre>
</div>
<p>As I was retrieving information on &#8220;Remove-Item,&#8221; this is what I came across. There is more detail beyond what I am showing, but pay attention to what is <strong>bolded</strong>. </p>
<blockquote>
<p>NAME<br />&nbsp;&nbsp;&nbsp; Remove-Item </p>
<p>SYNOPSIS<br />&nbsp;&nbsp;&nbsp; Deletes the specified items. </p>
<p>SYNTAX<br />&nbsp;&nbsp;&nbsp; Remove-Item [-path] &lt;string[]&gt; [-recurse] [-force] [-include &lt;string[]&gt;] [-<br />&nbsp;&nbsp;&nbsp; exclude &lt;string[]&gt;] [-filter &lt;string&gt;] [-credential &lt;PSCredential&gt;] [-whatI<br />&nbsp;&nbsp;&nbsp; f] [-confirm] [&lt;CommonParameters&gt;] </p>
<p>&nbsp;&nbsp;&nbsp; Remove-Item [-literalPath] &lt;string[]&gt; [-recurse] [-force] [-include &lt;string<br />&nbsp;&nbsp;&nbsp; []&gt;] [-exclude &lt;string[]&gt;] [-filter &lt;string&gt;] [-credential &lt;PSCredential&gt;]<br />&nbsp;&nbsp;&nbsp; [-whatIf] [-confirm] [&lt;CommonParameters&gt;] </p>
<p>DETAILED DESCRIPTION<br />&nbsp;&nbsp;&nbsp; The Remove-Item cmdlet deletes one or more items. Because it is supported b<br />&nbsp;&nbsp;&nbsp; y many providers, it can delete many different types of items, including fi<br />&nbsp;&nbsp;&nbsp; les, directories, registry keys, variables, aliases, certificates, and func<br />&nbsp;&nbsp;&nbsp; tions. </p>
<p>PARAMETERS<br />&nbsp;&nbsp;&nbsp; -path &lt;string[]&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Specifies a path to the items being removed. Wildcards are permitted. T<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; he parameter name (&#8220;-Path&#8221;) is optional. </p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Required?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; true<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Position?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Default value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; N/A &#8211; The path must be specified<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Accept pipeline input?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; true (ByValue, ByPropertyName)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Accept wildcard characters?&nbsp; true </p>
<p>&nbsp;&nbsp;&nbsp; -recurse &lt;SwitchParameter&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Deletes the items in the specified locations and in all child items of<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; the locations. </p>
<p><strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The Recurse parameter in this cmdlet does not work properly. </strong></p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Required?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; false<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Position?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; named<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Default value&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; False<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Accept pipeline input?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; false<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Accept wildcard characters?&nbsp; false </p>
<p><strong></strong>&nbsp;</p>
</blockquote>
<p>&#8220;Hmmm&#8230; Am I feeling lucky? Ahhh, what the hell, let&#8217;s do it.&#8221;</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:a3ee0edf-63f8-43fc-a4fb-22c6277656f8" class="wlWriterSmartContent">
<pre  style="width:100%;;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #000000;">Remove</span><span style="color: #000000;">-</span><span style="color: #000000;">Item </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">C:\</span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">Recurse</span></div>
</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/12/17/powershell-documentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automate Daily Tasks with PowerShell</title>
		<link>http://elegantcode.com/2008/12/08/automate-daily-tasks-with-powershell/</link>
		<comments>http://elegantcode.com/2008/12/08/automate-daily-tasks-with-powershell/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 04:32:07 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/12/08/automate-daily-tasks-with-powershell/</guid>
		<description><![CDATA[I consider myself to be a strong follower of the DRY principle. I practice it religiously. Lately, I have been applying DRY outside of my IDE, more specifically, with my build environments and daily developer tasks. 
For example, every night I clean my build environment, sync up the latest code, and rebuild all products within [...]]]></description>
			<content:encoded><![CDATA[<p>I consider myself to be a strong follower of the DRY principle. I practice it religiously. Lately, I have been applying DRY outside of my IDE, more specifically, with my build environments and daily developer tasks. </p>
<p>For example, every night I clean my build environment, sync up the latest code, and rebuild all products within my domain. The total time it takes to clean, sync, and build is over two hours, depending on hardware and connection speed. This has been reduced from over four hours. Now before I do all of this, I need to check my environment to ensure I have all the latest tools and versions of those tools, such as Visual Studio, SQL Server, windows updates, service packs, ect. This is just part of our build environment. Typically, we run this check until we receive a positive response, &#8220;all is well.&#8221; </p>
<p>Rather than spend my time running these commands, I automate them, and run them around the clock using Task Scheduler, a BAT file, and PowerShell. </p>
<p>I create one scheduled task that runs once per hour, indefinitely. My scheduled task runs a BAT file that calls my PowerShell script. Within my PowerShell script, I create a Hashtable of commands to run and at which hour to run them. Each hour as the script is executed, I get the current hour and see if any tasks are available to run. For example, each night, sometime during the 2 AM hour, I start my full build. I realize that running once per hour limits the number of commands I can run, but for now, this imperfect solution meets my needs. </p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:a7988140-752b-4ce1-ad06-71236bd6eeab" class="wlWriterSmartContent">Nightly PowerShell Script &#8211; <a style="cursor:hand" onClick="javascript:window.clipboardData.setData('Text', document.getElementById('Code74dbce9c46474edb8d66c67510f3ce94').innerText); ">Copy Code</a>
<pre id="Code74dbce9c46474edb8d66c67510f3ce94" style="width:100%;;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #66758C;"> 1</span> <span style="color: #008000;">#</span><span style="color: #008000;"> Local variables</span><span style="color: #008000;">
</span><span style="color: #66758C;"> 2</span> <span style="color: #008000;"></span><span style="color: #800080;">$productRoot</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">c:\Projects\dev</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">
</span><span style="color: #66758C;"> 3</span> <span style="color: #000000;"></span><span style="color: #800080;">$currentHour</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> (Get</span><span style="color: #000000;">-</span><span style="color: #000000;">Date).Hour
</span><span style="color: #66758C;"> 4</span> <span style="color: #000000;"></span><span style="color: #800080;">$list</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Object System.Collections.Hashtable
</span><span style="color: #66758C;"> 5</span> <span style="color: #000000;">
</span><span style="color: #66758C;"> 6</span> <span style="color: #000000;"></span><span style="color: #008000;">#</span><span style="color: #008000;"> Define tasks to run each hour</span><span style="color: #008000;">
</span><span style="color: #66758C;"> 7</span> <span style="color: #008000;">#</span><span style="color: #008000;">     Hour 0 = 12:00-12:59 AM</span><span style="color: #008000;">
</span><span style="color: #66758C;"> 8</span> <span style="color: #008000;">#</span><span style="color: #008000;">     Hour 1 = 1:00-1:59 AM</span><span style="color: #008000;">
</span><span style="color: #66758C;"> 9</span> <span style="color: #008000;">#</span><span style="color: #008000;">     Hour 20 = 8:00-8:59 PM</span><span style="color: #008000;">
</span><span style="color: #66758C;">10</span> <span style="color: #008000;"></span><span style="color: #800080;">$list</span><span style="color: #000000;">.Add(</span><span style="color: #000000;">20</span><span style="color: #000000;">,</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">environmentCheck dev</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #66758C;">11</span> <span style="color: #000000;"></span><span style="color: #800080;">$list</span><span style="color: #000000;">.Add(</span><span style="color: #000000;">21</span><span style="color: #000000;">,</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">environmentCheck test</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #66758C;">12</span> <span style="color: #000000;"></span><span style="color: #800080;">$list</span><span style="color: #000000;">.Add(</span><span style="color: #000000;">22</span><span style="color: #000000;">,</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">environmentCheck system</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #66758C;">13</span> <span style="color: #000000;"></span><span style="color: #800080;">$list</span><span style="color: #000000;">.Add(</span><span style="color: #000000;">23</span><span style="color: #000000;">,</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">projects clean sync</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #66758C;">14</span> <span style="color: #000000;"></span><span style="color: #800080;">$list</span><span style="color: #000000;">.Add(</span><span style="color: #000000;">2</span><span style="color: #000000;">,</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">projects build full</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">);
</span><span style="color: #66758C;">15</span> <span style="color: #000000;">
</span><span style="color: #66758C;">16</span> <span style="color: #000000;"></span><span style="color: #008000;">#</span><span style="color: #008000;"> if a task is defined for this hour, execute it</span><span style="color: #008000;">
</span><span style="color: #66758C;">17</span> <span style="color: #008000;"></span><span style="color: #0000FF;">if</span><span style="color: #000000;">(</span><span style="color: #800080;">$list</span><span style="color: #000000;">.Contains(</span><span style="color: #800080;">$currentHour</span><span style="color: #000000;">))
</span><span style="color: #66758C;">18</span> <span style="color: #000000;">{
</span><span style="color: #66758C;">19</span> <span style="color: #000000;">    </span><span style="color: #008000;">#</span><span style="color: #008000;"> Get the command to execute for this hour</span><span style="color: #008000;">
</span><span style="color: #66758C;">20</span> <span style="color: #008000;"></span><span style="color: #000000;">    </span><span style="color: #800080;">$buildCommand</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$list</span><span style="color: #000000;">[</span><span style="color: #800080;">$currentHour</span><span style="color: #000000;">]
</span><span style="color: #66758C;">21</span> <span style="color: #000000;">
</span><span style="color: #66758C;">22</span> <span style="color: #000000;">    </span><span style="color: #008000;">#</span><span style="color: #008000;"> Set the project bat path</span><span style="color: #008000;">
</span><span style="color: #66758C;">23</span> <span style="color: #008000;"></span><span style="color: #000000;">    </span><span style="color: #800080;">$pathToBat</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$productRoot</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">\bin\project.bat</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">
</span><span style="color: #66758C;">24</span> <span style="color: #000000;">
</span><span style="color: #66758C;">25</span> <span style="color: #000000;">    </span><span style="color: #008000;">#</span><span style="color: #008000;"> Set the cmd.exe's arguments</span><span style="color: #008000;">
</span><span style="color: #66758C;">26</span> <span style="color: #008000;"></span><span style="color: #000000;">    </span><span style="color: #800080;">$arguments</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">/C cd /d </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$productRoot</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> &amp; </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$pathToBat</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;"> &amp; </span><span style="color: #800000;">&quot;</span><span style="color: #000000;"> </span><span style="color: #000000;">+</span><span style="color: #000000;"> </span><span style="color: #800080;">$buildCommand</span><span style="color: #000000;">
</span><span style="color: #66758C;">27</span> <span style="color: #000000;">
</span><span style="color: #66758C;">28</span> <span style="color: #000000;">    </span><span style="color: #008000;">#</span><span style="color: #008000;"> Start up the DOS prompt, execute the commands</span><span style="color: #008000;">
</span><span style="color: #66758C;">29</span> <span style="color: #008000;"></span><span style="color: #000000;">    </span><span style="color: #800080;">$process</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> New</span><span style="color: #000000;">-</span><span style="color: #000000;">Object </span><span style="color: #000000;">-</span><span style="color: #000000;">TypeName System.Diagnostics.</span><span style="color: #0000FF;">Process</span><span style="color: #000000;">
</span><span style="color: #66758C;">30</span> <span style="color: #000000;">    </span><span style="color: #800080;">$process</span><span style="color: #000000;">.StartInfo.FileName </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">cmd.exe</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">
</span><span style="color: #66758C;">31</span> <span style="color: #000000;">    </span><span style="color: #800080;">$process</span><span style="color: #000000;">.StartInfo.Arguments </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800080;">$arguments</span><span style="color: #000000;">
</span><span style="color: #66758C;">32</span> <span style="color: #000000;">    </span><span style="color: #800080;">$process</span><span style="color: #000000;">.StartInfo.UseShellExecute </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">$false</span><span style="color: #000000;">
</span><span style="color: #66758C;">33</span> <span style="color: #000000;">    </span><span style="color: #800080;">$process</span><span style="color: #000000;">.Start()
</span><span style="color: #66758C;">34</span> <span style="color: #000000;">    </span><span style="color: #800080;">$process</span><span style="color: #000000;">.WaitForExit()
</span><span style="color: #66758C;">35</span> <span style="color: #000000;">} </span></div>
</pre>
</div>
<p>Every morning, I expect to have fresh builds. My build system will email me with the results. However, adding email capabilities to the above script with PowerShell is doable. The above commands execute on my dev server, but executing them on remote servers is also doable, even with PowerShell 1.0 and something like the following.</p>
</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:F2210F5F-69EB-4d4c-AFF7-B8A050E9CC72:e732d6b0-bd96-4b2a-a419-f867afe918d1" class="wlWriterSmartContent">Execute Command Remotely &#8211; <a style="cursor:hand" onClick="javascript:window.clipboardData.setData('Text', document.getElementById('Code2b6dd067262345728f29e8941ad2454a').innerText); ">Copy Code</a>
<pre id="Code2b6dd067262345728f29e8941ad2454a" style="width:100%;;">
<div><!--

Code highlighting produced by Actipro CodeHighlighter (freeware)

http://www.CodeHighlighter.com/

--><span style="color: #999999;">1</span> <span style="color: #800080;">$toServer</span><span style="color: #000000;"> </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">&quot;</span><span style="color: #800000;">my-remote-server</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">
</span><span style="color: #999999;">2</span> <span style="color: #000000;">([WMICLASS]</span><span style="color: #800000;">&quot;</span><span style="color: #800000;">\\$toServer\ROOT\CIMV2:win32_process</span><span style="color: #800000;">&quot;</span><span style="color: #000000;">).Create(</span><span style="color: #800080;">$command</span><span style="color: #000000;">)</span></div>
</pre>
</div>
<p>If my environment is not current and my builds are not working, I can lose productivity during normal business hours. Using a simple scheduled task and PowerShell helps me administer my server and keeps me from repeating the same tedious steps on a daily basis.</p>
<p>How else does PowerShell help me adhere to DRY? It enables me to administer my Hyper-V machines, configure websites, GAC and un-GAC assemblies, and much more.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/12/08/automate-daily-tasks-with-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SketchPath XPath Editor</title>
		<link>http://elegantcode.com/2008/11/13/sketchpath-xpath-editor/</link>
		<comments>http://elegantcode.com/2008/11/13/sketchpath-xpath-editor/#comments</comments>
		<pubDate>Thu, 13 Nov 2008 17:29:04 +0000</pubDate>
		<dc:creator>Alex Mueller</dc:creator>
				<category><![CDATA[Esoterica]]></category>

		<guid isPermaLink="false">http://elegantcode.com/2008/11/13/sketchpath-xpath-editor/</guid>
		<description><![CDATA[This is by no means a comprehensive review of SketchPath, but I just wanted to say thanks Phil Fearon, for developing this app. 
I use XML/XPath/XSL less frequently today than with previous positions, but every now and then, when chiseling away at a slab of XML, having an XPath tool can make my life much [...]]]></description>
			<content:encoded><![CDATA[<p>This is by no means a comprehensive review of <a title="SketchPath" target="_blank" href="http://pgfearo.googlepages.com/">SketchPath</a>, but I just wanted to say thanks Phil Fearon, for developing this app. </p>
<p>I use XML/XPath/XSL less frequently today than with previous positions, but every now and then, when chiseling away at a slab of XML, having an XPath tool can make my life much easier. I always relied on <a title="Interactive XPath Expression Builder 4.0" target="_blank" href="http://www.pluralsight.com/community/blogs/aaron/pages/170.aspx">Interactive XPath Expression Builder 4.0</a>, but larger XML files hindered performance. In an effort to find a good XPath editor, I have installed several I have found on the web, used them, and uninstalled all of them. </p>
<p>Ideally, I am looking for a tool that is light and free. By light I mean, I am not looking to install a development studio, nor something that attempts to integrate with all of my existing applications, nor something that requires a reboot when installing or uninstalling, nor something that cannot fully uninstall itself. I plan on using this tool as often as I have to deal with XML/XPath/XSL these days, which is once every few months. Usually the time it takes me to find a tool, install it, author what I need, and uninstall it, I could have written the XPath by hand.</p>
<p>As I searched online for tools this time, I stumbled across <a title="SketchPath" target="_blank" href="http://pgfearo.googlepages.com/">SketchPath</a>. While hesitant to install another XML app to only end up in my graveyard of XML apps, I gave this one a try. It is free, so I figured, why not.</p>
<p>&#8220;YES! F-bomb YEAH!&#8221;</p>
<p>After installing, I loaded up my XML, clicked on an attribute within a node, and sure enough, the XPath needed to locate that element was displayed. It was that simple. After a few more node selections, I had the XPath I needed for my app. In and out like a robbery.</p>
<p>&#8220;<a title="SketchPath" target="_blank" href="http://pgfearo.googlepages.com/">SketchPath</a> is a free XPath Editor and XML analysis and testing tool supporting XPath 1.0 and XPath 2.0. It provides an integrated graphical environment for viewing XML files, developing and testing XPath expressions against them and managing the expressions in file libraries.&#8221;</p>
<p>Thanks Phil! This was exactly what I needed. I will not be uninstalling.</p>
]]></content:encoded>
			<wfw:commentRss>http://elegantcode.com/2008/11/13/sketchpath-xpath-editor/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
