<?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.nl</title>
	<atom:link href="http://www.peetersonline.nl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peetersonline.nl</link>
	<description>Virtually Everything about Powershell and PowerCLI</description>
	<lastBuildDate>Mon, 30 Jul 2012 09:33:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Poor Man&#8217;s Virtual Machine Backup with PowerCLI</title>
		<link>http://www.peetersonline.nl/2012/07/poor-mans-virtual-machine-backup-with-powercli/</link>
		<comments>http://www.peetersonline.nl/2012/07/poor-mans-virtual-machine-backup-with-powercli/#comments</comments>
		<pubDate>Fri, 27 Jul 2012 13:01:19 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=512</guid>
		<description><![CDATA[<p>Are you still performing old-school in-guest VM backups with a backup agent? Not ready to buy a backup product that does complete VM backups through the vStorage APIs? Then you will need to rebuild all your VM&#8217;s with the original configuration before you can start restoring your data.</p> <p>As always: <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> to the [...]]]></description>
				<content:encoded><![CDATA[<p>Are you still performing old-school in-guest VM backups with a backup agent? Not ready to buy a backup product that does complete VM backups through the vStorage APIs? Then you will need to rebuild all your VM&#8217;s with the original configuration before you can start restoring your data.</p>
<p>As always: <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> to the rescue! This script will connect to vCenter Servers on your primary site and secondary (recovery) site. <span id="more-512"></span>It scans the datastores on the primary site for vmx files and copies them to a designated datastore on the secondary site. (It uses a local temp location, because direct copy from one vCenter to another is not possible.)</p>
<p>When you add these vmx files to the inventory on the secondary site, you&#8217;ll notice the disks are either not available or have a zero size. That&#8217;s because the size is listed in the vmdk files, not the vmx. Copying the vmdk descriptors as well might sound like a nice solution to this challenge, but this will not help due to absolute paths being used to locate the vmdk files.</p>
<p>Another challenge lies in the fact that the VM name, the OS host name and the vmx file name might not be identical.</p>
<p>To solve both problems, the script gathers all this information for you &#8211; vm names, OS host names, vmx names and disk sizes &#8211; stores it in a csv file and uploads it to the same datastore in the secondary datacenter. This way you are all set to recover your VM&#8217;s on the cheap!</p>
<p>#DISCLAIMER# You still need the old school backup to restore your data! This script just helps rebuild the empty VM&#8217;s in your recovery location.</p>

<div class="wp_syntax"><table><tr><td class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Created by http://www.peetersonline.nl</span>
&nbsp;
<span style="color: #000080;">$VerbosePreference</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Continue&quot;</span> <span style="color: #008000;"># Use &quot;Continue&quot; to show verbose information during interactive use. Use &quot;SilentlyContinue&quot; to hide verbose info during non-interactive use.</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;=====================&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;VM Config Copy Script&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Copies VMX files and an overview of remaining important VM configuration to a remote datastore (via local TEMP folder) &quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;=====================&quot;</span>
&nbsp;
<span style="color: #008000;">#REGION Variables</span>
<span style="color: #800080;">$vCenterSource</span> <span style="color: pink;">=</span> <span style="color: #800000;">'PrimaryVC.domain.local'</span> <span style="color: #008000;"># Source vCenter Server (Primary Site)</span>
<span style="color: #800080;">$vCenterDestination</span> <span style="color: pink;">=</span> <span style="color: #800000;">'SecondaryVC.domain.local'</span> <span style="color: #008000;"># Destination vCenter Server (Secondary Site)</span>
<span style="color: #800080;">$DestinationDatastore</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;MY-DATASTORE-01&quot;</span> <span style="color: #008000;"># Destination datastore (Secondary Site)</span>
<span style="color: #800080;">$Temp</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Item</span> Env:\TEMP<span style="color: #000000;">&#41;</span>.Value <span style="color: #008000;"># Path to local temp folder (on host running this script)</span>
&nbsp;
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;vCenter Source : $vCenterSource&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;vCenter Destination : $vCenterDestination&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Destination : $DestinationDatastore&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Temp Folder : $Temp&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;---------------------&quot;</span>
<span style="color: #008000;">#ENDREGION Variables</span>
&nbsp;
<span style="color: #008000;">#REGION Script</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Connecting to Source vCenter $vCenterSource...&quot;</span>
<span style="color: #800080;">$VIServer</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$vCenterSource</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Connecting to Destination vCenter $vCenterDestination...&quot;</span>
<span style="color: #800080;">$VIServer</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$vCenterDestination</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Connecting to Destination Datastore $DestinationDatastore...&quot;</span>
<span style="color: #800080;">$Destination</span> <span style="color: pink;">=</span> New<span style="color: pink;">-</span>DatastoreDrive <span style="color: pink;">-</span>DriveName Destination <span style="color: pink;">-</span>Datastore <span style="color: #800080;">$DestinationDatastore</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;---------------------&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Start VMX COPY section&quot;</span>
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$SourceDatastore</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>Datastore <span style="color: pink;">-</span>Server <span style="color: #800080;">$vCenterSource</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;---------------------&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Connecting to source datastore $($SourceDatastore.Name)...&quot;</span>
New<span style="color: pink;">-</span>DatastoreDrive <span style="color: pink;">-</span>DriveName <span style="color: #800080;">$SourceDatastore</span>.Name <span style="color: pink;">-</span>Datastore <span style="color: #800080;">$SourceDatastore</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
<span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VmConfigFile</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-ChildItem</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800000;">&quot;$($SourceDatastore.Name):&quot;</span> <span style="color: #008080; font-style: italic;">-Recurse</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.ItemType <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;VmConfigFile&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Copying VmConfigFile $($VmConfigFile.Name) to TEMP...&quot;</span>
Copy<span style="color: pink;">-</span>DatastoreItem <span style="color: #800080;">$VmConfigFile</span> <span style="color: #800080;">$Temp</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Copying VmConfigFile $($VmConfigFile.Name) to destination...&quot;</span>
Copy<span style="color: pink;">-</span>DatastoreItem <span style="color: #800000;">&quot;$($Temp)\$($VmConfigFile.Name)&quot;</span> <span style="color: #800000;">&quot;Destination:\&quot;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;---------------------&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Start VMconfig section&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;---------------------&quot;</span>
<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;">$VM</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VM <span style="color: pink;">-</span>Server <span style="color: #800080;">$vCenterSource</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</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> VMName<span style="color: pink;">,</span> GuestName<span style="color: pink;">,</span> VMX<span style="color: pink;">,</span> DiskSizesGB
<span style="color: #800080;">$myObj</span>.VMName <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span>.Name
<span style="color: #800080;">$myObj</span>.GuestName <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span>.Guest.HostName
<span style="color: #800080;">$myObj</span>.VMX <span style="color: pink;">=</span> <span style="color: #800080;">$vm</span>.ExtensionData.Config.Files.VmPathName.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: pink;">-</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>
<span style="color: #800080;">$myObj</span>.DiskSizesGB <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VM</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>HardDisk <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.CapacityKB<span style="color: pink;">/</span><span style="color: #804000;">1024</span><span style="color: pink;">/</span><span style="color: #804000;">1024</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span>join <span style="color: #800000;">&quot;;&quot;</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: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Writing VMconfig file to TEMP...&quot;</span>
<span style="color: #800080;">$myCol</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Export-Csv</span> <span style="color: #008080; font-style: italic;">-NoTypeInformation</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800000;">&quot;$($Temp)\VMConfig.csv&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Copying VMConfig file to destination...&quot;</span>
Copy<span style="color: pink;">-</span>DatastoreItem <span style="color: #800000;">&quot;$($Temp)\VMConfig.csv&quot;</span> <span style="color: #800000;">&quot;Destination:\&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;---------------------&quot;</span>
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Disconnecting from both vCenter Servers...&quot;</span>
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: pink;">*</span> <span style="color: #008080; font-style: italic;">-Confirm</span>:<span style="color: #800080;">$false</span>
<span style="color: #008000;">#ENDREGION Script</span></pre></td></tr></table></div>

<p>Download the script here: <a href="http://www.peetersonline.nl/wp-content/Copy-VMXFilesRemote.txt">Copy-VMXFilesRemote (rename to .ps1)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2012/07/poor-mans-virtual-machine-backup-with-powercli/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Calculate vSphere 5 Licenses with Powershell (UPDATED)</title>
		<link>http://www.peetersonline.nl/2011/07/calculate-vsphere-5-licenses-with-powershell/</link>
		<comments>http://www.peetersonline.nl/2011/07/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[<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 [...]]]></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://i0.wp.com/www.peetersonline.nl/wp-content/Vsp5.jpg"><img src="http://i0.wp.com/www.peetersonline.nl/wp-content/Vsp5.jpg?resize=705%2C192" alt="" title="Vsp5" class="alignnone size-full wp-image-489" data-recalc-dims="1" /></a><br />
 <span id="more-484"></span></p>

<div class="wp_syntax"><table><tr><td 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></td></tr></table></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>
]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2011/07/calculate-vsphere-5-licenses-with-powershell/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
		<item>
		<title>Remove vmware memory limits with Powershell</title>
		<link>http://www.peetersonline.nl/2011/07/remove-vmware-memory-limits-with-powershell/</link>
		<comments>http://www.peetersonline.nl/2011/07/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[<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 [...]]]></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"><table><tr><td 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></td></tr></table></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>
]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2011/07/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/2011/02/configure-syslog-on-local-datastore-with-powercli/</link>
		<comments>http://www.peetersonline.nl/2011/02/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[<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 /> </p> #Folder [...]]]></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"><table><tr><td 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></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2011/02/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/2011/01/convert-scripts-to-module/</link>
		<comments>http://www.peetersonline.nl/2011/01/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[<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 [...]]]></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"><table><tr><td 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></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2011/01/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/2010/12/set-vapp-guest-shutdown/</link>
		<comments>http://www.peetersonline.nl/2010/12/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[<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> $VC [...]]]></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"><table><tr><td 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></td></tr></table></div>

<p>Download script: <a href='http://www.peetersonline.nl/wp-content/Set-VAppGuestShutdown.txt'>Set-VAppGuestShutdown (rename to .ps1)</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2010/12/set-vapp-guest-shutdown/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Find LUN ID&#8217;s in VMware with Powershell</title>
		<link>http://www.peetersonline.nl/2010/05/find-lun-ids-in-vmware-with-powershell/</link>
		<comments>http://www.peetersonline.nl/2010/05/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[<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 [...]]]></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"><table><tr><td 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></td></tr></table></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>
]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2010/05/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/2010/05/fix-dcom-event-10005-with-powershell/</link>
		<comments>http://www.peetersonline.nl/2010/05/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[<p>Do you get these events in your system log?</p> <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> <p>Symantec <a href="http://seer.support.veritas.com/docs/240378.htm">explains</a> this is caused by disabling the [...]]]></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"><table><tr><td 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></td></tr></table></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>
]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2010/05/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/2009/10/report-vsphere-alarms-with-powershell/</link>
		<comments>http://www.peetersonline.nl/2009/10/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[<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 God <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></p> # Report vSphere Alarms [...]]]></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"><table><tr><td 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></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2009/10/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/2009/09/add-vmx-path-to-vi-client-using-powershell/</link>
		<comments>http://www.peetersonline.nl/2009/09/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[<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></p> ############################## # [...]]]></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"><table><tr><td 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></td></tr></table></div>

<p>Enjoy!<br />
Hugo</p>
]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/2009/09/add-vmx-path-to-vi-client-using-powershell/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>
