<?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>inVURTED.com &#187; powershell</title>
	<atom:link href="http://invurted.com/tag/powershell/feed/" rel="self" type="application/rss+xml" />
	<link>http://invurted.com</link>
	<description>With great virtualisation comes great responsibility!</description>
	<lastBuildDate>Thu, 09 Feb 2012 03:50:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Vmware ESX3.5 Templates</title>
		<link>http://invurted.com/vmware-esx3-5-templates/</link>
		<comments>http://invurted.com/vmware-esx3-5-templates/#comments</comments>
		<pubDate>Mon, 28 Sep 2009 02:47:52 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[VMWare]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://invurted.com/?p=300</guid>
		<description><![CDATA[Templates and their usage are one of the big time savers in ESX. The ability to setup a &#8220;perfect&#8221; vritual machine and then deploy multiple copies of it allows us to minimise the risk of deployment errors. However, there are a few limits around what can be achieved. Specifically, in the environment I am in [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Templates and their usage are one of the big time savers in ESX. The ability to setup a &#8220;perfect&#8221; vritual machine and then deploy multiple copies of it allows us to minimise the risk of deployment errors. However, there are a few limits around what can be achieved.<span id="more-300"></span></p>
<p>Specifically, in the environment I am in at the moment, there is a requirement for the operating system to be deployed to one LUN and the any application partitons to be deployed to another LUN.</p>
<p>Templates only allow me to deploy the machine&#8217;s virtual hard disk to one LUN and not split across two. Hence the problem.</p>
<p>There is no quick fix that I could find; so it was off the scripting land I went.</p>
<p>First things first. The customer required the deployment of twenty seven virtual machines all based off one. The process is prety simple; open my Virtual Infrastructure Client, point it at a Virtual Center (ESX servers by themselves don&#8217;t have template functionality), and convert the baseline virtual machine to a template.</p>
<p>I could have chosen to deploy twenty seven virtual machines manually, but, well, I&#8217;m lazy. So, the lazy man&#8217;s solution? Scripting!</p>
<p>The process was as follows:</p>
<p>1) Remove the 40GB hard drive (cloning and templating doesn&#8217;t allow hard drives to be placed in multiple datastores eg. osLUN and appLUN)<br />
2) Create a template of the virtual machine.<br />
3) Install powershell and the Vmware VI Toolkit giving us the powershell for Vmware functionality.<br />
4) Save the following to a .ps1 (Powershell script file):</p>
<p>$array = &#8220;Machine1&#8243;,&#8221;Machine2&#8243;,&#8221;Machine3&#8243; (and so forth)<br />
$TARGET = &#8220;FQDN_OF_TARGET_ESX_SERVER&#8221;</p>
<p>Connect-viserver FQDN_OF_VIRTUAL_CENTER</p>
<p>foreach ($vm in $array)<br />
{<br />
$vm=New-VM -Name $vm -Template BASELINE_TEMPLATE -Host $TARGET -Datastore osLUN<br />
}</p>
<p>The above script will connect to the VI Center (it will prompt for username and password) and then create a new machine called &#8220;Machine1&#8243; etc. for each machine in the list. It will place the virtual machine on the esx server in $TARGET and build it from the template called BASELINE_TEMPLATE.</p>
<p>Now comes the hard part. There are 27 42GB drives that need to be created for the virtual machines. There is no powershell that will allow this to happen. Therefore, a script is required.</p>
<p>In appLUN is a vmdk called BASELINE_TEMPLATE_VMDK and this is the virtual hard drive (pre partitioned and formatted) that will be used for the virtual machines.</p>
<p>for DESTINATION in machine1 machine2 machine3 machine4 ETC.<br />
do<br />
        # Copy<br />
        echo &#8220;Copying $SOURCE to $DESTINATION&#8221;<br />
        mkdir $DESTINATION<br />
        cp -a $SOURCE/* $DESTINATION/<br />
        # Rename vmdk files<br />
        cd $DESTINATION<br />
        for file in $(ls -1 *.vmdk)<br />
        do<br />
                echo &#8220;Renaming $SOURCE vmdks to $DESTINATION&#8221;<br />
                DEST=$(echo $file | sed s/$SOURCE/$DESTINATION/g)<br />
                mv $file $DEST<br />
        done<br />
        # Edit .vmdk<br />
        for file in $(ls -1 *.vmdk | grep -v flat)<br />
        do<br />
                echo &#8220;Replacing references to $SOURCE in .vmdk file $file&#8221;<br />
                sed -i s/$SOURCE/$DESTINATION/g $file<br />
        done<br />
 cd ..<br />
done<br />
echo &#8220;Finished&#8221;</p>
<p>This will copy the BASELINE_TEMPLATE_VMDK virtual hard drive one time for each virtual machine and make sure it is useable for that machine. It will also go through the .vmdk file and change the reference from BASELINE_TEMPLATE_VMDK to the destination virtual machine name.</p>
<p>Once it is run, we have to manually add the newly created vmdk to the corresponding virtual machine.</p>
<p>Then it is a simple matter of logging into each virtual machine and changing their host names and IP addresses.</p>
<p>There is still a fair bit of manual intervention involved, but at least the boring, tedious bits (deploying the templates and copying the hard drives) has been automated.</p>
<p>If you can offer any other scripts that can complete the picture, let me know!</p>
<div class="shr-publisher-300"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Finvurted.com%2Fvmware-esx3-5-templates%2F' data-shr_title='Vmware+ESX3.5+Templates'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Finvurted.com%2Fvmware-esx3-5-templates%2F'></a><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Finvurted.com%2Fvmware-esx3-5-templates%2F' data-shr_title='Vmware+ESX3.5+Templates'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://invurted.com/vmware-esx3-5-templates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[TUTORIAL] Migrating Virtual Machines without Vmotion</title>
		<link>http://invurted.com/migrating-virtual-machines-without-vmotion/</link>
		<comments>http://invurted.com/migrating-virtual-machines-without-vmotion/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 06:50:03 +0000</pubDate>
		<dc:creator>Adam</dc:creator>
				<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[VMWare]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[vmotion]]></category>

		<guid isPermaLink="false">http://invurted.com/?p=103</guid>
		<description><![CDATA[Guys are hard at work with the labs at the moment here in sunny Hobart, and so I begin trawling the blogs (as is my want). I discovered this brilliant little gem from Mike DiPetrill&#8217;s blog. This post demonstates the awesome power of the Vmware API and the ease of use we get from the [...]]]></description>
			<content:encoded><![CDATA[<!-- Start Shareaholic LikeButtonSetTop Automatic --><!-- End Shareaholic LikeButtonSetTop Automatic --><p>Guys are hard at work with the labs at the moment here in sunny Hobart, and so I begin trawling the blogs (as is my want). I discovered this brilliant little gem from Mike DiPetrill&#8217;s blog.</p>
<p><span id="more-103"></span></p>
<p>This post demonstates the awesome power of the Vmware API and the ease of use we get from the VI Toolkit for Windows! The script will <a href="http://mikedatl.typepad.com/mikedvirtualization/2008/10/quick-migration.html">move a VM from one ESX host to another</a>, without making use of VMware VMotion. The drawback is that the VM becomes unresponsive for a period of time (usually a few seconds). This is roughly functionally equivalent to Microsoft&#8217;s Quick Migration feature, except that this was done in 130 lines of script.</p>
<div class="shr-publisher-103"></div><!-- Start Shareaholic LikeButtonSetBottom Automatic --><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><div class='shareaholic-like-buttonset' style='float:none;height:30px;'><a class='shareaholic-googleplusone' data-shr_size='medium' data-shr_count='true' data-shr_href='http%3A%2F%2Finvurted.com%2Fmigrating-virtual-machines-without-vmotion%2F' data-shr_title='%5BTUTORIAL%5D+Migrating+Virtual+Machines+without+Vmotion'></a><a class='shareaholic-fbsend' data-shr_href='http%3A%2F%2Finvurted.com%2Fmigrating-virtual-machines-without-vmotion%2F'></a><a class='shareaholic-fblike' data-shr_layout='button_count' data-shr_showfaces='false' data-shr_href='http%3A%2F%2Finvurted.com%2Fmigrating-virtual-machines-without-vmotion%2F' data-shr_title='%5BTUTORIAL%5D+Migrating+Virtual+Machines+without+Vmotion'></a></div><div style="clear: both; min-height: 1px; height: 3px; width: 100%;"></div><!-- End Shareaholic LikeButtonSetBottom Automatic -->]]></content:encoded>
			<wfw:commentRss>http://invurted.com/migrating-virtual-machines-without-vmotion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

