<?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</title>
	<atom:link href="http://www.peetersonline.nl/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peetersonline.nl</link>
	<description>Using Powershell for (virtually) everything!</description>
	<lastBuildDate>Thu, 27 May 2010 08:01:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<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 [...]


No related posts.]]></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: #000000;">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: #000000;">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: #000000;">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><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/find-lun-ids-in-vmware-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</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 [...]


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><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </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; [...]


No related posts.]]></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-File</span> <span style="color: #800080;">$Outfile</span>
<span style="color: #008080; font-weight: bold;">ii</span> $Outfile</pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/report-vsphere-alarms-with-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Add Vmx Path to VI Client using Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/add-vmx-path-to-vi-client-using-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/add-vmx-path-to-vi-client-using-powershell/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 08:56:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VI Toolkit 1.5]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[Custom Fields]]></category>
		<category><![CDATA[vSphere Client]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=415</guid>
		<description><![CDATA[The following script is a request from David Gontie, who was kind enough to comment on a previous post. He&#8217;d like to add the location of his vm&#8217;s to a custom field. This is especially handy if you store all the files for a vm in a single datastore. Here you go David: ############################## # Script [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>The following script is a request from David Gontie, who was kind enough to comment on a previous post.</p>
<p>He&#8217;d like to add the location of his vm&#8217;s to a custom field. This is especially handy if you store all the files for a vm in a single datastore.</p>
<p>Here you go David:</p>
<p><span id="more-415"></span></p>

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

<p>Enjoy!<br />
Hugo</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/add-vmx-path-to-vi-client-using-powershell/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Set VMware Snapshot Location with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/vmware/set-vmware-snapshot-location-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/vmware/set-vmware-snapshot-location-with-powershell/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 13:09:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerCLI 4.0]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[VI Toolkit 1.5]]></category>
		<category><![CDATA[VMware]]></category>
		<category><![CDATA[PowerCLI]]></category>
		<category><![CDATA[snapshots]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=411</guid>
		<description><![CDATA[Snapshots are m*th3rfcukers. If you&#8217;re not careful, they will mass-murder your vms. Yet they allow you to time-travel! You want to use them, but how to prevent a massacre? Here&#8217;s how: relocate the delta files. When you create a snapshot, the current state of the vm is preserved by leaving the disk files alone. All changes [...]


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

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

<p>You can download it here: <a href="http://www.peetersonline.nl/wp-content/Set-VMSnapshotLocation.txt">Set-VMSnapshotLocation (rename to .ps1)</a></p>
<p>I tried hard as I could, but I could not get my vm to die. Even running the script, creating a snapshot, running the script to move the working location again and deleting the snapshot did not prove a problem. However, I urge you to be careful with it. I&#8217;m not responsable for anything you do with it.</p>
<p>Tiny glitch: the VI Client shows the wrong datastore location when a vm has a snapshot in a modified workingdir.</p>
<p>Enjoy.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/set-vmware-snapshot-location-with-powershell/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>User Confirmation in Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/user-confirmation-in-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/user-confirmation-in-powershell/#comments</comments>
		<pubDate>Wed, 15 Jul 2009 13:48:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[function]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=407</guid>
		<description><![CDATA[Built-in cmdlets usually offer the -Confirm parameter whenever you need user confirmation. When writing your own scripts, you might want to ask the eventual user of the script for confirmation yourself. This handy little function (store it in your profile!) allows you to ask for confirmation whenever, where-ever. (Try not to bug your users too [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>Built-in cmdlets usually offer the -Confirm parameter whenever you need user confirmation. When writing your own scripts, you might want to ask the eventual user of the script for confirmation yourself. This handy little function (store it in your profile!) allows you to ask for confirmation whenever, where-ever. (Try not to bug your users too much.)</p>
<p><span id="more-407"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #008000;"># Description: Ask a user to answer a question with either yes or no.</span>
&nbsp;
<span style="color: #008000;"># Example use: </span>
<span style="color: #008000;"># If (Ask-YesOrNo)</span>
<span style="color: #008000;"># 	{ </span>
<span style="color: #008000;">#	# User has confirmed</span>
<span style="color: #008000;">#	...</span>
<span style="color: #008000;">#	}</span>
<span style="color: #008000;">#	Else</span>
<span style="color: #008000;">#	{</span>
<span style="color: #008000;">#	# User did not confirm</span>
<span style="color: #008000;">#	...</span>
<span style="color: #008000;">#	}</span>
&nbsp;
<span style="color: #0000FF;">Function</span> Ask<span style="color: pink;">-</span>YesOrNo
	<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;">$title</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Confirm&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;">$message</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Are you sure?&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$choiceYes</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Management.Automation.Host.ChoiceDescription <span style="color: #800000;">&quot;&amp;Yes&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Answer Yes.&quot;</span>
	<span style="color: #800080;">$choiceNo</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Management.Automation.Host.ChoiceDescription <span style="color: #800000;">&quot;&amp;No&quot;</span><span style="color: pink;">,</span> <span style="color: #800000;">&quot;Answer No.&quot;</span>
	<span style="color: #800080;">$options</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span>System.Management.Automation.Host.ChoiceDescription<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$choiceYes</span><span style="color: pink;">,</span> <span style="color: #800080;">$choiceNo</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$result</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.ui.PromptForChoice<span style="color: #000000;">&#40;</span><span style="color: #800080;">$title</span><span style="color: pink;">,</span> <span style="color: #800080;">$message</span><span style="color: pink;">,</span> <span style="color: #800080;">$options</span><span style="color: pink;">,</span> <span style="color: #000000;">1</span><span style="color: #000000;">&#41;</span>
		<span style="color: #0000FF;">switch</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$result</span><span style="color: #000000;">&#41;</span>
    	<span style="color: #000000;">&#123;</span>
			<span style="color: #000000;">0</span> 
			<span style="color: #000000;">&#123;</span>
			<span style="color: #0000FF;">Return</span> <span style="color: #800080;">$true</span>
			<span style="color: #000000;">&#125;</span>
&nbsp;
			<span style="color: #000000;">1</span> 
			<span style="color: #000000;">&#123;</span>
			<span style="color: #0000FF;">Return</span> <span style="color: #800080;">$false</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/user-confirmation-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</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 [...]


No related posts.]]></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><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/create-a-vswitch-port-overview-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</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 [...]


No related posts.]]></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: #000000;">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: #000000;">200</span><span style="color: pink;">,</span><span style="color: #000000;">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: #000000;">200</span><span style="color: pink;">,</span><span style="color: #000000;">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: #000000;">200</span><span style="color: pink;">,</span><span style="color: #000000;">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><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/vmware/examine-vmware-cpu-ready-times-with-powershell/feed/</wfw:commentRss>
		<slash:comments>5</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 [...]


No related posts.]]></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><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/managing-scheduled-tasks-remotely-using-powershell/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Increment PowerGUI Xml Version with Powershell</title>
		<link>http://www.peetersonline.nl/index.php/powershell/increment-powergui-xml-version-with-powershell/</link>
		<comments>http://www.peetersonline.nl/index.php/powershell/increment-powergui-xml-version-with-powershell/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 12:14:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PowerGUI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Config]]></category>
		<category><![CDATA[Xml]]></category>

		<guid isPermaLink="false">http://www.peetersonline.nl/?p=387</guid>
		<description><![CDATA[If you are using PowerGUI (which you should) and some of your collaegues do too, you might want to use a central configuration. Whenever you want to update the central configuration xml file, you need to increment the version number in order to push this change out to your collaegues. The following function increments the [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>If you are using <a href="http://powergui.org">PowerGUI</a> (which you should) and some of your collaegues do too, you might want to use a <a href="http://wiki.powergui.org/index.php/Customizing_PowerGUI_Configuration">central configuration</a>. Whenever you want to update the central configuration xml file, you need to increment the version number in order to push this change out to your collaegues. The following function increments the version number for you and even allows you to store the new file to the central location at the same time. All without having to edit the complex xml file manually. It even saves a backup copy of your central config file in case you mess up ;) It assumes you use a simple x.y version number, so please start out with 2.0 when setting up your config.<br />
To update your central config: just make the modifications within <a href="http://powergui.org" target='_blank'>PowerGUI</a> and then run this function.</p>
<p><span id="more-387"></span></p>

<div class="wp_syntax"><div class="code"><pre class="powershell" style="font-family:monospace;"><span style="color: #0000FF;">Function</span> Increment<span style="color: pink;">-</span>PowerGuiXmlVersion
	<span style="color: #000000;">&#123;</span>
	<span style="color: #0000FF;">Param</span><span style="color: #000000;">&#40;</span>
	<span style="color: #800080;">$PersonalXmlFile</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Join-Path</span> <span style="color: #800080;">$env</span>:appdata <span style="color: #800000;">&quot;Quest Software\PowerGUI\config.xml&quot;</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$CentralXmlFile</span> <span style="color: pink;">=</span> <span style="color: #800000;">'P:\Centrally Managed Files\config.xml'</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$XPath</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;//container[@name='version']&quot;</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$IncrementMajor</span> <span style="color: pink;">=</span> <span style="color: #800080;">$false</span><span style="color: pink;">,</span>
	<span style="color: #800080;">$IncrementMinor</span> <span style="color: pink;">=</span> <span style="color: #800080;">$true</span>
	<span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Load central xml file (for backup and reading the current version number)</span>
	<span style="color: #800080;">$CentralConfig</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Xml.XmlDocument
	<span style="color: #800080;">$CentralConfig</span>.Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CentralXmlFile</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Select the correct node</span>
	<span style="color: #800080;">$NodeToRead</span> <span style="color: pink;">=</span> <span style="color: #800080;">$CentralConfig</span>.SelectSingleNode<span style="color: #000000;">&#40;</span><span style="color: #800080;">$XPath</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Read the current version</span>
	<span style="color: #800080;">$CurrentVersion</span> <span style="color: pink;">=</span> <span style="color: #800080;">$NodeToRead</span>.Value
	<span style="color: #800080;">$MajorVersion</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">Int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$CurrentVersion</span>.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: #000000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$MinorVersion</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">Int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$CurrentVersion</span>.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: #000000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Current Version of Central Xml File: $CurrentVersion&quot;</span>
&nbsp;
	<span style="color: #008000;"># Backup central xml file</span>
	<span style="color: #800080;">$BackupFileName</span> <span style="color: pink;">=</span> <span style="color: #800080;">$CentralXmlFile</span>.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;.xml&quot;</span><span style="color: pink;">,</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;_{0}.xml&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$CurrentVersion</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #800080;">$CentralConfig</span>.Save<span style="color: #000000;">&#40;</span><span style="color: #800080;">$BackupFileName</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Load personal xml file</span>
	<span style="color: #800080;">$PersonalConfig</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Xml.XmlDocument
	<span style="color: #800080;">$PersonalConfig</span>.Load<span style="color: #000000;">&#40;</span><span style="color: #800080;">$PersonalXmlFile</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Select the correct node</span>
	<span style="color: #800080;">$NodeToBeChanged</span> <span style="color: pink;">=</span> <span style="color: #800080;">$PersonalConfig</span>.SelectSingleNode<span style="color: #000000;">&#40;</span><span style="color: #800080;">$XPath</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008000;"># Increment the version</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$IncrementMinor</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$MinorVersion</span><span style="color: pink;">++</span><span style="color: #000000;">&#125;</span>
	<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$IncrementMajor</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$MajorVersion</span><span style="color: pink;">++</span>; <span style="color: #800080;">$MinorVersion</span> <span style="color: pink;">=</span> <span style="color: #000000;">0</span><span style="color: #000000;">&#125;</span>
	<span style="color: #800080;">$newVersion</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span>::Concat<span style="color: #000000;">&#40;</span><span style="color: #800080;">$MajorVersion</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;.&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$MinorVersion</span><span style="color: #000000;">&#41;</span>
	<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;New Version of Central Xml File: $newVersion&quot;</span>
&nbsp;
	<span style="color: #008000;"># Write the new version</span>
	<span style="color: #800080;">$NodeToBeChanged</span>.Value <span style="color: pink;">=</span> <span style="color: #800080;">$newVersion</span>
&nbsp;
	<span style="color: #008000;"># Save the personal xml file as the new central xml file</span>
	<span style="color: #800080;">$PersonalConfig</span>.Save<span style="color: #000000;">&#40;</span><span style="color: #800080;">$CentralXmlFile</span><span style="color: #000000;">&#41;</span>	
	<span style="color: #000000;">&#125;</span></pre></div></div>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.peetersonline.nl/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>

<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.peetersonline.nl/index.php/powershell/increment-powergui-xml-version-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
