<?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>Tech Llama &#187; PowerCLI</title>
	<atom:link href="http://tech.lazyllama.com/tag/powercli/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.lazyllama.com</link>
	<description>Lazyllama&#039;s Technology Pages</description>
	<lastBuildDate>Sat, 14 Jan 2012 21:12:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>vSphere PowerCLI: Moved your ISO datastore ? Reconnecting your CD-ROM drives</title>
		<link>http://tech.lazyllama.com/2011/07/28/vsphere-powercli-moved-your-iso-datastore-reconnecting-your-cd-rom-drives/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=vsphere-powercli-moved-your-iso-datastore-reconnecting-your-cd-rom-drives</link>
		<comments>http://tech.lazyllama.com/2011/07/28/vsphere-powercli-moved-your-iso-datastore-reconnecting-your-cd-rom-drives/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 11:18:03 +0000</pubDate>
		<dc:creator>lazyllama</dc:creator>
				<category><![CDATA[VMware]]></category>
		<category><![CDATA[ISO]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://tech.lazyllama.com/?p=130</guid>
		<description><![CDATA[We recently moved our ISO store from a legacy NFS server to our main NFS filer. The first task was copying the actual files, which can be done via any machine that has both datastores mounted (with read-write access to the destination store). The more significant job is reconfiguring the VMs to use the copies [...]]]></description>
			<content:encoded><![CDATA[<p>We recently moved our ISO store from a legacy NFS server to our main NFS filer.</p>
<p>The first task was copying the actual files, which can be done via any machine that has both datastores mounted (with read-write access to the destination store).</p>
<p>The more significant job is reconfiguring the VMs to use the copies of the ISOs in the new datastore.</p>
<p>Here&#8217;s the PowerCLI script I used:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#</span>
<span style="color: #008000;"># Disconnect all CD/DVD ISOs on a particular datastore and reconnect them to the new datastore</span>
<span style="color: #008000;">#</span>
<span style="color: #800080;">$myvcenter</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;myvcenter.host.net&quot;</span>
<span style="color: #800080;">$mydatacenter</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;BigDC1&quot;</span>
<span style="color: #800080;">$originalISOstore</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;MyFirstISOstore&quot;</span>
<span style="color: #800080;">$finalISOstore</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;MuchBetterISOstore&quot;</span>
&nbsp;
Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$myvcenter</span>
&nbsp;
<span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VM <span style="color: pink;">-</span>Location: <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>Datacenter <span style="color: #800080;">$mydatacenter</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span> <span style="color: #000080;">$_</span> <span style="color: #000000;">&#41;</span> 
	<span style="color: #000000;">&#123;</span> 
	<span style="color: #800080;">$myDrive</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>CDDrive <span style="color: #000080;">$_</span>
	<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$myDrive</span>.IsoPath <span style="color: #FF0000;">-match</span> <span style="color: #800000;">&quot;\[&quot;</span><span style="color: pink;">+</span><span style="color: #800080;">$originalISOstore</span><span style="color: pink;">+</span><span style="color: #800000;">&quot;\]&quot;</span><span style="color: #000000;">&#41;</span> 
		<span style="color: #000000;">&#123;</span>
		Set<span style="color: pink;">-</span>CDDrive <span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">CD</span> <span style="color: #800080;">$myDrive</span> <span style="color: pink;">-</span>IsoPath <span style="color: #000000;">&#40;</span><span style="color: #800080;">$myDrive</span>.IsoPath <span style="color: #FF0000;">-replace</span> <span style="color: #800080;">$originalISOstore</span><span style="color: pink;">,</span> <span style="color: #800080;">$finalISOstore</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-Confirm</span>:<span style="color: #800080;">$false</span>  
		<span style="color: #000000;">&#125;</span> 
	<span style="color: #000000;">&#125;</span>
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$myvcenter</span> <span style="color: #008080; font-style: italic;">-confirm</span>:$false</pre></td></tr></table></div>

<p>It&#8217;s fairly self-explanatory. </p>
<p>The biggest caveat with this is that it assumes that the source and destination stores have the same structure, but it wouldn&#8217;t be difficult to amend it to change the destination path slightly.</p>
<div id="tweetbutton130" class="tw_button" style="float:left;margin-right:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Ftech.lazyllama.com%2F2011%2F07%2F28%2Fvsphere-powercli-moved-your-iso-datastore-reconnecting-your-cd-rom-drives%2F&amp;text=vSphere%20PowerCLI%3A%20Moved%20your%20ISO%20datastore%20%3F%20Reconnecting%20your%20CD-ROM%20drives&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Ftech.lazyllama.com%2F2011%2F07%2F28%2Fvsphere-powercli-moved-your-iso-datastore-reconnecting-your-cd-rom-drives%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://tech.lazyllama.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://tech.lazyllama.com/2011/07/28/vsphere-powercli-moved-your-iso-datastore-reconnecting-your-cd-rom-drives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add multiple datastores to multiple vSphere hosts</title>
		<link>http://tech.lazyllama.com/2010/09/17/add-multiple-datastores-to-multiple-vsphere-hosts/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=add-multiple-datastores-to-multiple-vsphere-hosts</link>
		<comments>http://tech.lazyllama.com/2010/09/17/add-multiple-datastores-to-multiple-vsphere-hosts/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 14:33:35 +0000</pubDate>
		<dc:creator>lazyllama</dc:creator>
				<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://tech.lazyllama.com/?p=78</guid>
		<description><![CDATA[In large vSphere environments it can be very tedious to add multiple NFS datastores to lots of hosts. PowerCLI comes to the rescue as usual. I needed to add some datastores to all the clustered hosts in a single datacenter, but to skip our non-clustered standalone hosts which are used for backups. A bit of [...]]]></description>
			<content:encoded><![CDATA[<p>In large vSphere environments it can be very tedious to add multiple NFS datastores to lots of hosts.<br />
PowerCLI comes to the rescue as usual.</p>
<p>I needed to add some datastores to all the clustered hosts in a single datacenter, but to skip our non-clustered standalone hosts which are used for backups.</p>
<p>A bit of PowerCLI which should be fairly self-explanatory:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#</span>
<span style="color: #008000;">#  Add Datastores to all hosts in all clusters in a specified datacenter</span>
<span style="color: #008000;">#  If a host isn't in a cluster it won't get the datastore</span>
<span style="color: #008000;">#  Easy enough to change to do all hosts in a datacenter, all in vCenter etc</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;">#  Change the value below to point it to your own vCenter</span>
<span style="color: #800080;">$myvCenter</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;vcenter.example.com&quot;</span>
&nbsp;
<span style="color: #008000;"># Array of arrays below holds NFS-hostname, NFS-path and Datastore name, should be easy to add to</span>
<span style="color: #800080;">$nfsArray</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span>
			  <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;nfsserver1&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;/vol/nfspath1&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;VMstore1&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
			  <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;nfsserver2&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;/vol/nfspath2&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;VMstore2&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
			  <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;nfsserver3&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;/vol/nfspath3&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;VMstore3&quot;</span><span style="color: #000000;">&#41;</span>
			 <span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #800080;">$datacenter</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #008080; font-style: italic;">-Prompt</span> <span style="color: #800000;">&quot;Datacenter name&quot;</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Datacenter is $datacenter&quot;</span>
&nbsp;
connect<span style="color: pink;">-</span>viserver <span style="color: pink;">-</span>server <span style="color: #800080;">$myvCenter</span>
&nbsp;
<span style="color: #008000;">#</span>
<span style="color: #008000;"># Get all hosts in all clusters in the named datacenter</span>
<span style="color: #800080;">$ObjAllHosts</span> <span style="color: pink;">=</span> get<span style="color: pink;">-</span>datacenter <span style="color: #008080; font-style: italic;">-name</span> <span style="color: #800080;">$datacenter</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>Cluster  <span style="color: pink;">|</span>  Get<span style="color: pink;">-</span>VMHost 
&nbsp;
<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: #800080;">$ObjAllHosts</span><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;">$nfsItem</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$nfsArray</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span>
&nbsp;
      <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Adding datastore&quot;</span> <span style="color: #800080;">$nfsItem</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: #800000;">&quot;with path&quot;</span> <span style="color: #800080;">$nfsItem</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: #800080;">$nfsItem</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #800000;">&quot;to&quot;</span> <span style="color: #800080;">$objHost</span>
      New<span style="color: pink;">-</span>Datastore <span style="color: pink;">-</span>Nfs <span style="color: pink;">-</span>NfsHost <span style="color: #800080;">$nfsItem</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$nfsItem</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$nfsItem</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">-</span>VMHost <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMHost <span style="color: #800080;">$objHost</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
disconnect<span style="color: pink;">-</span>viserver <span style="color: pink;">-</span>server <span style="color: #800080;">$myvCenter</span> <span style="color: #008080; font-style: italic;">-Confirm</span>:$false</pre></td></tr></table></div>

<div id="tweetbutton78" class="tw_button" style="float:left;margin-right:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Ftech.lazyllama.com%2F2010%2F09%2F17%2Fadd-multiple-datastores-to-multiple-vsphere-hosts%2F&amp;text=Add%20multiple%20datastores%20to%20multiple%20vSphere%20hosts&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Ftech.lazyllama.com%2F2010%2F09%2F17%2Fadd-multiple-datastores-to-multiple-vsphere-hosts%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://tech.lazyllama.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://tech.lazyllama.com/2010/09/17/add-multiple-datastores-to-multiple-vsphere-hosts/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Passing info from PowerCLI into your VM using guestinfo variables</title>
		<link>http://tech.lazyllama.com/2010/06/22/passing-info-from-powercli-into-your-vm-using-guestinfo-variables/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=passing-info-from-powercli-into-your-vm-using-guestinfo-variables</link>
		<comments>http://tech.lazyllama.com/2010/06/22/passing-info-from-powercli-into-your-vm-using-guestinfo-variables/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 11:22:42 +0000</pubDate>
		<dc:creator>lazyllama</dc:creator>
				<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerCLI]]></category>

		<guid isPermaLink="false">http://tech.lazyllama.com/?p=37</guid>
		<description><![CDATA[For a project at work we&#8217;ve been trying to pass information into a VM without connecting the VM to the network. This is in order to set up some config within both Windows and Linux VMs. We decided to explore the use of GuestInfo variables which are held in memory in VMware Tools within the [...]]]></description>
			<content:encoded><![CDATA[<p>For a project at work we&#8217;ve been trying to pass information into a VM without connecting the VM to the network.<br />
This is in order to set up some config within both Windows and Linux VMs. We decided to explore the use of GuestInfo variables which are held in memory in VMware Tools within the Guest VM, but which can be set from the host.</p>
<p>From the ESX Service Console of the host you can use<br />
<code>vmware-cmd &lt;cfgfile&gt; setguestinfo &lt;variable&gt; &lt;value&gt;<br />
</code> to set a value and <code>vmware-cmd &lt;cfgfile&gt; getguestinfo &lt;variable&gt;</code> to read the value. Note that you don&#8217;t need to use the &#8220;guestinfo.&#8221; prefix when using these commands.</p>
<p>Within the VM guest OS the values can be set/read using:<br />
<em>(Windows)</em><br />
<code>vmtoolsd.exe --cmd "info-set guestinfo.&lt;variable&gt; &lt;value&gt;"<br />
vmtoolsd.exe --cmd "info-get guestinfo.&lt;variable&gt;"</code>(vmtoolsd.exe is usually in C:\Program Files\VMware\VMware Tools)</p>
<p><em>(Linux)</em><br />
<code>vmware-guestd --cmd "info-set guestinfo.&lt;variable&gt; &lt;value&gt;"<br />
vmware-guestd --cmd "info-get guestinfo.&lt;variable&gt;"</code>(vmware-guestd is usually in /usr/sbin)</p>
<p>It wasn&#8217;t immediately obvious where the guestinfo variables live with regard to the PowerCLI vmConfig properties. Googling didn&#8217;t reveal much useful info, so I though I&#8217;d try the wonders of new technology and use Twitter. I&#8217;ve been following <a href="http://twitter.com/cshanklin">Carter Shanklin of VMware on Twitter</a> since I attended a London UK VMware User Group meeting a couple of months ago, and as he&#8217;s the Product Manager for PowerCLI and the SDK, I thought I&#8217;d ask.</p>
<p>He quickly pointed me at the VMware SDK documentation for the <a href="http://is.gd/cHhHI"><strong>ConfigInfo object</strong></a> and the <strong>extraConfig</strong> object in particular.</p>
<p>A bit of further reading led me to some experiments let me to try the following code:<br />
<code>$vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec<br />
$extra = New-Object VMware.Vim.optionvalue<br />
$extra.Key="guestinfo.test"<br />
$extra.Value="TestFromPCLI"<br />
$vmConfigSpec.extraconfig += $extra<br />
$vm =  Get-View -ViewType VirtualMachine | where { $_.name -eq "MyVMName" }<br />
$vm.ReconfigVM($vmConfigSpec) </code><br />
That will set the <strong>guestinfo.test</strong> property to <em>&#8220;TestFromPCLI&#8221;</em>. Once that&#8217;s been set it can be read by the VM.</p>
<p>The <strong>guestinfo</strong> property can have multiple Key/Value pairs so you can pass quite a few variables through to a VM. These can only be set when a VM is powered up and running VMware Tools as the value is stored in the VMs memory, and as far as I can tell, the contents are lost when the VM reboots.</p>
<p>However, there is another <strong>extraConfig</strong> object which can also be set which is the <strong>machine.id</strong>. Again this can be read from within the VM (replace <strong>guestinfo.</strong> with <strong>machine.id</strong> in the above code snippets), but this one gets written to the VMs VMX config file and will thus survive reboots.</p>
<p>You could squish several bits of info into that one object/variable, for example a unique identifier and the VM name so that the VM can self-configure.</p>
<div id="tweetbutton37" class="tw_button" style="float:left;margin-right:10px;"><a href="http://twitter.com/share?url=http%3A%2F%2Ftech.lazyllama.com%2F2010%2F06%2F22%2Fpassing-info-from-powercli-into-your-vm-using-guestinfo-variables%2F&amp;text=Passing%20info%20from%20PowerCLI%20into%20your%20VM%20using%20guestinfo%20variables&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Ftech.lazyllama.com%2F2010%2F06%2F22%2Fpassing-info-from-powercli-into-your-vm-using-guestinfo-variables%2F" class="twitter-share-button"  style="width:55px;height:22px;background:transparent url('http://tech.lazyllama.com/wp-content/plugins/wp-tweet-button/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;">Tweet</a></div>]]></content:encoded>
			<wfw:commentRss>http://tech.lazyllama.com/2010/06/22/passing-info-from-powercli-into-your-vm-using-guestinfo-variables/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

