<?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>ben.neise.co.uk &#187; vCenter</title>
	<atom:link href="http://ben.neise.co.uk/index.php/tag/vcenter/feed/" rel="self" type="application/rss+xml" />
	<link>http://ben.neise.co.uk</link>
	<description></description>
	<lastBuildDate>Wed, 27 Jul 2011 10:19:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Eric Sloof&#8217;s quick guide to using the VMware VIX API with vCenter</title>
		<link>http://ben.neise.co.uk/index.php/2010/04/eric-sloofs-quick-guide-to-using-the-vmware-vix-api-with-vcenter/</link>
		<comments>http://ben.neise.co.uk/index.php/2010/04/eric-sloofs-quick-guide-to-using-the-vmware-vix-api-with-vcenter/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 11:45:32 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[VMware]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[vCenter]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=373</guid>
		<description><![CDATA[Eric Sloof from NTPro.NL has posted an excellent short video showing how easy it is to create a VB application to do some simple operations on vSphere virtual machines. Online Training – Automating vSphere with the VIX API from Eric Sloof NTPRO.NL on Vimeo. I can&#8217;t wait to try this out, although I think I&#8217;m [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://twitter.com/esloof">Eric Sloof</a> from <a href="http://www.ntpro.nl/blog/">NTPro.NL</a> has posted an excellent short video showing how easy it is to create a VB application to do some simple operations on vSphere virtual machines.</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="400" height="300" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=11193427&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=24ff95&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="400" height="300" src="http://vimeo.com/moogaloop.swf?clip_id=11193427&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=1&amp;color=24ff95&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p><a href="http://vimeo.com/11193427">Online Training – Automating vSphere with the VIX API</a> from <a href="http://vimeo.com/esloof">Eric Sloof NTPRO.NL</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>I can&#8217;t wait to try this out, although I think I&#8217;m going to have to do a little Visual Basic study first.</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2010/04/eric-sloofs-quick-guide-to-using-the-vmware-vix-api-with-vcenter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vSphere 4.0 Update 1 Released</title>
		<link>http://ben.neise.co.uk/index.php/2009/11/vsphere-4-0-update-1-released/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/11/vsphere-4-0-update-1-released/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 13:22:27 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[vCenter]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=298</guid>
		<description><![CDATA[VMware have released update 1 for vSphere 4.0.]]></description>
			<content:encoded><![CDATA[<p>VMware have released update 1 for vSphere 4.0.</p>
<p>The following enhancements have been made to ESX (from the <a href="http://www.vmware.com/support/vsphere4/doc/vsp_esx40_u1_rel_notes.html#whatsnew">release notes</a>):-</p>
<blockquote><p><strong>VMware View 4.0 support</strong> <strong>–</strong> This release adds support for VMware View 4.0, a solution built specifically for delivering desktops as a managed service from the protocol to the platform.</p>
<p><strong>Windows 7 and Windows 2008 R2 support –</strong>This release adds support for 32-bit and 64-bit versions of Windows 7 as well as 64-bit Windows 2008 R2 as guest OS platforms. In addition, the vSphere Client is now supported and can be installed on a Windows 7 platform. For a complete list of supported guest operating systems with this release, see the <a href="http://www.vmware.com/resources/compatibility/search.php" target="_blank"><em>VMware Compatibility Guide</em></a>.</p>
<p><strong>Enhanced Clustering Support for Microsoft Windows –</strong> Microsoft Cluster Server (MSCS) for Windows 2000 and 2003 and Windows Server 2008 Failover Clustering is now supported on an VMware High Availability (HA) and Dynamic Resource Scheduler (DRS) cluster in a limited configuration. HA and DRS functionality can be effectively disabled for individual MSCS virtual machines as opposed to disabling HA and DRS on the entire ESX/ESXi host<strong>. </strong>Refer to the <em><a href="http://www.vmware.com/pdf/vsphere4/r40_u1/vsp_40_u1_mscs.pdf" target="_blank">Setup for Failover Clustering and  Microsoft Cluster Service</a></em> guide for additional configuration guidelines.</p>
<p><strong>Enhanced VMware Paravirtualized SCSI Support</strong><strong> –</strong> Support for boot disk devices attached to a Paravirtualized SCSI ( PVSCSI) adapter has been added for Windows 2003 and 2008 guest operating systems. Floppy disk images are also available containing the driver for use during the Windows installation by selecting F6 to install additional drivers during setup. Floppy images can be found in the <tt>/vmimages/floppies/</tt> folder.</p>
<p><strong>Improved vNetwork Distributed Switch  Performance</strong> <strong>–</strong> Several performance and usability issues have been resolved resulting in the following:</p>
<ul>
<li>Improved performance when making configuration changes to a vNetwork Distributed Switch (vDS) instance when the ESX/ESXi host is under a heavy load</li>
<li>Improved performance when adding or removing an ESX/ESXi host to or from a vDS instance</li>
</ul>
<p><strong>Increase in vCPU per Core Limit</strong> <strong>–</strong> The limit on vCPUs per core has been increased from 20 to 25. This change raises the supported limit only. It does not include any additional performance optimizations. Raising the limit allows users more flexibility to configure systems based on specific workloads and to get the most advantage from increasingly faster processors. The achievable number of vCPUs per core depends on the workload and specifics of the hardware. For more information see the <em><a href="http://www.vmware.com/pdf/Perf_Best_Practices_vSphere4.0.pdf" target="_blank">Performance Best Practices for VMware vSphere 4.0</a></em> guide.</p>
<p><strong>Enablement of Intel Xeon Processor 3400 Series</strong> – Support for the Xeon processor 3400 series has been added. For a complete list of supported third party hardware and devices, see the <a href="http://www.vmware.com/resources/compatibility/search.php" target="_blank">VMware Compatibility Guide</a>.</p></blockquote>
<p>vCenter 4.0 has also been updated, and now has full compatibility with Windows 7 x86 and x64 versions. Saving the <a href="http://xtravirt.com/running-vmware-vsphere-client-windows-7">various hacks that were necessary to get it working</a>.</p>
<p>Also, the PowerCLI has been updated, and can be found <a href="http://blogs.vmware.com/vipowershell/2009/11/powercli-40-u1-is-out.html">here</a>. There are 68 new CMDLETS, which <a href="http://www.virtu-al.net/2009/11/20/powercli-bring-on-the-next-version/">Alan Renouf does a great job of explaining</a>. I&#8217;m especially looking forward to trying out Get\Set-CustomAttribute (no more manipulation of the View object), Move-VMTemplate (no more converting templates to machines), and Get\Set-VMQuestion (for those times when the datastores run out of space for the REDO files necessitated by Non-Persistent disks).</p>
<p>I&#8217;m looking forward to investigating the new PowerCLI functionality, and I&#8217;m also looking forward to not needing to  manually customise the dozen or so Windows 7 guests I&#8217;m deploying next week!</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/11/vsphere-4-0-update-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XtraVirt&#8217;s vAlarm</title>
		<link>http://ben.neise.co.uk/index.php/2009/10/xtravirts-valarm/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/10/xtravirts-valarm/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 20:20:58 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[VMware]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[vCenter]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=281</guid>
		<description><![CDATA[I've been trying out XtraVirt's vAlarm.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been trying out <a href="http://xtravirt.com/">XtraVirt</a>&#8216;s vAlarm:-</p>
<blockquote><p>vAlarm is a Windows® based application which monitors alarms generated by VMware® vCenter.</p>
<p>The product is designed to be installed on an administrators PC, and provides automated monitoring of vCenter alarms without needing to be logged into a full VI Client console.</p>
<p>The software automatically communicates with a vCenter server on a user configurable schedule, and notifies any active alarms via a popup information bubble in the notification area of a users desktop.</p>
<p>The option to show details of all active alarms displays an information dialogue which lists individual alarms with detailed descriptions.</p>
<p>The software supports VMware vCenter 2.5 &amp; 4.0.</p></blockquote>
<p>It&#8217;s turned out to be quite handy, as it&#8217;s making me far more conscious of alarms. It might even encourage me to modify the default set of alarms &#8211; I&#8217;m generally not interested in guests going into the red because of CPU or memory due to the nature of the way they&#8217;re used, but I do need to know when hosts and datastores are running close to capacity.</p>
<p>The system tray application pops up a bubble, even when there are no alarms, which isn&#8217;t strictly necessary, and it might be nice to be able to collate notifications from more than one vCenter Server (I&#8217;m currently watching over two); but these are minor quibbles about a free product.</p>
<p>You can download <a href="http://xtravirt.com/xd10130">vAlarm from XtraVirt</a> (free registration required).</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/10/xtravirts-valarm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vCenter and Host Build Numbers</title>
		<link>http://ben.neise.co.uk/index.php/2009/10/vcenter-and-host-build-numbers/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/10/vcenter-and-host-build-numbers/#comments</comments>
		<pubDate>Fri, 02 Oct 2009 09:53:07 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Powershell Script]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[vCenter]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=270</guid>
		<description><![CDATA[Script to loop through the list of vCenter servers, and gets their version and build info, as well as the version and build info for it's connected hosts.]]></description>
			<content:encoded><![CDATA[<p>This is based on <a href="http://communities.vmware.com/message/1013433#1013433">Carter Shanklin&#8217;s PowerShell snippets to query VC and ESX build version numbers</a>.</p>
<p>This script loops through the list of vCenter servers, and gets their version and build info, as well as the version and build info for it&#8217;s connected hosts.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Script to connect to a list of vCenter Servers, and get their version numbers, as well as the version numbers of their hosts</span>
<span style="color: #008000;"># Ben Neise</span>
<span style="color: #008000;"># 02/10/09</span>
&nbsp;
<span style="color: #008000;"># Array of vCenter Servers</span>
<span style="color: #800080;">$arrVCenterServers</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;server1&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;server2&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;server3&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Create empty arrays for the results</span>
<span style="color: #800080;">$arrTableVCs</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$arrTableHosts</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Loop through the array of vCenter servers specified above</span>
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$strVCenterServer</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$arrVCenterServers</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Connect to the VC</span>
	<span style="color: #800080;">$objVCenterServer</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$strVCenterServer</span>
	<span style="color: #008000;"># Version info about the VC you are connected to</span>
	<span style="color: #800080;">$viewVCenterServer</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View serviceinstance
	<span style="color: #008000;"># Add custom attributes to each VC objects for version and build</span>
	<span style="color: #800080;">$objVCenterServer</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Add-Member</span> <span style="color: #008080; font-style: italic;">-Name</span> Version <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">type</span> noteproperty <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$viewVCenterServer</span>.content.about.Version<span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-Force</span>
	<span style="color: #800080;">$objVCenterServer</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Add-Member</span> <span style="color: #008080; font-style: italic;">-Name</span> Build <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">type</span> noteproperty <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$viewVCenterServer</span>.content.about.Build<span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-Force</span>
	<span style="color: #008000;"># Add the VC object to the results array</span>
	<span style="color: #800080;">$arrTableVCs</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$objVCenterServer</span>
	<span style="color: #008000;"># When connected to loop through the hosts managed by the VC</span>
	<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$objHost</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMhost <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort-Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Get the view for the current host</span>
		<span style="color: #800080;">$viewHost</span> <span style="color: pink;">=</span> <span style="color: #800080;">$objHost</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>View
		<span style="color: #008000;"># Add custom attributes to the host object for VC server, Host and Version</span>
		<span style="color: #800080;">$objHost</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Add-Member</span> <span style="color: #008080; font-style: italic;">-Name</span> VCServer <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">type</span> noteproperty <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$objVCenterServer</span>.Name <span style="color: #008080; font-style: italic;">-Force</span>
		<span style="color: #800080;">$objHost</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Add-Member</span> <span style="color: #008080; font-style: italic;">-Name</span> Host <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">type</span> noteproperty <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$viewHost</span>.Name <span style="color: #008080; font-style: italic;">-Force</span>
		<span style="color: #800080;">$objHost</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Add-Member</span> <span style="color: #008080; font-style: italic;">-Name</span> Version <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">type</span> noteproperty <span style="color: #008080; font-style: italic;">-value</span> <span style="color: #800080;">$viewHost</span>.Config.Product.Version <span style="color: #008080; font-style: italic;">-Force</span>
		<span style="color: #008000;"># Add the host object to the results array</span>
		<span style="color: #800080;">$arrTableHosts</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$objHost</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #008000;"># Disconnect from the VC server</span>
	Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #008080; font-style: italic;">-Confirm</span>:<span style="color: #800080;">$False</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;"># Output the VC results (can be modified to output to a CSV with Export-CSV)</span>
<span style="color: #800080;">$arrTableVCs</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> Name<span style="color: pink;">,</span> Version<span style="color: pink;">,</span> Build <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort-Object</span> Name
&nbsp;
<span style="color: #008000;"># Output the Host results (can be modified to output to a CSV with Export-CSV)</span>
<span style="color: #800080;">$arrTableHosts</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> VCServer<span style="color: pink;">,</span> Host<span style="color: pink;">,</span> Version<span style="color: pink;">,</span> Build <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-Table</span>
&nbsp;
<span style="color: #008000;"># End of script</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/10/vcenter-and-host-build-numbers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell script to add a hash table full of virtual port groups to vSphere hosts</title>
		<link>http://ben.neise.co.uk/index.php/2009/09/powershell-script-to-add-a-hash-table-full-of-virtual-port-groups-to-vsphere-hosts/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/09/powershell-script-to-add-a-hash-table-full-of-virtual-port-groups-to-vsphere-hosts/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 11:45:27 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Powershell Script]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[hash tables]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[vCenter]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=259</guid>
		<description><![CDATA[PowerShell script to add a hash table full of virtual port groups to vSphere hosts
]]></description>
			<content:encoded><![CDATA[<p>As part of the migration I&#8217;m working on, we needed to add a whole bunch of Virtual Port Groups with associated VLANs to the servers. The following script could do this in a few minutes (although Host Profiles would accomplish much the same thing, we&#8217;re not running Enterprise)</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Sets up virtual port groups on all hosts connected to a specific vCenter Server</span>
&nbsp;
<span style="color: #008000;"># Name of vCenter Server</span>
<span style="color: #800080;">$strVCenterServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;your.vCenter.Server&quot;</span>
&nbsp;
<span style="color: #008000;"># VLANs and associated VPGs</span>
<span style="color: #800080;">$ArrVLANs</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>
	<span style="color: #800000;">&quot;123&quot;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Admin&quot;</span>;
	<span style="color: #800000;">&quot;456&quot;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;GPO&quot;</span>;
	<span style="color: #800000;">&quot;789&quot;</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;NAG&quot;</span>;
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Connect to the vCenter Server</span>
Connect<span style="color: pink;">-</span>VIserver <span style="color: #800080;">$strVCenterServer</span>
&nbsp;
<span style="color: #008000;"># Loop through the VLAN/VPG pairs</span>
<span style="color: #0000FF;">ForEach</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$objVLAN</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$ArrVLANs</span>.Keys <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort-Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Loop through the hosts</span>
	<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$objHost</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMHost <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort-Object</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Create the VPG with the VLAN as specified in the array above, on the switch called &quot;VMSwitch&quot; on the current host</span>
		<span style="color: #008000;"># Remove the &quot;-WhatIf&quot; tag from the end of the following line to &quot;arm&quot; the script</span>
		New<span style="color: pink;">-</span>VirtualPortGroup <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$strNewVPG</span> <span style="color: pink;">-</span>VirtualSwitch <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>Virtualswitch <span style="color: pink;">-</span>VMHost <span style="color: #800080;">$objHost</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span> <span style="color: #000080;">$_</span>.Name <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;VMswitch&quot;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span>VLanId <span style="color: #800080;">$strNewVlanTag</span> <span style="color: #008080; font-style: italic;">-WhatIf</span>
		<span style="color: #008000;"># Write what we've just done to screen</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Adding Virtual Port Group&quot;</span> <span style="color: #800080;">$ArrVLANs</span><span style="color: #000000;">&#91;</span><span style="color: #800080;">$objVLAN</span><span style="color: #000000;">&#93;</span> <span style="color: #800000;">&quot;with VLAN Tag&quot;</span> <span style="color: #800080;">$objVLAN</span> <span style="color: #800000;">&quot;to&quot;</span> <span style="color: #800080;">$objHost</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008000;"># Disconnect the session from the host</span>
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #008080; font-style: italic;">-Confirm</span>:$False</pre></div></div>

<p>Although this isn&#8217;t a complicated script, it was the first time I&#8217;ve used hash tables (thanks to <a href="http://powershell.com/cs/blogs/ebook/archive/2008/10/22/chapter-4-arrays-and-hashtables.aspx">PowerShell.Com&#8217;s excellent page</a>), so I thought I&#8217;d share.</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/09/powershell-script-to-add-a-hash-table-full-of-virtual-port-groups-to-vsphere-hosts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thin Provisioning in ESX 3.5</title>
		<link>http://ben.neise.co.uk/index.php/2009/05/thin-provisioning-in-esx-35/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/05/thin-provisioning-in-esx-35/#comments</comments>
		<pubDate>Wed, 06 May 2009 11:45:57 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[vCenter]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=142</guid>
		<description><![CDATA[Feasibility of using undocumented thin-provisioning functionality in VI 3.5 to reduce storage requirements.]]></description>
			<content:encoded><![CDATA[<p>One of the nice new features of vSphere 4 is thin provisioning of virtual disks. Thin provisioned (TP) disks will be familiar if you&#8217;ve ever used VMware Workstation where they are used by default, (you need to select <em>Allocate All Disk Space Now</em> to create thick disks). Essentially, rather than allocate all disk space at creation, disk space is allocated on the fly, meaning that a 50GB virtual disk with only 5GB being used by the guest, would only consume 5GB of space. This can obviously result in real savings, but it does have an impact on machine performance due to the increased disk provisioning overhead as the machine grows.</p>
<p>VirtualGeek had an interesting article on <a href="http://virtualgeek.typepad.com/virtual_geek/2009/04/thin-on-thin-where-should-you-do-thin-provisioning-vsphere-40-or-array-level.html">thin-provisioning in vSphere 4, and whether this should be done at the VM level, or at the array level</a>. As well as containing a good description of the different disk types (<em>Thick</em>, <em>Thin </em>&amp; <em>Eagerzeroedthick</em>), there was a brief mention of using TP disks in VI 3.5. This was the first time I&#8217;d heard of this, and despite it&#8217;s unsupported nature, it deserved some consideration. We&#8217;re still using VI 3.5, and disk space is probably our number one capacity constraint; the potential opportunity to reduce our disk-footprint without investing in any new hardware or software was too good to pass up.</p>
<p>I soon discovered that we already used TP disks in a very limited way. One of the options in vCenter&#8217;s <em>Clone to Template</em> operation allows the creation of a <em>compact</em> template, and we had been using this to reduce the amount of space used by templates. Templates created in this manner use TP disks, and if you convert that template to a machine, the machine inherits the TP disk. However VMs deployed from the template are created with normal (thick) disks. If you&#8217;re curious to see if you&#8217;ve got any existing TP machines, Eric Gray wrote a <a href="http://www.vcritical.com/2009/01/finding-thin-provisioned-virtual-disks-with-powershell/#more-514">PowerShell script to find existing thin provisioned disks</a>.</p>
<p>After only a little more digging, my dream of being lauded for increasing our free space overnight came to an end. In an article on <a href="http://virtualfuture.info/2008/12/vmware-esx-35-and-thinprovisioning/">Virtual Future</a>, Sven Huisman wrote:</p>
<blockquote>
<p style="text-align: left;">Apparently, when you move a VM with a thinprovisioned disk from vCenter server, it converts to a thick-disk. This is because thinprovisioned disks is not integrated with vCenter server yet.</p>
<p style="text-align: left;">Also, when you deploy from a template with a thinprovisioned disk, the new VM will get a thick-disk.</p>
</blockquote>
<p style="text-align: left;">I imagine this is what they mean by &#8220;unsupported&#8221;, and this is why the TP functionality in VI 3.5 is largely undocumented.</p>
<p style="text-align: left;">This changes the conversion process from a one-off time-consuming action to something that would need to be done on an ongoing basis. I think we&#8217;ll just have to wait until we get the chance to upgrade to vSphere 4.</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/05/thin-provisioning-in-esx-35/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMware vCenter server preview video</title>
		<link>http://ben.neise.co.uk/index.php/2009/04/vmware-vcenter-server/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/04/vmware-vcenter-server/#comments</comments>
		<pubDate>Mon, 27 Apr 2009 12:25:12 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[vCenter]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=93</guid>
		<description><![CDATA[VMware vCenter Server Video from vCritical showing installation and GUI on the new vCenter.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.youtube.com/watch?v=oKLotQGgVGM">VMware vCenter Server</a></p>
<p>Video from vCritical showing installation and GUI on the new vCenter.</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/04/vmware-vcenter-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VMware VCenter Remote Access</title>
		<link>http://ben.neise.co.uk/index.php/2009/03/vmware-vcenter-remote-access/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/03/vmware-vcenter-remote-access/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 12:06:11 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[vCenter]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=75</guid>
		<description><![CDATA[Remotely accessing ESX Guests on an (emulated) portable device.  If only I could convince work to get me a BlackBerry it would free me from my desk. The only problem being; I&#8217;m not entirely sure where I would go instead.]]></description>
			<content:encoded><![CDATA[<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="350" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="data" value="http://www.youtube.com/v/9UxDnV2qaeM" /><param name="src" value="http://www.youtube.com/v/9UxDnV2qaeM" /><embed type="application/x-shockwave-flash" width="425" height="350" src="http://www.youtube.com/v/9UxDnV2qaeM" data="http://www.youtube.com/v/9UxDnV2qaeM"></embed></object></p>
<p>Remotely accessing ESX Guests on an (emulated) portable device.  If only I could convince work to get me a BlackBerry it would free me from my desk.</p>
<p>The only problem being; I&#8217;m not entirely sure where I would go instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/03/vmware-vcenter-remote-access/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to using VMware vSphere PowerCLI</title>
		<link>http://ben.neise.co.uk/index.php/2009/03/intro-to-powercli/</link>
		<comments>http://ben.neise.co.uk/index.php/2009/03/intro-to-powercli/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 10:33:06 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Powershell Script]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Script]]></category>
		<category><![CDATA[vCenter]]></category>
		<category><![CDATA[VI Toolkit]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://ben.neise.co.uk/?p=46</guid>
		<description><![CDATA[An introduction to using VMware PowerCLI to manage virtual machines.]]></description>
			<content:encoded><![CDATA[<p>About 2 years ago, I moved from working as an application packager, and being responsible for two or three (VMware Workstation) virtual machines, to working on the supporting infrastructure for over 200 packagers who require around 700 virtual machines on VMware vSphere (which was at that point called VMware ESX).</p>
<p>While I was (and I still am) impressed by VMware&#8217;s hypervisor based virtualisation, there were a few things that started to grate with such an otherwise excellent product:-</p>
<ul>
<li>Performing repetitive tasks &#8211; for example setting a group of virtual hard-drives to non-persistent &#8211; using the vSphere Client GUI was time-consuming (and RSI inducing!).</li>
<li>There was also no real way of extracting information from vCenter in any structured way. For example, if I wanted to know how many of our Microsoft Windows XP guests had over 512MB RAM allocated to them, they had to be counted manually.</li>
</ul>
<p>I had a look into <a href="http://www.amazon.com/Scripting-VMware-Power-Tools-Infrastructure/dp/1597490598">running scripts on the host</a>, and toyed with the <a href="http://www.vmware.com/download/vi/drivers_tools.html">Remote CLI Appliance</a>, but it was the <a href="http://communities.vmware.com/community/vmtn/vsphere/automationtools/windows_toolkit">VMware PowerCLI</a> that unlocked the functionality I&#8217;d been looking for.</p>
<p>VMware <a href="http://communities.vmware.com/community/vmtn/vsphere/automationtools/windows_toolkit">PowerCLI</a> (formerly VI Toolkit for Windows)  utilises <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx">Windows PowerShell </a>to provide a command-line driven interface for your virtual infrastructure. This can dramatically reduce the amount of time taken to perform almost all batch-style tasks and also enables some pretty advanced reporting functionality.</p>
<p>This is nowhere near a proper introduction in how to use PowerShell, but should give enough information to get you started, and hopefully make you want to find out more.</p>
<h2>PowerCLI pre-requisites</h2>
<p>Powershell is included in Windows 7, and Server 2008, but if it&#8217;s not included in your version of Windows, you&#8217;ll need to  <a href="http://support.microsoft.com/kb/968930" target="_blank">download and install the appropriate version of Windows PowerShell</a> for your operating system.</p>
<p>Then you need to <a href="http://www.vmware.com/support/developer/PowerCLI/index.html" target="_blank">download and install VMware vSphere PowerCLI</a> (registration required).</p>
<p>If you&#8217;re running  PowerShell for the first time you need to change the default execution policy.  To do this:</p>
<ol>
<ol>
<li>As a user with local Administrator rights, run Windows PowerShell  (on machines with <a href="http://en.wikipedia.org/wiki/User_Account_Control" target="_blank">UAC</a>, right-click and <strong>Run as Administrator</strong>)</li>
<li>In that window &#8211; run the command</li>
</ol>
</ol>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Set-ExecutionPolicy</span> <span style="color: pink;">-</span> ExecutionPolicy RemoteSigned</pre></div></div>

<p style="padding-left: 30px;">This allows you to run local scripts which have not been signed with a digital signature (which will almost certainly include the scripts you&#8217;re using to learn). Scripts from remote sources will still require signing.</p>
<h2>Security considerations</h2>
<p>The PowerShell security model is designed to address some of the  failures of VBScript &#8211; a common virus attack vector. PowerShell scripts (which have a PS1 suffix) do not run by default when invoked in Windows.  Also, as noted above, the default execution policy is not to run unsigned scripts. In order to run a script, you need to modify the execution policy, and then run the script name from the command line. This helps to prevent them from being launched by accident.</p>
<p>In vSphere, users running PowerCLI scripts  have the same permissions as they would get if they logged into vSphere Client. However, as with all scripting languages,  when modifications can be  made easier and faster, the potential impact of mistakes is made greater. PowerShell includes <a href="http://www.computerperformance.co.uk/powershell/powershell_whatif_confirm.htm">specific measures to alleviate risk</a>, and it&#8217;s worth being familiar with this functionality before trying anything more complex.</p>
<h2>PowerShell fundamentals</h2>
<p>PowerShell works using <em>cmdlets</em>. These are typically fairly descriptive, and great care has been taken to make them work in a consistent and logical way. Most cmdlets follow the format verb-noun, with modifiers for the target of the action, and any cmdlet specific options. They are not case sensitive.</p>
<p>The downside of the commands being so descriptive is that they are sometimes quite long. In order to alleviate this PowerShell allows Aliases to be created. Most common Windows Shell commands already exist in PowerShell as aliases. For example <strong>CD</strong>, <strong>DIR</strong>, <strong>CLS </strong>&amp; <strong>REN </strong>all work as expected. I find these quite useful when working interactively (entering commands at the prompt for immediate execution), but I tend to avoid them in scripts for the sake of consistency and clarity.</p>
<p>When launching scripts, you need to use absolute paths. For example, if you want to launch the script <strong>C:\Scripts\ExampleScript.ps1</strong>, when you&#8217;re in <strong>C:\Scripts</strong> you would either need to enter the whole path, or use  <strong>./ExampleScript.ps1.</strong></p>
<p>In order to use PowerShell, you need to import the VI commands using</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</pre></div></div>

<p>Running the VMware vSphere PowerCLI shortcut created when you install the application does this on launch.</p>
<p><img class="alignnone size-full wp-image-225" title="PowerCLI_Shortcut" src="http://ben.neise.co.uk/wp-content/uploads/2009/03/PowerCLI_Shortcut1.png" alt="PowerCLI_Shortcut" width="46" height="44" /></p>
<p>Running the standard PowerShell shortcut does not.</p>
<p><img class="alignnone size-full wp-image-226" title="PowerShell_Icon" src="http://ben.neise.co.uk/wp-content/uploads/2009/03/PowerShell_Icon.png" alt="PowerShell_Icon" width="47" height="42" /></p>
<p>You can however add it to your <a href="http://www.howtogeek.com/50236/customizing-your-powershell-profile/" target="_blank">PowerShell profile</a>, which will enable it in all PowerShell sessions, no matter which shortcut you use to launch them.</p>
<p>PowerShell is object-oriented, meaning that the information returned from commands can be easily used as the input for another command.</p>
<p>If you want to put comments into your scripts, PowerShell ignores anything after the <strong>#</strong>symbol.</p>
<h2>Some simple Cmdlets</h2>
<p>Here are a couple of commands to get you started. Open up the PowerCLI command line using the VMware vSphere PowerCLI shortcut, then enter them as shown.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Help</span></pre></div></div>

<p>Can display help on the various cmdlets. Running this as above shows the syntax for getting help.</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Command</span></pre></div></div>

<p>Use to find out all the commands containing certain keywords. For example&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Command</span> <span style="color: pink;">*-</span>VM</pre></div></div>

<p>&#8230;uses the wildcard character (*) to show all commands that end with VM, this shows all the  cmdlets that can be used to operate on Virtual Machines. Let&#8217;s try a simple one&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>VM</pre></div></div>

<p>You should now get an error message saying &#8220;<em>You are not currently connected to any servers. Please connect first using Connect-VIServer or one of its aliases</em>.&#8221;. Let&#8217;s do that&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Connect<span style="color: pink;">-</span>VIServer Name_of_your_vCenter_Server</pre></div></div>

<p>This uses your current windows credentials to connects to the specified server.  You need to do this before you run any VMware specific PowerShell commands. Now try this again&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>VM</pre></div></div>

<p>You should now be looking at a list of virtual machines managed by your vCenter server.  You can reduce the scope by adding switches, for example&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>VM –Name A<span style="color: pink;">*</span></pre></div></div>

<p>&#8230;gets all machines with names starting “A”. For more information, try</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008080; font-weight: bold;">Get-Help</span> Get<span style="color: pink;">-</span>VM <span style="color: #008080; font-style: italic;">-Detailed</span></pre></div></div>

<p>Variables in PowerShell are always preceded by a $ symbol. You can set a variable to the result of any kind of PowerShell command, for example, you can store the results of a Get-VM in a variable&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$objVMs</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VM</pre></div></div>

<p>then use that variable any time you need it, typing</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">$objVMs</pre></div></div>

<p>Will display the virtual machine objects stored in the variable. This variable is a collection of objects, each object representing a virtual machine, so we can run more commands against this variable:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>VMGuest <span style="color: pink;">-</span>VM $objVMs</pre></div></div>

<p>This lists the State, IP Address and guest OS of all your machine objects.</p>
<p>Instead of using variables for commands like this, you can also pipe the result of one command, straight into another. The equivalent of the above command, using pipes rather than variables is</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">Get<span style="color: pink;">-</span>VM <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>VMGuest</pre></div></div>

<p>The objects output byt he first command are piped straight into the second command. Pipes are used extensively in PowerShell, and many cmdlets can be linked together using pipes. This means you can run some complex commands in PowerShell at the command prompt in one line, rather than resorting to writing a script.</p>
<p>Have a  play around with these commands in your test environment before moving onto the next section. As long as you&#8217;re using <strong>Get-</strong> based commands, (rather than <strong>Set-</strong> or <strong>Remove-</strong>) you shouldn&#8217;t make any changes, but append <strong>-WhatIf</strong> and/or <strong>-Confirm</strong> to the end of your Cmdlets if you&#8217;re feeling extra-cautious.</p>
<h2>Example scripts</h2>
<p>Like batch files, PowerShell scripts are simply collections of commands linked together into a text file.</p>
<p>Here are a couple of example scripts, showing what can be done.  Copy into notepad, and save with a PS1 extension. You should run <strong>Connect-VIServer</strong> interactively before running any of the scripts (or add it as the first line to the script file).</p>
<h3>Get information about a specific machine</h3>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$strVm</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;Please enter the VM name&quot;</span>
<span style="color: #800080;">$vm</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VM <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$strVm</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span>.PowerState <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;PoweredOn&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
<span style="color: #800080;">$event</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VIEvent <span style="color: pink;">-</span>Entity <span style="color: #800080;">$vm</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.fullFormattedMessage <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;Task: Power on Virtual Machine&quot;</span><span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$VM</span>.Name
<span style="color: #800080;">$VM</span>.PowerState
<span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMGuest <span style="color: pink;">-</span>VM <span style="color: #800080;">$VM</span><span style="color: #000000;">&#41;</span>.IPAddress<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$event</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">Set-Variable</span> <span style="color: #008080; font-style: italic;">-Name</span> user <span style="color: #008080; font-style: italic;">-Value</span> <span style="color: #800000;">&quot;N/A&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span> <span style="color: #008080; font-weight: bold;">Set-Variable</span> <span style="color: #008080; font-style: italic;">-Name</span> user <span style="color: #008080; font-style: italic;">-Value</span> <span style="color: #800080;">$event</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.username <span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$strMessageText</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Machine: &quot;</span> <span style="color: pink;">+</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;">`n</span>&quot;</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;Power State: &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$VM</span>.PowerState <span style="color: pink;">+</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;IP Address: &quot;</span> <span style="color: pink;">+</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMGuest <span style="color: pink;">-</span>VM <span style="color: #800080;">$VM</span><span style="color: #000000;">&#41;</span>.IPAddress<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span> <span style="color: pink;">+</span> <span style="color: #800000;">&quot;Switched on by: &quot;</span> <span style="color: pink;">+</span> <span style="color: #800080;">$user</span>
<span style="color: #800080;">$strMessageText</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">else</span>
<span style="color: #000000;">&#123;</span><span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Machine not powered on&quot;</span><span style="color: #000000;">&#125;</span></pre></div></div>

<p>This script asks the user for a machine name (using <strong>Read-Host</strong>), then converts that string to a computer object, then (assuming the machine is switched on and VMware Tools is running), displays the DNS name, IP address and the username of the last user to power on the machine (as shown in the machine&#8217;s Event Log). The <strong>`n</strong> is a carriage return.</p>
<h3>Get All Windows XP Machines with more than 2Gb of RAM</h3>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$strMachine</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>get<span style="color: pink;">-</span>vm <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.MemoryMB <span style="color: #FF0000;">-gt</span> <span style="color: #800000;">&quot;2000&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span>
Get<span style="color: pink;">-</span>VMGuest <span style="color: pink;">-</span>VM <span style="color: #800080;">$strMachine</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.OSFullName <span style="color: #FF0000;">-like</span> <span style="color: #800000;">&quot;Microsoft Windows XP Professional*&quot;</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> VMName<span style="color: pink;">,</span> IPAddress
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>This script could easily be modified and used as a component to make modifications on machines fulfilling certain criteria.</p>
<h2>What else can you do?</h2>
<p>Almost anything that can be done in the GUI can be done in PowerShell.  Machines can be deployed, customized, switched on, migrated between hosts and resource pools etc. Or you could get the last time a machine was switched on, and by whom.</p>
<p>You can also use PowerCLI to report on the status of guests and hosts. Check out Alan Renouf&#8217;s excellent <a href="http://www.virtu-al.net/2009/08/18/powercli-daily-report-v2/">PowerCLI Daily Report</a>, or Hugo Peeter&#8217;s script to <a href="http://www.peetersonline.nl/index.php/vmware/track-datastore-free-space/">track free space in your datastores</a>.</p>
<p>One drawback of the API is that performance of cmdlets (especially <strong>Get-VM</strong>) is quite slow.  Hopefully this will be addressed in future versions.</p>
<h2>Further resources</h2>
<p>There are many tools, example scripts and on-line resources available. Your first stop for help should be the <a href="http://communities.vmware.com/community/vmtn/vsphere/automationtools/windows_toolkit">VMware vSphere PowerCLI Community</a>. I also recommend you keep <a href="http://www.virtu-al.net/2009/05/17/icomasoft-powercli-reference-card/">Alan Renouf&#8217;s PowerCLI reference card</a> close-to-hand when you&#8217;re just starting out.</p>
]]></content:encoded>
			<wfw:commentRss>http://ben.neise.co.uk/index.php/2009/03/intro-to-powercli/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

