<?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>VCritical &#187; PowerCLI</title>
	<atom:link href="http://www.vcritical.com/tag/powercli/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vcritical.com</link>
	<description>Informed Virtualization Criticism</description>
	<lastBuildDate>Mon, 12 Jul 2010 22:38:36 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PowerShell Prevents Datastore Emergencies</title>
		<link>http://www.vcritical.com/2009/10/powershell-prevents-datastore-emergencies/</link>
		<comments>http://www.vcritical.com/2009/10/powershell-prevents-datastore-emergencies/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 10:30:03 +0000</pubDate>
		<dc:creator>Eric Gray</dc:creator>
				<category><![CDATA[Virtualizationism]]></category>
		<category><![CDATA[PASS]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[Storage VMotion]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[thin provisioning]]></category>
		<category><![CDATA[vCenter]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://www.vcritical.com/?p=1713</guid>
		<description><![CDATA[When a datastore in your VMware vSphere environment is about to fill up, you can have vCenter automatically spring into action to prevent downtime by using Storage VMotion.]]></description>
			<content:encoded><![CDATA[<p>In my previous post on <a href="http://www.vcritical.com/2009/10/responsible-thin-provisioning-in-vmware-vsphere/">VMware vSphere thin provisioning</a>, I pointed out the new datastore alarm feature.  You can take advantage of this feature to respond to a sudden storage demand and <strong>automatically take action before end users notice</strong>.</p>
<p>When triggered, vCenter Server alarm actions allow several options, including the ability to run an arbitrary command such as a VMware PowerCLI PowerShell script.  Please see <a href="http://blogs.vmware.com/vipowershell/2009/09/how-to-run-powercli-scripts-from-vcenter-alarms.html" target="_blank">Carter Shanklin&#8217;s in-depth article</a> for more details on how this works &#8212; note that he uses a different technique to launch the scripts.</p>
<h2>Storage VMotion to the Rescue</h2>
<p>When a datastore is about to run out of space, the fastest resolution may be to simply migrate virtual disks to another datastore.   VMware Storage VMotion provides that capability with zero downtime for VMs and no disruption to end users.  Fortunately, PowerCLI can perform this feat with ease, thanks to the Move-VM cmdlet.</p>
<p>Let&#8217;s take a look at a functional prototype PowerCLI PowerShell script:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Add-PSSnapin</span> VMware.Vimautomation.Core
Connect<span style="color: pink;">-</span>VIServer localhost
&nbsp;
<span style="color: #800080;">$vmToMove</span> <span style="color: pink;">=</span> get<span style="color: pink;">-</span>vm <span style="color: pink;">-</span>Datastore <span style="color: #800080;">$env</span>:VMWARE_ALARM_TARGET_NAME <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select-object</span> <span style="color: #008080; font-style: italic;">-first</span> <span style="color: #000000;">1</span>
&nbsp;
<span style="color: #800080;">$destDS</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>Datastore <span style="color: pink;">|</span> <span style="color: #0000FF;">where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.FreeSpaceMB <span style="color: #FF0000;">-gt</span> <span style="color: #000000;">50000</span> <span style="color: #FF0000;">-and</span> <span style="color: #000080;">$_</span>.Accessible <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select-object</span> <span style="color: #008080; font-style: italic;">-first</span> <span style="color: #000000;">1</span>
&nbsp;
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$destDS</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
	move<span style="color: pink;">-</span>vm <span style="color: pink;">-</span>VM <span style="color: #800080;">$vmToMove</span> <span style="color: pink;">-</span>Datastore <span style="color: #800080;">$destDS</span> <span style="color: pink;">-</span>RunAsync
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This script is a proof-of-concept that is not ready for your production environment as it is &#8212; it just picks an arbitrary VM from the nearly-full datastore, finds another datastore with at least 50GB free, and moves the VM disks.  More comprehensive selection logic and error checking are needed for a critical task like this.<span id="more-1713"></span></p>
<p>Save your script on the vCenter Server system somewhere, such as C:\scripts\datastore.ps1.</p>
<h2>Create the Datastore Alarm</h2>
<p>Create a new alarm at an appropriate level in the vCenter hierarchy, such as a datacenter, and configure like this:</p>
<p><img class="alignnone size-full wp-image-1717" title="Datastore Alarm" src="http://www.vcritical.com/wp-content/uploads/2009/09/datastore-emergency-general.png" alt="Datastore Alarm" width="404" height="253" /></p>
<p>On the Triggers tab, add a &#8220;Datastore Disk Usage (%)&#8221; trigger to alert at a reasonable percentage &#8212; I opted for 93.</p>
<h2>Run PowerShell Directly from vCenter Server</h2>
<p>For whatever reason, PowerShell.exe does not do well when launched directly by another process &#8212; it tends to hang instead of exiting when it is finished.  As a workaround, it <em>can</em> be launched from cmd.exe as long as it receives something on standard input.  To do all that, the necessary code looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="dos" style="font-family:monospace;">&quot;c:\windows\system32\cmd.exe&quot; &quot;/c <span style="color: #b1b100; font-weight: bold;">echo</span>.|powershell.exe -nologo -noprofile -noninteractive c:\scripts\datastore.ps1&quot;</pre></div></div>

<p>For an alternate approach, take a look at the intermediate batch file solution described by Carter Shanklin in the link above.</p>
<p>On the Actions tab, add a &#8220;Run a command&#8221; action and supply the appropriate command.  You also need to decide whether to run one time or repeat the action.</p>
<p><a href="http://www.vcritical.com/wp-content/uploads/2009/09/datastore-emergency-run-command.png"><img class="alignnone size-medium wp-image-1718" title="Datastore alarm running a PowerShell script" src="http://www.vcritical.com/wp-content/uploads/2009/09/datastore-emergency-run-command-300x191.png" alt="Datastore alarm running a PowerShell script" width="300" height="191" /></a></p>
<h2>Action!</h2>
<p>To test the alarm, either fill up the datastore or temporarily lower the alarm threshold.  When the alarm fires, a Storage VMotion should be seen in the vSphere Client:</p>
<p><img class="alignnone size-full wp-image-1721" title="Storage VMotion in progress" src="http://www.vcritical.com/wp-content/uploads/2009/09/svmotion-inprogress.png" alt="Storage VMotion in progress" width="381" height="39" /></p>
<p>Note the &#8220;Initiated by&#8221; column &#8212; that&#8217;s the machine account for this vCenter Server.  The PowerCLI script is kicked off from vpxd.exe, which is running as LocalSystem.</p>
<p>Additional information is available by looking at the Tasks &amp; Events tab for the datastore.  Here you can see a sample sequence of events, newest on top:</p>
<p><img class="alignnone size-full wp-image-1723" title="Datastore emergency events" src="http://www.vcritical.com/wp-content/uploads/2009/09/datastore-emergency-events.png" alt="Datastore emergency events" width="500" height="418" /></p>
<h2>The Last Resort</h2>
<p>This automated Storage VMotion recovery alarm is a safety valve that could help you avoid suddenly running out of space on a datastore.  It should not take the place of more proactive storage management, but it sure beats VM downtime.</p>
<p style="padding-left: 30px;">In case you are wondering: No, you can&#8217;t do the same thing with Hyper-V because Hyper-V does not have zero-downtime Storage VMotion.  Just another reason to choose VMware vSphere &#8212; as if you needed <em>another</em> reason.</p>
<p><strong>Have you used vCenter alarms to automate any recovery processes in your environment?<br />
</strong></p>


<p>Related posts:<ol><li><a href='http://www.vcritical.com/2009/10/easy-recovery-from-a-full-vmware-esx-datastore/' rel='bookmark' title='Permanent Link: Easy recovery from a full VMware ESX datastore'>Easy recovery from a full VMware ESX datastore</a></li>
<li><a href='http://www.vcritical.com/2009/10/responsible-thin-provisioning-in-vmware-vsphere/' rel='bookmark' title='Permanent Link: Responsible Thin Provisioning in VMware vSphere'>Responsible Thin Provisioning in VMware vSphere</a></li>
<li><a href='http://www.vcritical.com/2009/02/vi-toolkit-for-windows-15-and-the-powershell-prompt/' rel='bookmark' title='Permanent Link: VI Toolkit (for Windows) 1.5 and the PowerShell prompt'>VI Toolkit (for Windows) 1.5 and the PowerShell prompt</a></li>
<li><a href='http://www.vcritical.com/2009/06/vmware-vsphere-4-has-a-snapshot-alarm/' rel='bookmark' title='Permanent Link: VMware vSphere 4 has a Snapshot Alarm'>VMware vSphere 4 has a Snapshot Alarm</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vcritical.com/2009/10/powershell-prevents-datastore-emergencies/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Better console for PowerShell and VITK</title>
		<link>http://www.vcritical.com/2009/02/better-console-for-powershell-and-vitk/</link>
		<comments>http://www.vcritical.com/2009/02/better-console-for-powershell-and-vitk/#comments</comments>
		<pubDate>Thu, 05 Feb 2009 11:00:37 +0000</pubDate>
		<dc:creator>Eric Gray</dc:creator>
				<category><![CDATA[Virtualizationism]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://www.vcritical.com/?p=584</guid>
		<description><![CDATA[By using Console2 with PowerShell and the VI Toolkit, users have much better text manipulation capabilities as well as the option to use different fonts.]]></description>
			<content:encoded><![CDATA[<p>The stock Windows command prompt (cmd.exe) is pretty limited&#8211;if you want to use <a href="http://www.vcritical.com/2009/01/get-a-better-font-for-putty/">a better font</a> or copy text in lines instead of clunky rectangular blocks, you need something else.  For Windows command-line utilities, PowerShell, and the VI Toolkit (for Windows), I have been using the open-source <a href="http://sourceforge.net/projects/console/">Console2</a> with much satisfaction.  The tabbed interface is pretty cool:</p>
<p><img class="alignnone size-full wp-image-657" title="Console2 with VI Toolkit and PowerShell tabs." src="http://www.vcritical.com/wp-content/uploads/2009/02/console2-vitk-ps.gif" alt="Console2 with VI Toolkit and PowerShell tabs." width="500" height="280" /></p>
<p>If that looks interesting, here is what you do:<span id="more-584"></span></p>
<ul>
<li>Download <a href="http://sourceforge.net/projects/console/" target="_blank">Console2</a> (current version is 2.00 Beta, build 142); extract on your system somewhere</li>
<li>Grab <a href="http://www.vcritical.com/wp-content/uploads/2009/02/console2-vcritical-2009-02-04.zip">this file</a> with icons and a replacement configuration file (console.xml); extract into the same location</li>
<li>Make a shortcut to console.exe
<ul>
<li>Multiple tabs can be opened during launch by adding -t to your shortcut target (e.g., -t Console2 -t &#8220;VI Toolkit&#8221;)</li>
</ul>
</li>
<li>Optional: <a href="http://www.vcritical.com/2009/02/vi-toolkit-for-windows-15-and-the-powershell-prompt/">fix your prompts</a></li>
</ul>
<p>My configuration file has a few changes to the mouse behavior:</p>
<ul>
<li>Left &#8211; select + copy automatically</li>
<li>Right &#8211; paste</li>
<li>Middle &#8211; pop-up menu</li>
</ul>
<p>If you prefer to not use my entire configuration file, just copy the applicable portions from the &lt;tabs&gt; element.</p>
<p>I hope you  have enjoyed this slight diversion from the regular VCritical programming lineup.  Thanks for reading.</p>


<p>Related posts:<ol><li><a href='http://www.vcritical.com/2009/02/vi-toolkit-for-windows-15-and-the-powershell-prompt/' rel='bookmark' title='Permanent Link: VI Toolkit (for Windows) 1.5 and the PowerShell prompt'>VI Toolkit (for Windows) 1.5 and the PowerShell prompt</a></li>
<li><a href='http://www.vcritical.com/2009/01/finding-thin-provisioned-virtual-disks-with-powershell/' rel='bookmark' title='Permanent Link: Finding thin-provisioned virtual disks with PowerShell'>Finding thin-provisioned virtual disks with PowerShell</a></li>
<li><a href='http://www.vcritical.com/2009/10/powershell-prevents-datastore-emergencies/' rel='bookmark' title='Permanent Link: PowerShell Prevents Datastore Emergencies'>PowerShell Prevents Datastore Emergencies</a></li>
<li><a href='http://www.vcritical.com/2009/01/clean-up-vcenter-with-powershell-after-scvmm-leaves/' rel='bookmark' title='Permanent Link: Clean up vCenter with PowerShell after SCVMM leaves'>Clean up vCenter with PowerShell after SCVMM leaves</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vcritical.com/2009/02/better-console-for-powershell-and-vitk/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>VI Toolkit (for Windows) 1.5 and the PowerShell prompt</title>
		<link>http://www.vcritical.com/2009/02/vi-toolkit-for-windows-15-and-the-powershell-prompt/</link>
		<comments>http://www.vcritical.com/2009/02/vi-toolkit-for-windows-15-and-the-powershell-prompt/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 14:50:01 +0000</pubDate>
		<dc:creator>Eric Gray</dc:creator>
				<category><![CDATA[Virtualizationism]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technical]]></category>

		<guid isPermaLink="false">http://www.vcritical.com/?p=604</guid>
		<description><![CDATA[The VI Toolkit for Windows overrides an existing PowerShell prompt function.  Here is one simple way to restore a desired setting.]]></description>
			<content:encoded><![CDATA[<p>One of the first things that I noticed after launching my VI Toolkit (for Windows) 1.5 is the new prompt.  It&#8217;s tricked-out with color now, but unfortunately steps on the existing two-row PowerShell prompt I had configured on my system &#8212; which was working fine with VITK 1.0.</p>
<p>I tend to use a two-row prompt in all of my shells (cmd.exe, Bash, PowerShell) because long commands get confusing when they wrap to another line.  Some people think this is a terrible idea &#8212; if you are one of them, feel free to stop reading right now.</p>
<p>Here is the default VITK 1.5 console, along with a typical command:</p>
<p style="text-align: center;"><a href="http://www.vcritical.com/wp-content/uploads/2009/01/2-row-command.png"><img class="aligncenter size-full wp-image-606" title="Command wrapping onto another line." src="http://www.vcritical.com/wp-content/uploads/2009/01/2-row-command.png" alt="Command wrapping onto another line." width="468" height="237" /></a></p>
<p>You can see the customization added by VITK 1.5. Note that VITK 1.0 did not specify a prompt at all &#8212; it simply used whatever PowerShell was configured to use.  The PowerShell prompt can be configured in a variety of ways, one of which is to create the file: <span style="font-family: monospace; font-weight: bold; font-size: 10pt;">&#8230;\My Documents\WindowsPowerShell\profile.ps1</span> containing:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> global:prompt <span style="color: #000000;">&#123;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">get-location</span><span style="color: #000000;">&#41;</span>.path <span style="color: pink;">+</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&gt;;&quot;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p>That stopped working because VITK 1.5 now specifically defines a prompt function in <span style="font-family: monospace; font-weight: bold; font-size: 10pt;">C:\Program Files\VMware\Infrastructure\VIToolkitForWindows\Scripts\Initialize-VIToolkitEnvironment.ps1</span><br />
<span id="more-604"></span><br />
To get a two-row prompt, simply open that file and add <span style="font-family: monospace; font-weight: bold; font-size: 10pt;">`n</span> (that symbol is a backtick &#8212; above the Tab key on most keyboards) right before the <span style="font-family: monospace; font-weight: bold; font-size: 10pt;">&gt;</span> on line 81 (the last line shown in the snippet below):</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># change prompt text</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;[&quot;</span> <span style="color: #008080; font-style: italic;">-NoNewLine</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;VI Toolkit&quot;</span> <span style="color: #008080; font-style: italic;">-NoNewLine</span> <span style="color: #008080; font-style: italic;">-foregroundcolor</span> Green
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;] &quot;</span> <span style="color: #008080; font-style: italic;">-NoNewLine</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-location</span><span style="color: #000000;">&#41;</span>.Path <span style="color: pink;">+</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&gt;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-NoNewLine</span></pre></div></div>

<p>You will end up with this:</p>
<p style="text-align: center;"><a href="http://www.vcritical.com/wp-content/uploads/2009/01/2-row.png"><img class="aligncenter size-full wp-image-605" title="Two-row prompt with long command." src="http://www.vcritical.com/wp-content/uploads/2009/01/2-row.png" alt="Two-row prompt with long command." width="468" height="237" /></a></p>
<p>I don&#8217;t think this change causes any harm to the VITK installation &#8212; please correct me if I&#8217;m wrong.</p>
<p><strong>In related news&#8230;</strong><br />
A quick way to set up the standard Windows Command Prompt with two rows is to just load this .reg file:</p>

<div class="wp_syntax"><div class="code"><pre class="reg" style="font-family:monospace;"><span style="color: #0000FF;">Windows Registry Editor Version 5.00</span>
&nbsp;
<span style="color: #000000;">&#91;</span><span style="color: #800000;">HKEY_LOCAL_MACHINE</span>\SYSTEM\CurrentControlSet\Control\Session Manager\Environment<span style="color: #000000;">&#93;</span>
<span style="color: #0000FF;">&quot;PROMPT&quot;</span><span style="color: #000000;">=</span><span style="">&quot;$P\\$_$G&quot;</span></pre></div></div>



<p>Related posts:<ol><li><a href='http://www.vcritical.com/2009/02/better-console-for-powershell-and-vitk/' rel='bookmark' title='Permanent Link: Better console for PowerShell and VITK'>Better console for PowerShell and VITK</a></li>
<li><a href='http://www.vcritical.com/2009/01/finding-thin-provisioned-virtual-disks-with-powershell/' rel='bookmark' title='Permanent Link: Finding thin-provisioned virtual disks with PowerShell'>Finding thin-provisioned virtual disks with PowerShell</a></li>
<li><a href='http://www.vcritical.com/2009/01/vi-toolkit-for-windows-15-released/' rel='bookmark' title='Permanent Link: VI Toolkit (for Windows) 1.5 released'>VI Toolkit (for Windows) 1.5 released</a></li>
<li><a href='http://www.vcritical.com/2009/01/clean-up-vcenter-with-powershell-after-scvmm-leaves/' rel='bookmark' title='Permanent Link: Clean up vCenter with PowerShell after SCVMM leaves'>Clean up vCenter with PowerShell after SCVMM leaves</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vcritical.com/2009/02/vi-toolkit-for-windows-15-and-the-powershell-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VI Toolkit (for Windows) 1.5 released</title>
		<link>http://www.vcritical.com/2009/01/vi-toolkit-for-windows-15-released/</link>
		<comments>http://www.vcritical.com/2009/01/vi-toolkit-for-windows-15-released/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 19:08:40 +0000</pubDate>
		<dc:creator>Eric Gray</dc:creator>
				<category><![CDATA[Virtualizationism]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.vcritical.com/?p=586</guid>
		<description><![CDATA[There is a new version of the VI Toolkit (for Windows) up for the taking now, with quite a few new cmdlets and fixes.  Visit the official blog for links to download and read the release notes.  I installed the upgrade on top of my existing 1.0 without any issues.  (Wow, the download now weighs [...]]]></description>
			<content:encoded><![CDATA[<p>There is a new version of the VI Toolkit (for Windows) up for the taking now, with quite a few new cmdlets and fixes.  Visit the <a href="http://blogs.vmware.com/vipowershell/2009/01/vi-toolkit-15-released.html">official blog</a> for links to download and read the release notes.  I installed the upgrade on top of my existing 1.0 without any issues.  (Wow, the download now weighs in at 41MB.)</p>
<p>After launching the new version I noticed a couple of really nice additions right away.  Two new helpful commands:</p>
<p><strong>Get-VIToolkitDocumentation</strong> will pop open the local help file</p>
<p><strong>Get-VIToolkitCommunity</strong> launches your web browser to the <a href="http://communities.vmware.com/community/developer/windows_toolkit">official Community site</a></p>
<p>Carter Shanklin also posted a <a href="http://www.vimeo.com/videos/search:vi-toolkit%2015-release" target="_blank">series of videos</a> on Vimeo.  I was glad to hear about the fixes to <strong>Move-VM</strong>:</p>
<p><object type="application/x-shockwave-flash" style="width:448px;height:386px" data="http://www.vimeo.com/moogaloop.swf?clip_id=2985147&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="quality" value="best" /><param name="wmode" value="transparent" /><param name="movie" value="http://www.vimeo.com/moogaloop.swf?clip_id=2985147&amp;server=www.vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0" /><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer" />If you can see this, then you might need a Flash Player upgrade or you need to install Flash Player if it's missing. Get <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash Player</a> from Adobe.</object><br/>
		<!-- Valid XHTML flash object delivered by XHTML Video Embed. Get it at: http://saltwaterc.net/xhtml-video-embed -->
		</p>


<p>Related posts:<ol><li><a href='http://www.vcritical.com/2009/07/upgrading-vms-to-vsphere-virtual-hardware/' rel='bookmark' title='Permanent Link: Upgrading VMs to vSphere virtual hardware'>Upgrading VMs to vSphere virtual hardware</a></li>
<li><a href='http://www.vcritical.com/2010/01/vmware-esxi-4-sd-flash-in-bl460c-g6/' rel='bookmark' title='Permanent Link: VMware ESXi 4: SD Flash in BL460c G6'>VMware ESXi 4: SD Flash in BL460c G6</a></li>
<li><a href='http://www.vcritical.com/2009/02/better-console-for-powershell-and-vitk/' rel='bookmark' title='Permanent Link: Better console for PowerShell and VITK'>Better console for PowerShell and VITK</a></li>
<li><a href='http://www.vcritical.com/2009/01/clean-up-vcenter-with-powershell-after-scvmm-leaves/' rel='bookmark' title='Permanent Link: Clean up vCenter with PowerShell after SCVMM leaves'>Clean up vCenter with PowerShell after SCVMM leaves</a></li>
</ol></p><div style="font-family:Verdana; color:#000000; background-color: #C0C0C0; padding: 7px;border: dashed thin">

<a href="http://www.vcritical.com/2009/01/vi-toolkit-for-windows-15-released/#comments">Leave a Comment</a> •
<a href="http://feedproxy.google.com/vcritical">Subscribe to RSS</a> •
<a href="http://feedburner.google.com/fb/a/mailverify?uri=vcritical&loc=en_US">Subscribe via Email</a> •
<a href="http://www.twitter.com/eric_gray">Follow Eric Gray on Twitter</a><br/>

More articles on: <a href="http://www.vcritical.com/tag/powercli/" rel="tag">PowerCLI</a>, <a href="http://www.vcritical.com/tag/powershell/" rel="tag">PowerShell</a> • <a href="http://www.vcritical.com/category/virtualizationism/">Browse All Virtualization Content</a><br/>

<a href="http://www.vcritical.com/2009/01/vi-toolkit-for-windows-15-released/">VI Toolkit (for Windows) 1.5 released</a> by <a href="http://www.vcritical.com/about/">Eric Gray</a> © 2009 • <a href="http://www.vcritical.com/">VCritical</a>

</div>]]></content:encoded>
			<wfw:commentRss>http://www.vcritical.com/2009/01/vi-toolkit-for-windows-15-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Finding thin-provisioned virtual disks with PowerShell</title>
		<link>http://www.vcritical.com/2009/01/finding-thin-provisioned-virtual-disks-with-powershell/</link>
		<comments>http://www.vcritical.com/2009/01/finding-thin-provisioned-virtual-disks-with-powershell/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 18:26:39 +0000</pubDate>
		<dc:creator>Eric Gray</dc:creator>
				<category><![CDATA[Virtualizationism]]></category>
		<category><![CDATA[ESX]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[templates]]></category>
		<category><![CDATA[vCenter]]></category>
		<category><![CDATA[VI Client]]></category>

		<guid isPermaLink="false">http://www.vcritical.com/?p=514</guid>
		<description><![CDATA[Even though the VI Client does not offer creation of VMs with thin-provisioned disks, they may exist.  Use a PowerShell script to identify them.]]></description>
			<content:encoded><![CDATA[<p>By default, all virtual hard disks in VI3 are <strong>thick disks</strong> &#8212; space is allocated on the VMFS datastore for the entire disk.  <strong>Thin disks</strong>, on the other hand, grow dynamically according to guest OS demand.  There is a slight performance penalty with thin disks, but the real risk when using them is inadvertently filling up datastores after overcommitting storage resources.</p>
<p>The VI Client interface will not let administrators create new virtual machines with thin-provisioned disks.  Even so, it is entirely possible that your environment contains such disks.  Let&#8217;s take a look at a couple of ways to create these disks and then use a VI Toolkit (for Windows) PowerShell script to see if any exist.<span id="more-514"></span></p>
<h2>Manual VMDK Creation</h2>
<p>One way that thin disks may be introduced into an environment is by manually creating a VMDK file and then attaching that file to a virtual machine.  This can be accomplished by the vmkfstools command with the -d thin option.  This procedure is not for beginners, so if you have used it you presumably evaluated the risks of overcommitting your storage.  But what if one of your colleagues did this without telling you?</p>
<h2>Compact Clones</h2>
<p><img class="alignleft size-full wp-image-515" title="VI Client - Clone to template" src="http://www.vcritical.com/wp-content/uploads/2009/01/clone-to-template-menu.png" alt="VI Client - Clone to template" width="181" height="207" />Another source of thin disks requires a little background first:</p>
<p>There is a prominent option in the VI Client interface to convert a virtual machine to template (and vice versa).  But if you right-click a VM in the inventory, you are presented with a variation of that feature:  <strong>Clone to Template</strong>.</p>
<p>The wizard that launches in response to that option allows an administrator to optionally choose the <strong>Compact</strong> disk format &#8212; this is a thin-provisioned disk.  If your template has a 50GB virtual disk but only 8GB are actually used, this feature can provide significant storage savings.</p>
<p style="text-align: center;"><img class="aligncenter size-full wp-image-516" style="border: 1px solid black;" title="Clone to Template Wizard - Compact disk" src="http://www.vcritical.com/wp-content/uploads/2009/01/wizard-compact.png" alt="Clone to Template Wizard - Compact disk" width="499" height="347" /></p>
<p>So far so good.  Now, what do you suppose happens if you decide to convert that template to a VM?  Nothing happens &#8212; it just works.  You are free to use that VM just like any other in your inventory.  But this VM keeps its thin-provisioned disk, a fact that is not discernible through the user interface.</p>
<h2>Find the Thin-Provisioned Disks</h2>
<p>I wrote a small VI Toolkit (for Windows) PowerShell script that identifies latent thin disks in both VMs and templates.  I hope you find it useful:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># FindThinDisks.ps1</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># Identifies VMs and templates that are using thin-provisioned</span>
<span style="color: #008000;"># virtual disks.</span>
&nbsp;
<span style="color: #008000;"># Version 1.0  January 14, 2009</span>
<span style="color: #008000;"># Eric Gray</span>
&nbsp;
<span style="color: #800080;">$vmtp</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VM
<span style="color: #800080;">$vmtp</span> <span style="color: pink;">+=</span> Get<span style="color: pink;">-</span>Template
&nbsp;
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$vmtp</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>View<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
  <span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$dev</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$vm</span>.Config.Hardware.Device<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
    <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$dev</span>.GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;VirtualDisk&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
      <span style="color: #0000FF;">if</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$dev</span>.Backing.ThinProvisioned <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$true</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
        <span style="color: #800080;">$vm</span>.Name <span style="color: pink;">+</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`t</span>&quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$dev</span>.Backing.FileName
      <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
  <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p style="text-align: left;">Thin-provisioning is a great tool to have in your toolbox, when used properly.</p>
<p style="text-align: right;"><em>Script inspired by <a href="http://communities.vmware.com/message/1136794" target="_blank">this thread</a>.</em></p>


<p>Related posts:<ol><li><a href='http://www.vcritical.com/2009/11/vsphere-thin-provisioned-disk-performance/' rel='bookmark' title='Permanent Link: vSphere Thin-Provisioned Disk Performance'>vSphere Thin-Provisioned Disk Performance</a></li>
<li><a href='http://www.vcritical.com/2009/10/responsible-thin-provisioning-in-vmware-vsphere/' rel='bookmark' title='Permanent Link: Responsible Thin Provisioning in VMware vSphere'>Responsible Thin Provisioning in VMware vSphere</a></li>
<li><a href='http://www.vcritical.com/2009/10/powershell-prevents-datastore-emergencies/' rel='bookmark' title='Permanent Link: PowerShell Prevents Datastore Emergencies'>PowerShell Prevents Datastore Emergencies</a></li>
<li><a href='http://www.vcritical.com/2009/10/easy-recovery-from-a-full-vmware-esx-datastore/' rel='bookmark' title='Permanent Link: Easy recovery from a full VMware ESX datastore'>Easy recovery from a full VMware ESX datastore</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vcritical.com/2009/01/finding-thin-provisioned-virtual-disks-with-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Clean up vCenter with PowerShell after SCVMM leaves</title>
		<link>http://www.vcritical.com/2009/01/clean-up-vcenter-with-powershell-after-scvmm-leaves/</link>
		<comments>http://www.vcritical.com/2009/01/clean-up-vcenter-with-powershell-after-scvmm-leaves/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 21:16:01 +0000</pubDate>
		<dc:creator>Eric Gray</dc:creator>
				<category><![CDATA[Virtualizationism]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SCVMM]]></category>
		<category><![CDATA[Technical]]></category>
		<category><![CDATA[vCenter]]></category>

		<guid isPermaLink="false">http://www.vcritical.com/?p=432</guid>
		<description><![CDATA[When System Center Virtual Machine Manager (SCVMM) connects to VirtualCenter/vCenter, several changes are made.  Learn how to recover everything with PowerShell.]]></description>
			<content:encoded><![CDATA[<p>Microsoft System Center Virtual Machine Manager (SCVMM) 2008 makes several changes to your vCenter environment that you may like to know about, especially since they don&#8217;t seem to be mentioned in the product documentation.  It&#8217;s also worth pointing out that none of these changes are reverted when you subsequently decide to discontinue managing vCenter with SCVMM.</p>
<p>There are three different affected areas and you can fix each one manually or all in one shot with a VI Toolkit (for Windows) PowerShell script that I wrote for just this purpose.</p>
<h2>1.  SCVMM Port Groups</h2>
<p><img class="size-full wp-image-436 alignleft" title="VI Client displaying several SCVMM-created networks" src="http://www.vcritical.com/wp-content/uploads/2008/12/networks-scvmm.png" alt="networks-scvmm" width="203" height="205" /></p>
<p>First, let&#8217;s address the new port groups that SCVMM created when managing your VMware ESX VMs.  I covered this in more detail in a <a href="http://www.vcritical.com/2008/12/thanks-for-all-the-port-groups/">previous article</a>.  Essentially, the SCVMM interface presents vSwitches, not port groups.  It then creates one or more new port groups for you without warning &#8212; one per vSwitch, per VLAN, on each ESX host.</p>
<p>To recover from this mess, you will need to reconfigure any VMs that are currently using these port groups and then delete the port groups from the vSwitches.  If you have more than a couple VMs this task will be easier with the script.<span id="more-432"></span></p>
<h2 style="clear:both">2.  Custom Attribute: ClusterInvariantVMMId</h2>
<p>I bet you did not know that SCVMM would add a new strangely-named custom attribute to vCenter and tag every single VM in your inventory with a GUID.  I&#8217;ve heard puzzled VMware customers asking about this.  Initially, the explanation for this phenomenon was not clear &#8212; until I evaluated the SCVMM product and VMware vCenter integration.  If you are done with SCVMM, it is safe to remove this attribute with VI Client (on the Administration menu).</p>
<p><img class="size-full wp-image-435 alignnone" style="border: 1px solid black;" title="VM Annotation field displaying ClusterInvariantVMMID" src="http://www.vcritical.com/wp-content/uploads/2008/12/annotations.png" alt="annotations" width="433" height="243" /></p>
<h2>3.  Self-Service Role</h2>
<p>Evidently the Self-Service Portal feature of SCVMM will allow users to provision and manage VMs on ESX hosts in addition to Hyper-V.  I tried this and it did not work, but I probably wasn&#8217;t persistent enough.  When you are done using SCVMM you won&#8217;t be needing that role anymore &#8212; go ahead and delete it.</p>
<p><img class="alignnone size-full wp-image-433" title="roles" src="http://www.vcritical.com/wp-content/uploads/2008/12/roles.png" alt="roles" width="442" height="265" /></p>
<h2>PowerShell Cleanup Script</h2>
<p>If you would like to clean up all three of these issues in one step, use the following VI Toolkit (for Windows):</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># SCVMM-Cleanup.ps1</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># When SCVMM connects to vCenter, it makes several changes and doesn't clean up</span>
<span style="color: #008000;"># after itself.  This script returns everything back to normal.</span>
&nbsp;
<span style="color: #008000;"># Version 1.0  January 5, 2009</span>
<span style="color: #008000;"># Eric Gray</span>
&nbsp;
<span style="color: #008000;"># modify this line accordingly</span>
Get<span style="color: pink;">-</span>VC vchostname <span style="color: pink;">-</span>user xxx <span style="color: pink;">-</span>Password yyy
&nbsp;
<span style="color: #008000;"># VMs using SCVMM-created port groups will be reconfigured to use this instead</span>
<span style="color: #800080;">$portGroup</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;VM Network&quot;</span>
&nbsp;
<span style="color: #008000;"># Move all NICs from the SCVMM.vSwitchX.Y port groups to $portGroup</span>
get<span style="color: pink;">-</span>vm <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>NetworkAdapter <span style="color: pink;">|</span> <span style="color: #0000FF;">where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.NetworkName <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;SCVMM*&quot;</span><span style="color: #000000;">&#125;</span> `
    <span style="color: pink;">|</span> Set<span style="color: pink;">-</span>NetworkAdapter <span style="color: pink;">-</span>NetworkName <span style="color: #800080;">$portGroup</span> <span style="color: #008080; font-style: italic;">-Confirm</span>:<span style="color: #800080;">$false</span>
&nbsp;
<span style="color: #008000;"># Delete those SCVMM port groups after they are no longer in use</span>
<span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$esx</span> <span style="color: #0000FF;">in</span> Get<span style="color: pink;">-</span>VMHost<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
    Get<span style="color: pink;">-</span>VirtualPortGroup <span style="color: pink;">-</span>VMHost <span style="color: #800080;">$esx</span>.Name <span style="color: pink;">|</span> <span style="color: #0000FF;">where</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Name <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;SCVMM*&quot;</span> <span style="color: #000000;">&#125;</span> `
    <span style="color: pink;">|</span> Remove<span style="color: pink;">-</span>VirtualPortGroup  <span style="color: #008080; font-style: italic;">-Confirm</span>:<span style="color: #800080;">$false</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Clean up the custom attribute</span>
Get<span style="color: pink;">-</span>Datacenter <span style="color: pink;">|</span> Remove<span style="color: pink;">-</span>CustomField <span style="color: #008080; font-style: italic;">-Name</span> ClusterInvariantVMMId <span style="color: #008080; font-style: italic;">-Confirm</span>:<span style="color: #800080;">$false</span>
&nbsp;
<span style="color: #008000;"># Remove the SCVMM role</span>
<span style="color: #800080;">$authMgr</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View AuthorizationManager
<span style="color: #0000FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$role</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$authMgr</span>.RoleList <span style="color: pink;">|</span> <span style="color: #0000FF;">where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;SCVMMSelfServiceUser&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
    <span style="color: #800080;">$authMgr</span>.RemoveAuthorizationRole<span style="color: #000000;">&#40;</span><span style="color: #800080;">$role</span>.roleid<span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>If you or one of your coworkers accidentally polluted your vCenter environment, this should help you get everything back in order.</p>
<p style="text-align: right;"><em>Thanks go to Carter Shanklin for reviewing the script.</em></p>


<p>Related posts:<ol><li><a href='http://www.vcritical.com/2009/04/igt-part-6-cluster-invari-what-id/' rel='bookmark' title='Permanent Link: IGT Part 6: Cluster invari-what ID?'>IGT Part 6: Cluster invari-what ID?</a></li>
<li><a href='http://www.vcritical.com/2009/03/managing-vi3-with-scvmm-considered-harmful/' rel='bookmark' title='Permanent Link: Managing VI3 with SCVMM considered harmful'>Managing VI3 with SCVMM considered harmful</a></li>
<li><a href='http://www.vcritical.com/2008/12/thanks-for-all-the-port-groups/' rel='bookmark' title='Permanent Link: Thanks for all the port groups!'>Thanks for all the port groups!</a></li>
<li><a href='http://www.vcritical.com/2009/04/vmware-vcenter-server-4-task-and-event-retention/' rel='bookmark' title='Permanent Link: VMware vCenter Server 4 task and event retention'>VMware vCenter Server 4 task and event retention</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.vcritical.com/2009/01/clean-up-vcenter-with-powershell-after-scvmm-leaves/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
