<?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; PowerShell</title>
	<atom:link href="http://www.peetersonline.nl/index.php/category/powershell/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>Calculate vSphere 5 Licenses with Powershell (UPDATED)</title>
		<link>http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 09:41:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[CPU]]></category>
		<category><![CDATA[Licensing]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=484</guid>
		<description><![CDATA[VMware has announced the next generation of vSphere yesterday. Besides lots of new features, vSphere 5 also comes with a new licensing structure. For every licensed physical CPU, you get a certain amount of vRAM, which you will be able to allocate to virtual machine. Only the running VM&#8217;s will count towards your license limit. <a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-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>
</ol>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.vmware.com/" target='_blank'>VMware</a> has announced the next generation of <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> yesterday. Besides lots of new features, <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> 5 also comes with a new licensing structure. For every licensed physical CPU, you get a certain amount of vRAM, which you will be able to allocate to virtual machine. Only the running VM&#8217;s will count towards your license limit.<br />
Curious how the <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> 5 licensing model will impact your license cost? Want to know how many <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> 5 liceses you will need? The following script calculates exactly how many licenses you need for the different editions and how much overhead you will have left.</p>
<p>UPDATE 04-AUG-2011: <a href="http://www.vmware.com/" target='_blank'>vmware</a> has increased vRAM entitlements for all editions of <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> 5! I have updated the script (shown below and the attached script). The screenshot is still the old one. Please read the <a href="http://www.vmware.com/files/pdf/vsphere_pricing.pdf" target="_blank">new Licensing PDF here</a> for all the details.</p>
<p>NOTE: Please note that I add up all your pCpu’s, ignoring current license types. I also add up all your current vRAM usage (RAM assigned to powered on VM’s). I then show you different scenarios if you purchase license type x for ALL your pCpu’s. If your environment consists of a mix of <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> editions, check out <a href="http://www.virtu-al.net/2011/08/03/vsphere-5-license-entitlement-changes/" target="_blank">Alan Renouf&#8217;s script</a> to analyse your environment.</p>
<p><a href="http://www.peetersonline.nl/wp-content/Vsp5.jpg"><img src="http://www.peetersonline.nl/wp-content/Vsp5.jpg" alt="" title="Vsp5" width="767" height="209" class="alignnone size-full wp-image-489" /></a><br />
 <span id="more-484"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$vCenterServerName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;MyVC1.domain.local&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;myVC2.domain.local&quot;</span> <span style="color: #008000;"># Enter your vCenter server name here. In case of multiple vCenter servers, separate using a comma.</span>
&nbsp;
<span style="color: #000080;">$ErrorActionPreference</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Stop&quot;</span>
&nbsp;
<span style="color: #008000;"># Connect to vCenter(s)</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Connecting...&quot;</span>
<span style="color: #800080;">$VC</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$vCenterServerName</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Counting physical cpu's and vRAM in your environment. Please be patient...&quot;</span>
<span style="color: #008000;"># Gather information</span>
<span style="color: #800080;">$pCpu</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMHost <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>View <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-ExpandProperty</span> Hardware <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-ExpandProperty</span> CpuInfo <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> NumCpuPackages <span style="color: #008080; font-style: italic;">-Sum</span><span style="color: #000000;">&#41;</span>.Sum
<span style="color: #800080;">$vRAM</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Round<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VM <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.PowerState <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;PoweredOn&quot;</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> MemoryMB <span style="color: #008080; font-style: italic;">-Sum</span><span style="color: #000000;">&#41;</span>.Sum<span style="color: pink;">/</span><span style="color: #804000;">1024</span><span style="color: pink;">,</span><span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;======&quot;</span>
<span style="color: #800000;">&quot;pCpu Count: {0}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$pCpu</span>
<span style="color: #800000;">&quot;vRAM (GB):  {0}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$vRAM</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;======&quot;</span>
<span style="color: #008000;"># Disconnect</span>
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$vCenterServerName</span> <span style="color: #008080; font-style: italic;">-Confirm</span>:<span style="color: #800080;">$false</span>
&nbsp;
<span style="color: #008000;"># Calculate required licenses</span>
<span style="color: #800080;">$licCol</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;">$licObj</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Edition<span style="color: pink;">,</span> Entitlement<span style="color: pink;">,</span> Licenses
<span style="color: #800080;">$licObj</span>.Edition <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Essentials/Essentials Plus/Standard&quot;</span>
<span style="color: #800080;">$licObj</span>.Entitlement <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1 pCpu + 32 GB vRAM&quot;</span>
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">32</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$licObj</span>.Licenses <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0} with {1} pCpu overhead&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Ceiling<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">32</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Ceiling<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">32</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">Else</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$licObj</span>.Licenses <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0} with {1} GB vRAM overhead&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$pCpu</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #804000;">32</span> <span style="color: pink;">*</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span> <span style="color: #800080;">$vRAM</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$licCol</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$licObj</span>
<span style="color: #800080;">$licObj</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Edition<span style="color: pink;">,</span> Entitlement<span style="color: pink;">,</span> Licenses
<span style="color: #800080;">$licObj</span>.Edition <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Enterprise&quot;</span>
<span style="color: #800080;">$licObj</span>.Entitlement <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1 pCpu + 64 GB vRAM&quot;</span>
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">64</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$licObj</span>.Licenses <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0} with {1} pCpu overhead&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Ceiling<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">64</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Ceiling<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">64</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">Else</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$licObj</span>.Licenses <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0} with {1} GB vRAM overhead&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$pCpu</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #804000;">64</span> <span style="color: pink;">*</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span> <span style="color: #800080;">$vRAM</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$licCol</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$licObj</span>
<span style="color: #800080;">$licObj</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Edition<span style="color: pink;">,</span> Entitlement<span style="color: pink;">,</span> Licenses
<span style="color: #800080;">$licObj</span>.Edition <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Enterprise Plus&quot;</span>
<span style="color: #800080;">$licObj</span>.Entitlement <span style="color: pink;">=</span> <span style="color: #800000;">&quot;1 pCpu + 96 GB vRAM&quot;</span>
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">96</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-gt</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$licObj</span>.Licenses <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0} with {1} pCpu overhead&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Ceiling<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">96</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>Math<span style="color: #000000;">&#93;</span>::Ceiling<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vRAM</span><span style="color: pink;">/</span><span style="color: #804000;">96</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0000FF;">Else</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #800080;">$licObj</span>.Licenses <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0} with {1} GB vRAM overhead&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$pCpu</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #804000;">96</span> <span style="color: pink;">*</span> <span style="color: #800080;">$pCpu</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span> <span style="color: #800080;">$vRAM</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$licCol</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$licObj</span>
<span style="color: #008000;"># Displaying output</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Resulting license options:&quot;</span>
<span style="color: #800080;">$licCol</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;======&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;NOTE: vRAM only counts memory allocated to vm's that are POWERED ON.&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red 
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;NOTE: Please double check the results of this script, since hosts may have been omitted due to errors.&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red 
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Disclaimer: No rights can be deduced from this calculation.&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Red
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;======&quot;</span></pre></div></div>

<p>You can download the script here (rename to .ps1): <a href='http://www.peetersonline.nl/wp-content/Get-vSphere5LicensesUpdated.txt'>Get-vSphere5LicensesUpdated</a></p>
<p>Don’t forget to use <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> to run the script, or add the <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> snapin to your <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> session (Add-PSSnapIn <a href="http://www.vmware.com/" target='_blank'>vmware</a>*).</p>
<p>Enjoy!</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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/feed/</wfw:commentRss>
		<slash:comments>51</slash:comments>
		</item>
		<item>
		<title>Remove vmware memory limits with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 09:21:31 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[Limits]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=477</guid>
		<description><![CDATA[Using Memory Limits in vmware vSphere can cause severe performance issues. The guest operating system assumes it can use all of the allocated memory, but vSphere will make sure the vm cannot use more than the memory limit. It does this by inflating a memory balloon using the balloon driver included with the vmware tools. <a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/'>[...]</a>
Related posts:<ol>
<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>Using Memory Limits in <a href="http://www.vmware.com/" target='_blank'>vmware</a> <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> can cause severe performance issues. The guest operating system assumes it can use all of the allocated memory, but <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> will make sure the vm cannot use more than the memory limit. It does this by inflating a memory balloon using the balloon driver included with the <a href="http://www.vmware.com/" target='_blank'>vmware</a> tools. The performance chart in the <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> Client will show the virtual machine is ballooning. I never recommend using memory limits in <a href="http://www.vmware.com/" target='_blank'>vmware</a>.<br />
The following script will remove all memory limits in your <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> infrastructure, preventing the problems described above.<span id="more-477"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$vCenterServer</span> <span style="color: pink;">=</span> MyvCenterServer.domain.local <span style="color: #008000;">#Enter your vCenter server FQDN here</span>
&nbsp;
<span style="color: #008000;">#Connect to vCenter Server</span>
<span style="color: #800080;">$VC</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$vCenterServer</span>
&nbsp;
<span style="color: #008000;">#Gathering data</span>
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span> <span style="color: #0000FF;">in</span> get<span style="color: pink;">-</span>vm<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
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;======&quot;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;VM: $($vm.Name)&quot;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Current Limit: $($vmView.config.MemoryAllocation.Limit)&quot;</span>
&nbsp;
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$vmView</span>.config.MemoryAllocation.Limit <span style="color: #FF0000;">-ne</span> <span style="color: pink;">-</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;">#Preparing modified data</span>
		<span style="color: #800080;">$spec</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.VirtualMachineConfigSpec
		<span style="color: #800080;">$MemoryAllocation</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.ResourceAllocationInfo
		<span style="color: #800080;">$MemoryAllocation</span>.Limit <span style="color: pink;">=</span> <span style="color: pink;">-</span><span style="color: #804000;">1</span>
		<span style="color: #800080;">$spec</span>.MemoryAllocation <span style="color: pink;">=</span> <span style="color: #800080;">$MemoryAllocation</span>
&nbsp;
		<span style="color: #008000;">#Applying modification</span>
		<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Removing Memory Limit&quot;</span>
		<span style="color: #800080;">$vmView</span>.ReconfigVM<span style="color: #000000;">&#40;</span><span style="color: #800080;">$spec</span><span style="color: #000000;">&#41;</span>
&nbsp;
		<span style="color: #008000;">#Reloading data</span>
		<span style="color: #800080;">$vm</span> <span style="color: pink;">=</span> get<span style="color: pink;">-</span>vm <span style="color: #800080;">$vm</span>.name
		<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: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Current Limit: $($vmView.config.MemoryAllocation.Limit)&quot;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">#Cleanup</span>
	<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>
&nbsp;
<span style="color: #008000;">#Disconnect</span>
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$vCenterServer</span> <span style="color: #008080; font-style: italic;">-Confirm</span>:$false</pre></div></div>

<p>You can download the script here (rename to .ps1): <a href='http://www.peetersonline.nl/wp-content/Remove-MemoryLimits.txt'>Remove-MemoryLimits</a></p>
<p>Don&#8217;t forget to use <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> to run the script, or add the <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> snapin to your <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> session (Add-PSSnapIn <a href="http://www.vmware.com/" target='_blank'>vmware</a>*).</p>
<p>Enjoy!</p>
<p>Related posts:<ol>
<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/remove-vmware-memory-limits-with-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Configure Syslog on Local Datastore with PowerCLI</title>
		<link>http://www.peetersonline.nl/index.php/powershell/configure-syslog-on-local-datastore-with-powercli/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/configure-syslog-on-local-datastore-with-powercli/#comments</comments>
		<pubDate>Wed, 02 Feb 2011 13:13:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[syslog]]></category>
		<category><![CDATA[VMware]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=471</guid>
		<description><![CDATA[Configuring a syslog folder is convenient for troubleshooting ESXi. But it&#8217;s a pain you-know-where to configure manually across all your ESXi servers. Luckily, PowerCLI can help out. This script creates a folder on the local datastore and configures ESXi to write the syslog in that folder. Enjoy! Hugo #Folder name you like $syslogFolderName = &#34;syslog&#34; <a href='http://www.peetersonline.nl/index.php/powershell/configure-syslog-on-local-datastore-with-powercli/'>[...]</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>Configuring a syslog folder is convenient for troubleshooting ESXi. But it&#8217;s a pain you-know-where to configure manually across all your ESXi servers. Luckily, <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> can help out. This script creates a folder on the local datastore and configures ESXi to write the syslog in that folder.<br />
Enjoy!<br />
Hugo<br />
<span id="more-471"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#Folder name you like</span>
<span style="color: #800080;">$syslogFolderName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;syslog&quot;</span>
&nbsp;
<span style="color: #008000;">#Connect to vCenter</span>
Connect<span style="color: pink;">-</span>VIServer vcenter.domain.local
&nbsp;
<span style="color: #008000;">#Loop through hosts</span>
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$vmhost</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>
	<span style="color: #008000;">#Get only the first part of the FQDN (only if you used the FQDN to add the ESX server to vCenter)</span>
	<span style="color: #800080;">$hostname</span> <span style="color: pink;">=</span> <span style="color: #800080;">$vmhost</span>.name.split<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.ToUpper<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;">#Local datastore name (equal to hostname in my case)</span>
	<span style="color: #800080;">$datastorename</span> <span style="color: pink;">=</span> <span style="color: #800080;">$hostname</span>
&nbsp;
	<span style="color: #008000;">#Make the local datastore accessible as a PSdrive</span>
	<span style="color: #008080; font-weight: bold;">New-PSDrive</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$hostname</span> <span style="color: #008080; font-style: italic;">-Root</span> \ <span style="color: #008080; font-style: italic;">-PSProvider</span> VimDatastore <span style="color: pink;">-</span>Datastore <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>Datastore <span style="color: #800080;">$datastorename</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-Scope</span> global
&nbsp;
	<span style="color: #008000;">#Access the new PSDrive</span>
	<span style="color: #008080; font-weight: bold;">Set-Location</span> $hostname<span style="color: #800000;">&quot;:&quot;</span>
&nbsp;
	<span style="color: #008000;">#Create the syslog folder</span>
	<span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #800080;">$syslogFolderName</span> <span style="color: #008080; font-style: italic;">-ItemType</span> directory
&nbsp;
	<span style="color: #008000;">#Set the advanced parameter to configure the syslog on the local datastore</span>
	<span style="color: #800080;">$value</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;[$datastorename] $syslogFoldername/$hostname.log&quot;</span>
	Set<span style="color: pink;">-</span>VMHostAdvancedConfiguration <span style="color: pink;">-</span>VMHost <span style="color: #800080;">$vmhost</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800000;">&quot;Syslog.Local.DatastorePath&quot;</span> <span style="color: #008080; font-style: italic;">-Value</span> <span style="color: #800080;">$value</span>
&nbsp;
	<span style="color: #008000;">#Cleanup</span>
	<span style="color: #008080; font-weight: bold;">Set-Location</span> <span style="color: #800080;">$PSHOME</span>
	<span style="color: #008080; font-weight: bold;">Remove-PSDrive</span> <span style="color: #800080;">$hostname</span>
	<span style="color: #008080; font-weight: bold;">Clear-Variable</span> hostname <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
	<span style="color: #008080; font-weight: bold;">Clear-Variable</span> datastorename <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
	<span style="color: #008080; font-weight: bold;">Clear-Variable</span> value <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;">#Disconnect from vCenter</span>
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #008080; font-style: italic;">-confirm</span>:$false</pre></div></div>

<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/powershell/configure-syslog-on-local-datastore-with-powercli/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Convert Scripts to Module</title>
		<link>http://www.peetersonline.nl/index.php/powershell/convert-scripts-to-module/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/convert-scripts-to-module/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 15:16:58 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=467</guid>
		<description><![CDATA[I used to have all my common functions stored as separate scripts in a single folder. I&#8217;d load these through a few lines of code in my profile, looping through the script files and dot-sourcing them. Powershell v2.0 has a new feature called Modules. So how do you convert a bunch of scripts (containing functions) <a href='http://www.peetersonline.nl/index.php/powershell/convert-scripts-to-module/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>I used to have all my common functions stored as separate scripts in a single folder. I&#8217;d load these through a few lines of code in my profile, looping through the script files and dot-sourcing them. <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> v2.0 has a new feature called Modules. So how do you convert a bunch of scripts (containing functions) into a single module you can load or unload whenever you feel you might need those functions?</p>
<p>Here&#8217;s how:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Convert function scripts to Module</span>
&nbsp;
<span style="color: #008000;">#Variables</span>
<span style="color: #800080;">$myModuleName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;myModule123&quot;</span>
<span style="color: #800080;">$inputFolder</span> <span style="color: pink;">=</span> <span style="color: #800000;">'D:\scripts\Functions'</span>
<span style="color: #800080;">$outputFolder</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$PSHOME\Modules\$myModuleName&quot;</span>
&nbsp;
<span style="color: #008000;">#Create the module directory</span>
<span style="color: #800080;">$null</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Item</span> <span style="color: #800080;">$outputFolder</span> <span style="color: #008080; font-style: italic;">-ItemType</span> directory
&nbsp;
<span style="color: #008000;">#Create the module with a nice oneliner</span>
<span style="color: #008080; font-weight: bold;">Get-ChildItem</span> <span style="color: #800080;">$inputFolder</span> <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: #800000;">&quot;*.ps1&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800000;">&quot;$outputFolder\$myModuleName.psm1&quot;</span> <span style="color: #008080; font-style: italic;">-Append</span>
&nbsp;
<span style="color: #008000;">#Import the module</span>
Import<span style="color: pink;">-</span>Module <span style="color: #800080;">$myModuleName</span>
&nbsp;
<span style="color: #008000;">#Show functions loaded from the module</span>
<span style="color: #008080; font-weight: bold;">Get-Command</span> <span style="color: pink;">-</span>Module $myModuleName</pre></div></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/convert-scripts-to-module/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Set vApp Guest Shutdown</title>
		<link>http://www.peetersonline.nl/index.php/vmware/set-vapp-guest-shutdown/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/set-vapp-guest-shutdown/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 07:28:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Shutdown]]></category>
		<category><![CDATA[vApp]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=462</guid>
		<description><![CDATA[Annoyed by the default setting for VM&#8217;s inside a vApp? I was, because when you power down the vApp, the VM&#8217;s are powered down instead of being shutdown cleanly. It can be a tedious task to check and correct this setting for all your vApps. This little script solves that problem for you. Enjoy! $VC <a href='http://www.peetersonline.nl/index.php/vmware/set-vapp-guest-shutdown/'>[...]</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>Annoyed by the default setting for VM&#8217;s inside a vApp? I was, because when you power down the vApp, the VM&#8217;s are powered down instead of being shutdown cleanly. It can be a tedious task to check and correct this setting for all your vApps. This little script solves that problem for you. Enjoy!</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$VC</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800000;">&quot;MyvCenter.local&quot;</span>
&nbsp;
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Vapp</span> <span style="color: #0000FF;">in</span> Get<span style="color: pink;">-</span>VApp<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>	
	<span style="color: #800080;">$VAppView</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VApp</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>View
	<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Entity</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$VAppView</span>.VAppConfig.EntityConfig<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;">$Entity</span>.StopAction <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;guestShutdown&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$VAppConfigSpec</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.VAppConfigSpec
		<span style="color: #800080;">$EntityConfig</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.VAppEntityConfigInfo
			<span style="color: #800080;">$EntityConfig</span>.Key <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View <span style="color: #800080;">$Entity</span>.Key<span style="color: #000000;">&#41;</span>.MoRef
			<span style="color: #800080;">$EntityConfig</span>.StopAction <span style="color: pink;">=</span> <span style="color: #800000;">&quot;guestShutdown&quot;</span>
		<span style="color: #800080;">$VAppConfigSpec</span>.EntityConfig <span style="color: pink;">=</span> <span style="color: #800080;">$EntityConfig</span>
&nbsp;
		<span style="color: #800080;">$VAppView</span>.UpdateVAppConfig<span style="color: #000000;">&#40;</span><span style="color: #800080;">$VAppConfigSpec</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #008080; font-style: italic;">-Confirm</span>:$false</pre></div></div>

<p>Download script: <a href='http://www.peetersonline.nl/wp-content/Set-VAppGuestShutdown.txt'>Set-VAppGuestShutdown (rename to .ps1)</a></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/set-vapp-guest-shutdown/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Find LUN ID&#8217;s in VMware with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/find-lun-ids-in-vmware-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/find-lun-ids-in-vmware-with-powershell/#comments</comments>
		<pubDate>Thu, 27 May 2010 08:01:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[datastores]]></category>
		<category><![CDATA[LUN ID]]></category>
		<category><![CDATA[Luns]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=457</guid>
		<description><![CDATA[Determining the LUN ID for a specific LUN in your VMware Infrastructure used to be simple. It was listed as one of the properties of the datastore you selected in the VI Client. Nowadays, more often than not, I dont see the LUN ID in the vSphere Client. Instead, I see some sort of identifier <a href='http://www.peetersonline.nl/index.php/vmware/find-lun-ids-in-vmware-with-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>Determining the LUN ID for a specific LUN in your <a href="http://www.vmware.com/" target='_blank'>VMware</a> Infrastructure used to be simple. It was listed as one of the properties of the datastore you selected in the VI Client. Nowadays, more often than not, I dont see the LUN ID in the <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> Client. Instead, I see some sort of identifier like &#8220;EMC Fibre Channel Disk (sym.12673548127)&#8221;.<br />
Even more unfortunate is the fact that all my scripts show the same identifier, where they used to show the LUN ID. So I decided to create a script that can translate the identifier (sometimes referred to as Canonical Name) back to a LUN ID.<br />
By the way: in the <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> Client, you can still find the LUN ID by opening the datastore&#8217;s properties window and clicking Manage Paths. Or you could write down the canonical name, switch to the devices view and look up the device there. That is essentially what my script does for you.<br />
Here we go:<br />
<span id="more-457"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;">&nbsp;
<span style="color: #0000FF;">function</span> Get<span style="color: pink;">-</span>LunId
<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$CanonicalName</span><span style="color: pink;">,</span> <span style="color: #800080;">$VMHost</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;">#Get advanced host properties</span>
	<span style="color: #800080;">$VMHostView</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VMHost <span style="color: #800080;">$VMHost</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>View
&nbsp;
	<span style="color: #008000;">#Get two different collections with luns</span>
	<span style="color: #008000;">#The first one matches the canonical name with a key</span>
	<span style="color: #800080;">$HostLunsByCanonicalName</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VMHost <span style="color: #800080;">$VMHost</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>SCSILun
	<span style="color: #008000;">#The second one matches the key with a lun id</span>
	<span style="color: #800080;">$HostLunsByKey</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VMHostView</span>.Config.StorageDevice.ScsiTopology <span style="color: pink;">|</span> 
		<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Adapter<span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Target<span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Lun<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">#Use the first collection to translate the canonicalname into the key</span>
	<span style="color: #800080;">$Key</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$HostLunsByCanonicalName</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.CanonicalName <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$CanonicalName</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.Key
	<span style="color: #008000;">#Use the second colleciton to find the luns with the key</span>
	<span style="color: #800080;">$MatchingLuns</span> <span style="color: pink;">=</span> <span style="color: #800080;">$HostLunsByKey</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.ScsiLun <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$Key</span><span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #008000;">#Every path to the lun will be a match, </span>
	<span style="color: #008000;">#so let's deduplicate and see if there is really a single result</span>
	<span style="color: #800080;">$NumResults</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$MatchingLuns</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Group-Object</span> Lun <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span><span style="color: #000000;">&#41;</span>.Count
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$NumResults</span> <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;">#Multiple luns found</span>
		<span style="color: #800080;">$MatchingLuns</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Group-Object</span> Lun <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Name<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">ElseIf</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$NumResults</span> <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;">#Single result found</span>
		<span style="color: #000000;">&#40;</span><span style="color: #800080;">$MatchingLuns</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-First</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>.Lun
	<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">Else</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;">#No results found</span>
		<span style="color: #800000;">&quot;No result&quot;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Download the script here: <a href='http://www.peetersonline.nl/wp-content/Get-LunId.txt'>Get-LunId (rename to *.ps1)</a></p>
<p>Note that when you use this function inside a script where you loop through several LUNs/VMs/Datastores on the same host, you are able to speed up your script significantly by taking the Get-VMHost $VMHost | Get-View part outside of the function.</p>
<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/find-lun-ids-in-vmware-with-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fix DCOM Event 10005 with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/fix-dcom-event-10005-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/fix-dcom-event-10005-with-powershell/#comments</comments>
		<pubDate>Wed, 19 May 2010 12:57:24 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[DCOM]]></category>
		<category><![CDATA[Event Log]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Windows 2003]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=428</guid>
		<description><![CDATA[Do you get these events in your system log? The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. attempting to start the service ntmssvc with arguments &#8220;-Service&#8221; in order to run the server: {D61A27C6-8F53-11D0-BFA0-00A024151983} Symantec explains this is caused by disabling the Removable Storage <a href='http://www.peetersonline.nl/index.php/powershell/fix-dcom-event-10005-with-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Do you get these events in your system log?</p>
<blockquote><p>The service cannot be started, either because it is disabled or because it has no enabled devices associated with it. attempting to start the service ntmssvc with arguments &#8220;-Service&#8221; in order to run the server:<br />
{D61A27C6-8F53-11D0-BFA0-00A024151983}</p></blockquote>
<p>Symantec <a href="http://seer.support.veritas.com/docs/240378.htm">explains</a> this is caused by disabling the Removable Storage Manager and <a href="http://seer.entsupport.symantec.com/docs/262914.htm">provides a solution</a>.</p>
<p>Removing those registry keys on a bunch of servers manually is a pain. Modifying DCOM settings even more so. So I explored fixing this with <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a>.</p>
<p><span id="more-428"></span><br />
Scripting DCOM application settings (COM+ Apllications in dcomcnfg) is doable. See <a href="http://msdn.microsoft.com/en-us/library/ee309561(v=VS.85).aspx">MSDN</a>. However, scripting the DCOM Config section of dcomcnfg appears to be impossible. Turns out all these settings are located in the registry. Clearing the checkbox &#8220;Run application on this computer&#8221; does nothing more then rename one of the values in the registry key you will delete. That&#8217;s one problem down.<br />
So all we have to do is remove the appropriate registry keys on all our affected servers. Remote registry manipulation is something we have done before, so let&#8217;s jump to the script! In order to be able to undo the changes you will make with this script, I recommend you export the following keys on one of your servers:</p>
<blockquote><p>HKLM\Software\Classes\AppID\{D61A27C1-8F53-11D0-BFA0-00A024151983}<br />
HKLM\Software\Classes\CLSID\{D61A27C6-8F53-11D0-BFA0-00A024151983}</p></blockquote>
<p>Here&#8217;s the script:</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">function</span> Fix<span style="color: pink;">-</span>RsmDcom
<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">Param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ServerName</span> <span style="color: pink;">=</span> <span style="color: #800000;">'blank'</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$ServerName</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'blank'</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$ServerName</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;ServerName&quot;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #800080;">$Hive</span> <span style="color: pink;">=</span> <span style="color: #800000;">'LocalMachine'</span>
	<span style="color: #800080;">$AppIDKeyName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Software\Classes\AppID&quot;</span>
	<span style="color: #800080;">$AppIDSubKey</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{D61A27C1-8F53-11D0-BFA0-00A024151983}&quot;</span>
	<span style="color: #800080;">$CLSIDKeyName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Software\Classes\CLSID&quot;</span>
	<span style="color: #800080;">$CLSIDSubKey</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{D61A27C6-8F53-11D0-BFA0-00A024151983}&quot;</span>
	<span style="color: #800080;">$Writable</span> <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
&nbsp;
	<span style="color: #008080; font-weight: bold;">Write</span>	<span style="color: pink;">-</span>Host <span style="color: #800000;">&quot;Processing Server $Servername&quot;</span>
&nbsp;
	<span style="color: #800080;">$Registry</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryKey<span style="color: #000000;">&#93;</span>::OpenRemoteBaseKey<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>Microsoft.Win32.RegistryHive<span style="color: #000000;">&#93;</span>::<span style="color: #800080;">$Hive</span><span style="color: pink;">,</span> <span style="color: #800080;">$ServerName</span><span style="color: #000000;">&#41;</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Registry</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$AppID</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Registry</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800080;">$AppIDKeyName</span><span style="color: pink;">,</span> <span style="color: #800080;">$Writable</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$AppID</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;">$AppID</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800080;">$AppIDSubKey</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`t</span>Removing AppID subkey&quot;</span>
				<span style="color: #800080;">$AppID</span>.DeleteSubKey<span style="color: #000000;">&#40;</span><span style="color: #800080;">$AppIDSubKey</span><span style="color: #000000;">&#41;</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-Warning</span> <span style="color: #800000;">&quot;AppID SubKey not found on $ServerName&quot;</span>
			<span style="color: #000000;">&#125;</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-Warning</span> <span style="color: #800000;">&quot;Failed to open AppID subkey on $ServerName&quot;</span>
		<span style="color: #000000;">&#125;</span>
&nbsp;
		<span style="color: #800080;">$CLSID</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Registry</span>.OpenSubKey<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CLSIDKeyName</span><span style="color: pink;">,</span> <span style="color: #800080;">$Writable</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$CLSID</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;">$CLSID</span>.GetSubKeyNames<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-contains</span> <span style="color: #800080;">$CLSIDSubKey</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`t</span>Removing CSLID subkey tree&quot;</span>
				<span style="color: #800080;">$CLSID</span>.DeleteSubKeyTree<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CLSIDSubKey</span><span style="color: #000000;">&#41;</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-Warning</span> <span style="color: #800000;">&quot;CLSID SubKey not found on $ServerName&quot;</span>
			<span style="color: #000000;">&#125;</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-Warning</span> <span style="color: #800000;">&quot;Failed to open CLSID subkey on $ServerName&quot;</span>
		<span style="color: #000000;">&#125;</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-Warning</span> <span style="color: #800000;">&quot;Failed to connect to registry on $ServerName&quot;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Download it here: <a href='http://www.peetersonline.nl/wp-content/Fix-RsmDcom.txt'>Fix-RsmDcom (rename to .ps1)</a></p>
<p>Enjoy!</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/fix-dcom-event-10005-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Report vSphere Alarms with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/report-vsphere-alarms-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/report-vsphere-alarms-with-powershell/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 10:58:15 +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[Alarms]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[vSphere]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=418</guid>
		<description><![CDATA[Wow, vSphere vCenter Server has a lot of new alarms! Great for monitoring your environment. But a pain when it comes to documenting it. Thank God VMware for the PowerCLI! Just a few lines of code can do the documentation for you. Here&#8217;s how: # Report vSphere Alarms # by Hugo Peeters # www.peetersonline.nl &#160; <a href='http://www.peetersonline.nl/index.php/vmware/report-vsphere-alarms-with-powershell/'>[...]</a>
Related posts:<ol>
<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>
<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>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Wow, <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> vCenter Server has a lot of new alarms! Great for monitoring your environment. But a pain when it comes to documenting it. Thank <del datetime="2009-10-30T10:54:17+00:00">God</del> <a href="http://www.vmware.com/" target='_blank'>VMware</a> for the <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a>! Just a few lines of code can do the documentation for you.</p>
<p>Here&#8217;s how:</p>
<p><span id="more-418"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Report vSphere Alarms</span>
<span style="color: #008000;"># by Hugo Peeters</span>
<span style="color: #008000;"># www.peetersonline.nl</span>
&nbsp;
<span style="color: #008000;">#Region Variables</span>
<span style="color: #800080;">$VCServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;myVCServer&quot;</span>
<span style="color: #800080;">$Outfile</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;D:\scripts\Alarms.txt&quot;</span>
&nbsp;
Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$VCServer</span>
<span style="color: #800080;">$SI</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View ServiceInstance
<span style="color: #800080;">$AM</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View <span style="color: #800080;">$SI</span>.Content.AlarmManager
<span style="color: #800080;">$myCol</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: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Folder</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>Folder<span style="color: #000000;">&#41;</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;">$Alarm</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$AM</span>.GetAlarm<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Folder</span><span style="color: pink;">|</span>Get<span style="color: pink;">-</span>View<span style="color: #000000;">&#41;</span>.MoRef<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$Alarm</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>View <span style="color: #800080;">$Alarm</span>
		<span style="color: #800080;">$myObj</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Folder<span style="color: pink;">,</span> Name<span style="color: pink;">,</span> Description<span style="color: pink;">,</span> Enabled<span style="color: pink;">,</span> Summary
		<span style="color: #800080;">$myObj</span>.Folder <span style="color: pink;">=</span> <span style="color: #800080;">$Folder</span>.Name
		<span style="color: #800080;">$myObj</span>.Name <span style="color: pink;">=</span> <span style="color: #800080;">$Alarm</span>.Info.Name
		<span style="color: #800080;">$myObj</span>.Description <span style="color: pink;">=</span> <span style="color: #800080;">$Alarm</span>.Info.Description
		<span style="color: #800080;">$myObj</span>.Enabled <span style="color: pink;">=</span> <span style="color: #800080;">$Alarm</span>.Info.Enabled
		<span style="color: #800080;">$myObj</span>.Summary <span style="color: pink;">=</span> <span style="color: #800080;">$Alarm</span>.Info.Expression.Expression <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span>
		<span style="color: #800080;">$myObj</span>
		<span style="color: #800080;">$myCol</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$myObj</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #800080;">$myCol</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Enabled<span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #800080;">$Outfile</span>
<span style="color: #008080; font-weight: bold;">ii</span> $Outfile</pre></div></div>

<p>Related posts:<ol>
<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>
<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>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/report-vsphere-alarms-with-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<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>
		<item>
		<title>Set VMware Snapshot Location with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/set-vmware-snapshot-location-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/set-vmware-snapshot-location-with-powershell/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 13:09:49 +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[PowerCLI]]></category>
		<category><![CDATA[snapshots]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=411</guid>
		<description><![CDATA[Snapshots are m*th3rfcukers. If you&#8217;re not careful, they will mass-murder your vms. Yet they allow you to time-travel! You want to use them, but how to prevent a massacre? Here&#8217;s how: relocate the delta files. When you create a snapshot, the current state of the vm is preserved by leaving the disk files alone. All changes <a href='http://www.peetersonline.nl/index.php/vmware/set-vmware-snapshot-location-with-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>Snapshots are m*th3rfcukers. If you&#8217;re not careful, they will mass-murder your vms. Yet they allow you to time-travel! You want to use them, but how to prevent a massacre? Here&#8217;s how: relocate the delta files.</p>
<p>When you create a snapshot, the current state of the vm is preserved by leaving the disk files alone. All changes since the moment of creating the snapshot are written to delta files. The delta files are stored in the vm&#8217;s working directory. The working directory is &#8211; by default &#8211; the location where the vmx and other config files reside. If that datastore runs out of free space &#8211; especially if it also contains disk files &#8211; you&#8217;re in a bit of a kerfuffle. Vms not booting or being frozen as if they stared into Medusa&#8217;s reptoid eyes.</p>
<p>So you can do two things: reserve overhead in your datastores and stay afraid some overactive snapshot might destroy your environment, or set the working directory of your vms to some big-ass datastore you don&#8217;t use for anything else and let the snapshots enjoy themselves. If they fill up the datastore, they only kill all vms with snapshots, not the rest.</p>
<p>But how, you ask? You can edit the vmx files of you vms manually - which requires your vms to be powered down &#8211; and add the line: workingDir = &#8220;/vmfs/volumes/&lt;insanely long guid you need to somehow find&gt;/&#8221;</p>
<p>Or, you run my script and change the working location on the fly:</p>
<p><span id="more-411"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Description:</span>
<span style="color: #008000;"># Set's the Working Location for a VM. This location will hold the vswap and snapshot delta files.</span>
&nbsp;
<span style="color: #008000;"># Usage:</span>
<span style="color: #008000;"># First, connect to a virtual server server (Connect-VIServer)</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># Set snapshot location for one vm (folder must already exist on datastore):</span>
<span style="color: #008000;"># Set-VMSnapshotLocation -vm VM001 -Location &quot;[BigAssDatastore] Snapshots&quot;</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># For all vms at once (no folder specified will put all in the root of the datastore):</span>
<span style="color: #008000;"># Get-VM | ForEach-Object {Set-VMSnapshotLocation -vm $_ -Location &quot;[BigAssDatastore]&quot;}</span>
<span style="color: #008000;">#</span>
<span style="color: #008000;"># Reset the location to the original location (with the vmx file):</span>
<span style="color: #008000;"># Set-VMSnapshotLocation -vm VM001 -Reset</span>
&nbsp;
<span style="color: #0000FF;">Function</span> Set<span style="color: pink;">-</span>VMSnapshotLocation
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Location</span><span style="color: pink;">,</span> <span style="color: #000000;">&#91;</span><span style="color: #0000FF;">switch</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Reset</span><span style="color: pink;">=</span><span style="color: #800080;">$False</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;">#Region Input Validation</span>
	<span style="color: #008000;"># Check vm parameter</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">!</span><span style="color: #800080;">$vm</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">Throw</span> <span style="color: #800000;">&quot;No VM specified.&quot;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #008000;"># Check Location parameter.</span>
	<span style="color: #008000;"># Can be empty when using Reset, can be &quot;[datastore]&quot; or can be &quot;[datastore] folder&quot; (folder must exist).</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">!</span><span style="color: #800080;">$Reset</span> <span style="color: #FF0000;">-and</span> <span style="color: #800080;">$Location</span> <span style="color: #FF0000;">-notmatch</span> <span style="color: #800000;">&quot;\[\S+\](\s\w+)?&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">Throw</span> <span style="color: #800000;">&quot;Invalid location specified. Syntax: [Datastore] Folder&quot;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #008000;"># Specifying Reset will set Location to empty, which causes the original location to be used (same location as vmx file).</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Reset</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$Location</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;&quot;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #008000;"># Make sure to get a vm object to work with.</span>
	<span style="color: #008000;"># This allows both using a vm name when targeting one vm (Set-VMSnapshotLocation -vm VM001 -Reset);</span>
	<span style="color: #008000;"># AND piping a collection of vm's (Get-VM | ForEach (Set-VMSnapshotLocation -vm $_ -Location &quot;[BigAssDatastore] Snapshots&quot; ).</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span>.GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;String&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$oVM</span> <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VM <span style="color: #800080;">$vm</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">ElseIf</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span>.GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;VirtualMachineImpl&quot;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #800080;">$oVM</span> <span style="color: pink;">=</span> <span style="color: #800080;">$vm</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">Else</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #0000FF;">Throw</span> <span style="color: #800000;">&quot;Parameter vm is of an invalid type.&quot;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #008000;">#EndRegion InputValidation</span>
&nbsp;
	<span style="color: #008000;">#Region Main</span>
	<span style="color: #008000;"># Get advanced properties of vm</span>
	<span style="color: #800080;">$vmView</span> <span style="color: pink;">=</span> <span style="color: #800080;">$oVM</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>View
	<span style="color: #008000;"># Create object containing new properties</span>
	<span style="color: #800080;">$vmConfigSpec</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.VirtualMachineConfigSpec
	<span style="color: #800080;">$vmConfigSpec</span>.Files <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.VirtualMachineFileInfo
	<span style="color: #800080;">$vmConfigSpec</span>.Files.SnapshotDirectory <span style="color: pink;">=</span> <span style="color: #800080;">$Location</span>
	<span style="color: #008000;"># Reconfigure VM using new properties</span>
	<span style="color: #800080;">$vmView</span>.ReconfigVM<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vmConfigSpec</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008000;">#EndRegion Main</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You can download it here: <a href="http://www.peetersonline.nl/wp-content/Set-VMSnapshotLocation.txt">Set-VMSnapshotLocation (rename to .ps1)</a></p>
<p>I tried hard as I could, but I could not get my vm to die. Even running the script, creating a snapshot, running the script to move the working location again and deleting the snapshot did not prove a problem. However, I urge you to be careful with it. I&#8217;m not responsable for anything you do with it.</p>
<p>Tiny glitch: the VI Client shows the wrong datastore location when a vm has a snapshot in a modified workingdir.</p>
<p>Enjoy.</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/set-vmware-snapshot-location-with-powershell/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

