<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PeetersOnline &#187; Scripts</title>
	<atom:link href="http://www.peetersonline.nl/index.php/tag/scripts/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peetersonline.nl</link>
	<description>Using Powershell for (virtually) everything!</description>
	<lastBuildDate>Fri, 19 Aug 2011 09:22:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Set vApp Guest Shutdown</title>
		<link>http://www.peetersonline.nl/index.php/vmware/set-vapp-guest-shutdown/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/set-vapp-guest-shutdown/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 07:28:17 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Shutdown]]></category>
		<category><![CDATA[vApp]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=462</guid>
		<description><![CDATA[Annoyed by the default setting for VM&#8217;s inside a vApp? I was, because when you power down the vApp, the VM&#8217;s are powered down instead of being shutdown cleanly. It can be a tedious task to check and correct this setting for all your vApps. This little script solves that problem for you. Enjoy! $VC <a href='http://www.peetersonline.nl/index.php/vmware/set-vapp-guest-shutdown/'>[...]</a>
Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>Annoyed by the default setting for VM&#8217;s inside a vApp? I was, because when you power down the vApp, the VM&#8217;s are powered down instead of being shutdown cleanly. It can be a tedious task to check and correct this setting for all your vApps. This little script solves that problem for you. Enjoy!</p>

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

<p>Download script: <a href='http://www.peetersonline.nl/wp-content/Set-VAppGuestShutdown.txt'>Set-VAppGuestShutdown (rename to .ps1)</a></p>
<p>Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/set-vapp-guest-shutdown/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Find LUN ID&#8217;s in VMware with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/find-lun-ids-in-vmware-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/find-lun-ids-in-vmware-with-powershell/#comments</comments>
		<pubDate>Thu, 27 May 2010 08:01:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[datastores]]></category>
		<category><![CDATA[LUN ID]]></category>
		<category><![CDATA[Luns]]></category>
		<category><![CDATA[Scripts]]></category>

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

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

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

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

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

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

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

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

<p>Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/report-vsphere-alarms-with-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create a vSwitch Port Overview with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/create-a-vswitch-port-overview-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/create-a-vswitch-port-overview-with-powershell/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 10:42:26 +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[vSwitch]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=404</guid>
		<description><![CDATA[WARNING: VMware vmotion does not check wether there are sufficient ports available on the virtual switch on the destination host. Migrating a vm to a host with insufficient ports will cause the vmotion to complete without warnings, yet the virtual NIC will be disconnected! This issue is descripbed in this KB article. The solution to <a href='http://www.peetersonline.nl/index.php/vmware/create-a-vswitch-port-overview-with-powershell/'>[...]</a>
Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>WARNING: <a href="http://www.vmware.com/" target='_blank'>VMware</a> vmotion does not check wether there are sufficient ports available on the virtual switch on the destination host. Migrating a vm to a host with insufficient ports will cause the vmotion to complete without warnings, yet the virtual NIC will be disconnected! This issue is descripbed in <a href="http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&#038;docType=kc&#038;externalId=1009103&#038;sliceId=1&#038;docTypeID=DT_KB_1_1&#038;dialogID=26680233&#038;stateId=1%200%2026678654">this KB article</a>.<br />
The solution to this problem is to create vSwitches with sufficient ports, obviously. Do you want to know how many ports are currently being used on every vSwitch in your environment? <a href="http://www.vmware.com/products/vsphere/" target='_blank'>vSphere</a> <a href="http://communities.vmware.com/community/developer/windows_toolkit" target='_blank'>PowerCLI</a> to the rescue! Try the following script:</p>
<p><span id="more-404"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #800080;">$VC</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800000;">&quot;MyVCServer&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;">$VMHost</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMHost <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> Name<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;">$VM</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VMHost</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>VM<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;">$NIC</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>NetworkAdapter <span style="color: pink;">-</span>VM <span style="color: #800080;">$VM</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> VMHost<span style="color: pink;">,</span> VM<span style="color: pink;">,</span> NIC<span style="color: pink;">,</span> PortGroup<span style="color: pink;">,</span> vSwitch
			<span style="color: #800080;">$myObj</span>.VMHost <span style="color: pink;">=</span> <span style="color: #800080;">$VMHost</span>.Name
			<span style="color: #800080;">$myObj</span>.VM <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span>.Name
			<span style="color: #800080;">$myObj</span>.NIC <span style="color: pink;">=</span> <span style="color: #800080;">$NIC</span>.Name
			<span style="color: #800080;">$myObj</span>.PortGroup <span style="color: pink;">=</span> Get<span style="color: pink;">-</span>VirtualPortGroup <span style="color: pink;">-</span>VM <span style="color: #800080;">$VM</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$NIC</span>.NetworkName
			<span style="color: #800080;">$myObj</span>.vSwitch <span style="color: pink;">=</span> <span style="color: #800080;">$myObj</span>.PortGroup.VirtualSwitchName
			<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: #000000;">&#125;</span>
<span style="color: #800080;">$myCol</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Group-Object</span> VMHost<span style="color: pink;">,</span> vSwitch <span style="color: #008080; font-style: italic;">-NoElement</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> Name <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span> Count
Disconnect<span style="color: pink;">-</span>VIServer <span style="color: #008080; font-style: italic;">-Confirm</span>:$false</pre></div></div>

<p>Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/create-a-vswitch-port-overview-with-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Examine VMware CPU Ready Times with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/examine-vmware-cpu-ready-times-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/examine-vmware-cpu-ready-times-with-powershell/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 13:26:43 +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[Performance]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Stat]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=398</guid>
		<description><![CDATA[When your (VMware) consolidation ratios are becoming high, it might be smart to keep an eye on your vm&#8217;s CPU Ready Times. Unfortunately, by default, the VI Client will only show realtime ready time statistics. Plus you&#8217;d have to look at each vm individually. Thank God VMware for the PowerCLI! Read this document for more <a href='http://www.peetersonline.nl/index.php/vmware/examine-vmware-cpu-ready-times-with-powershell/'>[...]</a>
Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>When your (<a href="http://www.vmware.com/" target='_blank'>VMware</a>) consolidation ratios are becoming high, it might be smart to keep an eye on your vm&#8217;s CPU Ready Times. Unfortunately, by default, the VI Client will only show realtime ready time statistics. Plus you&#8217;d have to look at each vm individually. Thank <del datetime="2009-06-12T13:20:49+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>! Read <a href="http://viops.vmware.com/home/docs/DOC-1404.pdf;jsessionid=C2335915887A860FD97EA727CDC5DC15">this document </a>for more information on how to interpret the results.</p>
<p><span id="more-398"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Variables</span>
<span style="color: #800080;">$OutFile</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;D:\Scripts\ReadyTimes.csv&quot;</span>
<span style="color: #800080;">$VIServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;MyVIServer.domain.local&quot;</span>
&nbsp;
<span style="color: #008000;"># Connect to Virtual Center</span>
<span style="color: #800080;">$VI</span> <span style="color: pink;">=</span> Connect<span style="color: pink;">-</span>VIServer <span style="color: #800080;">$VIServer</span>
&nbsp;
<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;">$VMHost</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VMHost <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> Name<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;">$VM</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$VMHost</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>VM <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> Name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		<span style="color: #008000;"># Gather Stats</span>
		<span style="color: #800080;">$Ready</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>Stat <span style="color: pink;">-</span>Stat Cpu.Ready.Summation <span style="color: pink;">-</span>RealTime
		<span style="color: #800080;">$Used</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>Stat <span style="color: pink;">-</span>Stat Cpu.Used.Summation <span style="color: pink;">-</span>RealTime
		<span style="color: #800080;">$Wait</span> <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span> <span style="color: pink;">|</span> Get<span style="color: pink;">-</span>Stat <span style="color: pink;">-</span>Stat Cpu.Wait.Summation <span style="color: pink;">-</span>RealTime
		<span style="color: #0000FF;">For</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$a</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span>; <span style="color: #800080;">$a</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$VM</span>.NumCpu; <span style="color: #800080;">$a</span><span style="color: pink;">++</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> VMHost<span style="color: pink;">,</span> VM<span style="color: pink;">,</span> Instance<span style="color: pink;">,</span> <span style="color: pink;">%</span>RDY<span style="color: pink;">,</span> <span style="color: pink;">%</span>USED<span style="color: pink;">,</span> <span style="color: pink;">%</span>WAIT
			<span style="color: #800080;">$myObj</span>.VMHost <span style="color: pink;">=</span> <span style="color: #800080;">$VMHost</span>.Name
			<span style="color: #800080;">$myObj</span>.VM <span style="color: pink;">=</span> <span style="color: #800080;">$VM</span>.Name
			<span style="color: #800080;">$myObj</span>.Instance <span style="color: pink;">=</span> <span style="color: #800080;">$a</span>
			<span style="color: #800080;">$myObj</span>.<span style="color: #800000;">&quot;%RDY&quot;</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><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Ready</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Instance <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$a</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> Value <span style="color: #008080; font-style: italic;">-Average</span><span style="color: #000000;">&#41;</span>.Average<span style="color: #000000;">&#41;</span><span style="color: pink;">/</span><span style="color: #804000;">200</span><span style="color: pink;">,</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
			<span style="color: #800080;">$myObj</span>.<span style="color: #800000;">&quot;%USED&quot;</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><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Used</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Instance <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$a</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> Value <span style="color: #008080; font-style: italic;">-Average</span><span style="color: #000000;">&#41;</span>.Average<span style="color: #000000;">&#41;</span><span style="color: pink;">/</span><span style="color: #804000;">200</span><span style="color: pink;">,</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span>
			<span style="color: #800080;">$myObj</span>.<span style="color: #800000;">&quot;%WAIT&quot;</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><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Wait</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Instance <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$a</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> Value <span style="color: #008080; font-style: italic;">-Average</span><span style="color: #000000;">&#41;</span>.Average<span style="color: #000000;">&#41;</span><span style="color: pink;">/</span><span style="color: #804000;">200</span><span style="color: pink;">,</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</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;">Clear-Variable</span> Ready <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue 
		<span style="color: #008080; font-weight: bold;">Clear-Variable</span> Wait <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue 
		<span style="color: #008080; font-weight: bold;">Clear-Variable</span> Used <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue 
		<span style="color: #008080; font-weight: bold;">Clear-Variable</span> myObj <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
		<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>:<span style="color: #800080;">$false</span>
&nbsp;
<span style="color: #008000;"># Export and launch output</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: #800080;">$OutFile</span>
<span style="color: #008080; font-weight: bold;">Invoke-Item</span> $OutFile</pre></div></div>

<p>Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
<li><a href='http://www.peetersonline.nl/index.php/vmware/calculate-vsphere-5-licenses-with-powershell/' rel='bookmark' title='Calculate vSphere 5 Licenses with Powershell (UPDATED)'>Calculate vSphere 5 Licenses with Powershell (UPDATED)</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/examine-vmware-cpu-ready-times-with-powershell/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Managing Scheduled Tasks Remotely Using Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/managing-scheduled-tasks-remotely-using-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/managing-scheduled-tasks-remotely-using-powershell/#comments</comments>
		<pubDate>Thu, 04 Jun 2009 12:40:04 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[scheduled tasks]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=395</guid>
		<description><![CDATA[The following Powershell functions allow you to manage querying, creating and removing scheduled tasks on one or more computers remotely. The functions use schtasks.exe, which is included in Windows. Unlike the Win32_ScheduledJob WMI class, the schtasks.exe commandline tool will show manually created tasks, as well as script-created ones. The examples show some, but not all <a href='http://www.peetersonline.nl/index.php/powershell/managing-scheduled-tasks-remotely-using-powershell/'>[...]</a>
Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>The following <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> functions allow you to manage querying, creating and removing scheduled tasks on one or more computers remotely.<br />
The functions use schtasks.exe, which is included in Windows. Unlike the Win32_ScheduledJob WMI class, the schtasks.exe commandline tool will show manually created tasks, as well as script-created ones. The examples show some, but not all parameters in action. I think the parameter names are descriptive enough to figure it out, really. If not, take a look at schtasks.exe /?. One tip: try piping a list of computer names to foreach-object and into this function.</p>
<p><span id="more-395"></span><br />
Enjoy.<br />
Hugo</p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>ScheduledTask
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$ComputerName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Computer: $ComputerName&quot;</span>
	<span style="color: #800080;">$Command</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;schtasks.exe /query /s $ComputerName&quot;</span>
	<span style="color: #008080; font-weight: bold;">Invoke-Expression</span> <span style="color: #800080;">$Command</span>
	<span style="color: #008080; font-weight: bold;">Clear-Variable</span> Command <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># EXAMPLE: Get-ScheduledTask -ComputerName Server01</span>
&nbsp;
<span style="color: #0000FF;">Function</span> Remove<span style="color: pink;">-</span>ScheduledTask
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$ComputerName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$TaskName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;blank&quot;</span>
	<span style="color: #000000;">&#41;</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>ScheduledTask <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$ComputerName</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-match</span> <span style="color: #800080;">$TaskName</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: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;Are you sure you want to remove task $TaskName from $ComputerName(y/n)&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;y&quot;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
			<span style="color: #800080;">$Command</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;schtasks.exe /delete /s $ComputerName /tn $TaskName /F&quot;</span>
			<span style="color: #008080; font-weight: bold;">Invoke-Expression</span> <span style="color: #800080;">$Command</span>
			<span style="color: #008080; font-weight: bold;">Clear-Variable</span> Command <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
			<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;Task $TaskName not found on $ComputerName&quot;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># EXAMPLE: Remove-ScheduledTask -ComputerName Server01 -TaskName MyTask</span>
&nbsp;
<span style="color: #0000FF;">Function</span> Create<span style="color: pink;">-</span>ScheduledTask
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$ComputerName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;localhost&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$RunAsUser</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;System&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$TaskName</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;MyTask&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$TaskRun</span> <span style="color: pink;">=</span> <span style="color: #800000;">'&quot;C:\Program Files\Scripts\Script.vbs&quot;'</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Schedule</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Monthly&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Modifier</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;second&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Days</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;SUN&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Months</span> <span style="color: pink;">=</span> <span style="color: #800000;">'&quot;MAR,JUN,SEP,DEC&quot;'</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$StartTime</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;13:00&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$EndTime</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;17:00&quot;</span><span style="color: pink;">,</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Interval</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;60&quot;</span>	
	<span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Computer: $ComputerName&quot;</span>
	<span style="color: #800080;">$Command</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;schtasks.exe /create /s $ComputerName /ru $RunAsUser /tn $TaskName /tr $TaskRun /sc $Schedule /mo $Modifier /d $Days /m $Months /st $StartTime /et $EndTime /ri $Interval /F&quot;</span>
	<span style="color: #008080; font-weight: bold;">Invoke-Expression</span> <span style="color: #800080;">$Command</span>
	<span style="color: #008080; font-weight: bold;">Clear-Variable</span> Command <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&quot;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #008000;"># EXAMPLE: Create-ScheduledTask -ComputerName MyServer -TaskName MyTask02 -TaskRun &quot;D:\scripts\script2.vbs&quot;</span></pre></div></div>

<p>Related posts:<ol>
<li><a href='http://www.peetersonline.nl/index.php/vmware/remove-vmware-memory-limits-with-powershell/' rel='bookmark' title='Remove vmware memory limits with Powershell'>Remove vmware memory limits with Powershell</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/managing-scheduled-tasks-remotely-using-powershell/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Get SQL database size using Windows Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/#comments</comments>
		<pubDate>Tue, 26 May 2009 09:13:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=383</guid>
		<description><![CDATA[The following script examines servers from (part of) your Active Directory domain, identifies SQL servers and lists the instances with their total database sizes. # Get-SQLSizes.ps1 # Created by Hugo Peeters # http://www.peetersonline.nl # Description: Finds SQL Servers in Active Directory and gets the total database size in GB. &#160; #Region VARIABLES $SearchRoot = &#34;OU=Servers,DC=domain,DC=local&#34; <a href='http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>The following script examines servers from (part of) your Active Directory domain, identifies SQL servers and lists the instances with their total database sizes.</p>
<p><span id="more-383"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Get-SQLSizes.ps1</span>
<span style="color: #008000;"># Created by Hugo Peeters</span>
<span style="color: #008000;"># http://www.peetersonline.nl</span>
<span style="color: #008000;"># Description: Finds SQL Servers in Active Directory and gets the total database size in GB.</span>
&nbsp;
<span style="color: #008000;">#Region VARIABLES</span>
	<span style="color: #800080;">$SearchRoot</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;OU=Servers,DC=domain,DC=local&quot;</span>
	<span style="color: #800080;">$OutFile</span> <span style="color: pink;">=</span> <span style="color: #800000;">'D:\scripts\SQLSizes.csv'</span>
	<span style="color: #800080;">$Digits</span> <span style="color: pink;">=</span> <span style="color: #804000;">2</span>
<span style="color: #008000;">#EndRegion VARIABLES</span>
&nbsp;
<span style="color: #008000;">#Region SCRIPT</span>
	<span style="color: #000000;">&#91;</span><span style="color: #008080;">System.Reflection.Assembly</span><span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">'Microsoft.SqlServer.Smo'</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-Null</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;">$Server</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>QADComputer <span style="color: pink;">-</span>SearchRoot <span style="color: #800080;">$SearchRoot</span> <span style="color: pink;">-</span>SizeLimit <span style="color: #804000;">0</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> Name<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;">$Instance</span> <span style="color: #0000FF;">in</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_Service <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$Server</span>.Name <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;">-like</span> <span style="color: #800000;">'MSSQL$*'</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: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Instance</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #0000FF;">break</span><span style="color: #000000;">&#125;</span>
			<span style="color: #008000;"># Connect to SQL</span>
			<span style="color: #800080;">$InstanceString</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;{0}\{1}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$Server</span>.Name<span style="color: pink;">,</span> <span style="color: #800080;">$Instance</span>.Name.Split<span style="color: #000000;">&#40;</span><span style="color: #800000;">'$'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>
			<span style="color: #800080;">$Sql</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">'Microsoft.SqlServer.Management.Smo.Server'</span><span style="color: #000000;">&#41;</span> <span style="color: #800080;">$InstanceString</span>
			<span style="color: #008000;"># Gather information</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> Instance<span style="color: pink;">,</span> TotalDBSizeGB
			<span style="color: #800080;">$myObj</span>.Instance <span style="color: pink;">=</span> <span style="color: #800080;">$InstanceString</span>
			<span style="color: #800080;">$myObj</span>.TotalDBSizeGB <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><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Sql</span>.Databases <span style="color: pink;">|</span> <span style="color: #0000FF;">ForEach</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Size<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;">-Sum</span><span style="color: #000000;">&#41;</span>.Sum <span style="color: pink;">*</span> 1MB <span style="color: pink;">/</span> 1GB<span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$Digits</span><span style="color: #000000;">&#41;</span>
			<span style="color: #800080;">$myCol</span> <span style="color: pink;">+=</span> <span style="color: #800080;">$myObj</span>
			<span style="color: #008000;"># Cleanup</span>
			<span style="color: #008080; font-weight: bold;">Clear-Variable</span> Sql <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
			<span style="color: #008080; font-weight: bold;">Clear-Variable</span> InstanceString <span style="color: #008080; font-style: italic;">-ErrorAction</span> SilentlyContinue
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>	
<span style="color: #008000;">#EndRegion SCRIPT</span>
&nbsp;
<span style="color: #008000;">#Region OUTPUT</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: #800080;">$OutFile</span> <span style="color: #008080; font-style: italic;">-NoTypeInformation</span>
	<span style="color: #008080; font-weight: bold;">Invoke-Item</span> <span style="color: #800080;">$OutFile</span>
<span style="color: #008000;">#EndRegion OUTPUT</span></pre></div></div>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/get-sql-database-size-using-windows-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Synchronize WSUS with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/synchronize-wsus-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/synchronize-wsus-with-powershell/#comments</comments>
		<pubDate>Sat, 04 Apr 2009 07:05:50 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WSUS]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=374</guid>
		<description><![CDATA[Yesterday, I showed you how to script the WSUS Cleanup Wizard with Powershell. Today, the WSUS fun continues! Here&#8217;s how to use powershell to &#8220;manually&#8221; synchronize your WSUS server, i.e. download the latest updates. #Region VARIABLES &#160; # WSUS Connection Parameters: &#91;String&#93;$updateServer = &#34;myWSUSServer.domain.local&#34; &#91;Boolean&#93;$useSecureConnection = $False &#91;Int32&#93;$portNumber = 80 &#160; #EndRegion VARIABLES &#160; #Region <a href='http://www.peetersonline.nl/index.php/powershell/synchronize-wsus-with-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.peetersonline.nl/index.php/powershell/wsus-cleanup-with-powershell/">Yesterday</a>, I showed you how to script the WSUS Cleanup Wizard with <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a>. Today, the WSUS fun continues! Here&#8217;s how to use <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>powershell</a> to &#8220;manually&#8221; synchronize your WSUS server, i.e. download the latest updates.</p>
<p><span id="more-374"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#Region VARIABLES</span>
&nbsp;
<span style="color: #008000;"># WSUS Connection Parameters:</span>
<span style="color: #000000;">&#91;</span><span style="color: #008080;">String</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$updateServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;myWSUSServer.domain.local&quot;</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$useSecureConnection</span> <span style="color: pink;">=</span> <span style="color: #800080;">$False</span>
<span style="color: #000000;">&#91;</span>Int32<span style="color: #000000;">&#93;</span><span style="color: #800080;">$portNumber</span> <span style="color: pink;">=</span> <span style="color: #804000;">80</span>
&nbsp;
<span style="color: #008000;">#EndRegion VARIABLES</span>
&nbsp;
<span style="color: #008000;">#Region SCRIPT</span>
&nbsp;
<span style="color: #008000;"># Load .NET assembly</span>
<span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.UpdateServices.Administration&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Connect to WSUS Server</span>
<span style="color: #800080;">$Wsus</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.UpdateServices.Administration.AdminProxy<span style="color: #000000;">&#93;</span>::getUpdateServer<span style="color: #000000;">&#40;</span><span style="color: #800080;">$updateServer</span><span style="color: pink;">,</span><span style="color: #800080;">$useSecureConnection</span><span style="color: pink;">,</span><span style="color: #800080;">$portNumber</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Perform Synchronization</span>
<span style="color: #800080;">$Subscription</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Wsus</span>.GetSubscription<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$Subscription</span>.StartSynchronization<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;">#EndRegion SCRIPT</span></pre></div></div>

<p>Download the script here: <a href='http://www.peetersonline.nl/wp-content/synchronize-wsus.txt'>Synchronize-Wsus (rename to .ps1)</a></p>
<p>Enjoy!<br />
Hugo</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/synchronize-wsus-with-powershell/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>WSUS Cleanup with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/wsus-cleanup-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/wsus-cleanup-with-powershell/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 06:51:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WSUS]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=369</guid>
		<description><![CDATA[If you manage a Windows Server Update Services (WSUS) server, you probably run the Server Cleanup Wizard every once and a while. It removes old and superseded updates and computers that haven&#8217;t reported their status for more than 30 days. Wouldn&#8217;t it be nice to schedule such a cleanup to run every month? Too bad <a href='http://www.peetersonline.nl/index.php/powershell/wsus-cleanup-with-powershell/'>[...]</a>
No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you manage a Windows Server Update Services (WSUS) server, you probably run the Server Cleanup Wizard every once and a while. It removes old and superseded updates and computers that haven&#8217;t reported their status for more than 30 days. Wouldn&#8217;t it be nice to schedule such a cleanup to run every month? Too bad there&#8217;s no command line tool I know of that can help you out with this. <a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> to the rescue!<br />
<a href="http://www.microsoft.com/windowsserver2003/technologies/management/powershell/default.mspx" target='_blank'>Powershell</a> can not only run the built-in commandlets or even those added by snapins. It can leverage the full power of the .NET Framework. Browse the <a href="http://msdn.microsoft.com/en-us/library/default.aspx">MSDN Library</a> if you want to find more cool things you can do with it. Here&#8217;s a script that uses this information to run the cleanup wizard:</p>
<p><span id="more-369"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;">#Region VARIABLES</span>
&nbsp;
<span style="color: #008000;"># WSUS Connection Parameters:</span>
<span style="color: #000000;">&#91;</span><span style="color: #008080;">String</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$updateServer</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;myWSUSServer.domain.local&quot;</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$useSecureConnection</span> <span style="color: pink;">=</span> <span style="color: #800080;">$False</span>
<span style="color: #000000;">&#91;</span>Int32<span style="color: #000000;">&#93;</span><span style="color: #800080;">$portNumber</span> <span style="color: pink;">=</span> <span style="color: #804000;">80</span>
&nbsp;
<span style="color: #008000;"># Cleanup Parameters:</span>
<span style="color: #008000;"># Decline updates that have not been approved for 30 days or more, are not currently needed by any clients, and are superseded by an aproved update.</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$supersededUpdates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #008000;"># Decline updates that aren't approved and have been expired my Microsoft.</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$expiredUpdates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #008000;"># Delete updates that are expired and have not been approved for 30 days or more.</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$obsoleteUpdates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #008000;"># Delete older update revisions that have not been approved for 30 days or more.</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$compressUpdates</span> <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #008000;"># Delete computers that have not contacted the server in 30 days or more.</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$obsoleteComputers</span> <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
<span style="color: #008000;"># Delete update files that aren't needed by updates or downstream servers.</span>
<span style="color: #000000;">&#91;</span>Boolean<span style="color: #000000;">&#93;</span><span style="color: #800080;">$unneededContentFiles</span> <span style="color: pink;">=</span> <span style="color: #800080;">$True</span>
&nbsp;
<span style="color: #008000;">#EndRegion VARIABLES</span>
&nbsp;
<span style="color: #008000;">#Region SCRIPT</span>
&nbsp;
<span style="color: #008000;"># Load .NET assembly</span>
<span style="color: #000000;">&#91;</span>void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#91;</span>reflection.assembly<span style="color: #000000;">&#93;</span>::<span style="color: #800000;">LoadWithPartialName</span><span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;Microsoft.UpdateServices.Administration&quot;</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Connect to WSUS Server</span>
<span style="color: #800080;">$Wsus</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>Microsoft.UpdateServices.Administration.AdminProxy<span style="color: #000000;">&#93;</span>::getUpdateServer<span style="color: #000000;">&#40;</span><span style="color: #800080;">$updateServer</span><span style="color: pink;">,</span><span style="color: #800080;">$useSecureConnection</span><span style="color: pink;">,</span><span style="color: #800080;">$portNumber</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;"># Perform Cleanup</span>
<span style="color: #800080;">$CleanupManager</span> <span style="color: pink;">=</span> <span style="color: #800080;">$Wsus</span>.GetCleanupManager<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$CleanupScope</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> Microsoft.UpdateServices.Administration.CleanupScope<span style="color: #000000;">&#40;</span><span style="color: #800080;">$supersededUpdates</span><span style="color: pink;">,</span><span style="color: #800080;">$expiredUpdates</span><span style="color: pink;">,</span><span style="color: #800080;">$obsoleteUpdates</span><span style="color: pink;">,</span><span style="color: #800080;">$compressUpdates</span><span style="color: pink;">,</span><span style="color: #800080;">$obsoleteComputers</span><span style="color: pink;">,</span><span style="color: #800080;">$unneededContentFiles</span><span style="color: #000000;">&#41;</span>
<span style="color: #800080;">$CleanupManager</span>.PerformCleanup<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CleanupScope</span><span style="color: #000000;">&#41;</span>
&nbsp;
<span style="color: #008000;">#EndRegion SCRIPT</span></pre></div></div>

<p>Download it here: <a href="http://www.peetersonline.nl/wp-content/cleanup-wsus.txt">Cleanup-Wsus (rename to .ps1)</a></p>
<p>Happy scheduling!</p>
<p>Hugo</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/wsus-cleanup-with-powershell/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

