<?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>PeetersOnline &#187; vSphere Client</title>
	<atom:link href="http://www.peetersonline.nl/index.php/tag/vsphere-client/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peetersonline.nl</link>
	<description>Using Powershell for (virtually) everything!</description>
	<lastBuildDate>Fri, 19 Aug 2011 09:22:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Add Vmx Path to VI Client using Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/add-vmx-path-to-vi-client-using-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/add-vmx-path-to-vi-client-using-powershell/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 08:56:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VI Toolkit 1.5]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[Custom Fields]]></category>
		<category><![CDATA[vSphere Client]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=415</guid>
		<description><![CDATA[The following script is a request from David Gontie, who was kind enough to comment on a previous post. He&#8217;d like to add the location of his vm&#8217;s to a custom field. This is especially handy if you store all the files for a vm in a single datastore. Here you go David: ############################## # Script <a href='http://www.peetersonline.nl/index.php/vmware/add-vmx-path-to-vi-client-using-powershell/'>[...]</a>
Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The following script is a request from David Gontie, who was kind enough to comment on a previous post.</p>
<p>He&#8217;d like to add the location of his vm&#8217;s to a custom field. This is especially handy if you store all the files for a vm in a single datastore.</p>
<p>Here you go David:</p>
<p><span id="more-415"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">##############################</span>
<span style="color: #008000;"># Script created by Hugo Peeters #</span>
<span style="color: #008000;"># http://www.peetersonline.nl   #</span>
<span style="color: #008000;">##############################</span>
&nbsp;
<span style="color: #008000;"># Variables</span>
<span style="color: #800080;">$VCServerName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;MYVCSERVER&quot;</span>
<span style="color: #800080;">$CustomFieldName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;VMX&quot;</span>
<span style="color: #800080;">$ManagedObjectType</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;VirtualMachine&quot;</span>
&nbsp;
<span style="color: #008000;"># Script</span>
<span style="color: #800080;">$VC</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$VCServerName</span>
<span style="color: #800080;">$SI</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View ServiceInstance
<span style="color: #800080;">$CFM</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View <span style="color: #800080;">$SI</span>.Content.CustomFieldsManager
&nbsp;
<span style="color: #800080;">$myCustomField</span> <span style="color: pink;">=</span> <span style="color: #800080;">$CFM</span>.Field <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: #800080;">$CustomFieldName</span><span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">!</span><span style="color: #800080;">$myCustomField</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #008000;"># Create Custom Field</span>
	<span style="color: #800080;">$FieldCopy</span> <span style="color: pink;">=</span> <span style="color: #800080;">$CFM</span>.Field<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>
	<span style="color: #800080;">$CFM</span>.AddCustomFieldDef<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CustomFieldName</span><span style="color: pink;">,</span><span style="color: #800080;">$ManagedObjectType</span><span style="color: pink;">,</span><span style="color: #800080;">$FieldCopy</span>.FieldDefPrivileges<span style="color: pink;">,</span><span style="color: #800080;">$FieldCopy</span>.FieldInstancePrivileges<span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$myCustomField</span> <span style="color: pink;">=</span> <span style="color: #800080;">$CFM</span>.Field <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: #800080;">$CustomFieldName</span><span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># Fill Custom Fields</span>
<span style="color: #800080;">$VMs</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VM
<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;">$VMs</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$VMView</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>View
	<span style="color: #800080;">$VMXPath</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VMView</span>.Config.Files.VMPathName
	<span style="color: #008000;"># Compare value to current value</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VMXPath</span> <span style="color: #FF0000;">-ne</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VMView</span>.CustomValue <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Key <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$myCustomField</span>.Key<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.Value<span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Set Custom Value</span>
		<span style="color: #800080;">$VMView</span>.setCustomValue<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CustomFieldName</span><span style="color: pink;">,</span><span style="color: #800080;">$VMXPath</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #008080; font-weight: bold;">Clear-Variable</span> VMXPath <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
	<span style="color: #008080; font-weight: bold;">Clear-Variable</span> VMView <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
	<span style="color: #000000;">&#125;</span>
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #008080; font-style: italic;">-Confirm</span>:$False</pre></div></div>

<p>Enjoy!<br />
Hugo</p>
<p>Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/add-vmx-path-to-vi-client-using-powershell/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

