<?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>EnterpriseAdmins.org</title>
	<atom:link href="http://enterpriseadmins.org/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://enterpriseadmins.org/blog</link>
	<description>Random topics in Virtualization and Systems Administration</description>
	<lastBuildDate>Wed, 22 May 2013 20:55:51 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>When are Windows patches happening?</title>
		<link>http://enterpriseadmins.org/blog/scripting/when-are-windows-patches-happening/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/when-are-windows-patches-happening/#comments</comments>
		<pubDate>Wed, 22 May 2013 20:55:51 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1269</guid>
		<description><![CDATA[As most people know, Microsoft releases patches on the second Tuesday of the month. In some organizations these patches are deployed to development, test and QA systems within a couple]]></description>
				<content:encoded><![CDATA[<p>As most people know, Microsoft releases patches on the second Tuesday of the month.  In some organizations these patches are deployed to development, test and QA systems within a couple of days of the release.  However, production systems can&#8217;t be patched until the next maintenance window.  Assuming this patch window is on a Saturday, we need to find the first Saturday after the second Tuesday.  When looking at a calendar this is pretty simple for most people to figure out.  However, when you need a whole years worth it takes a few minutes to calculate.  What we need is some code to look these up for us&#8230;like this function:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>WsusSaturday <span style="color: #000000;">&#123;</span><br />
&nbsp;<span style="color: #0000FF;">param</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$date</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <br />
&nbsp;<span style="color: #800080;">$numberOfTuesdays</span><span style="color: pink;">=</span><span style="color: #804000;">0</span> <br />
&nbsp;<br />
&nbsp; <span style="color: #804000;">1</span>..<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span>::DaysInMonth<span style="color: #000000;">&#40;</span> <span style="color: #800080;">$date</span>.year <span style="color: pink;">,</span> <span style="color: #800080;">$date</span>.month <span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #800080;">$thisDate</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Get-Date</span> <span style="color: #800000;">&quot;$($date.month)/$($_)/$($date.year)&quot;</span><br />
&nbsp; &nbsp;<span style="color: #0000FF;">if</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;">$thisDate</span>.DayOfWeek <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'Tuesday'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$numberOfTuesdays</span><span style="color: pink;">++</span> <br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$numberOfTuesdays</span> <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> &nbsp;<br />
&nbsp; &nbsp; &nbsp;<span style="color: #800080;">$thisDate</span>.AddDays<span style="color: #000000;">&#40;</span><span style="color: #804000;">4</span><span style="color: #000000;">&#41;</span>.ToLongDateString<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Line 2: accept the date as a parameter and cast it to a date/time value, defaulting to today&#8217;s date if nothing is provided<br />
Line 3: max sure we don&#8217;t think its Tuesday already<br />
Line 5: starting on the first of each month, loop through the max number of days in the month<br />
Line 8: if the date is Tuesday, add one to the counter<br />
Line 9: once we find the second Tuesday<br />
Line 10: add 4 more days to find the following Saturday and return the date text</p>
<p>You can take this function and do something creative, like find the next 5 years worth of patch Saturdays.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #804000;">13</span>..<span style="color: #804000;">18</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #800080;">$year</span> <span style="color: pink;">=</span> <a href="about:blank"><span style="color: #000080;">$_</span></a><br />
&nbsp; <span style="color: #804000;">1</span>..<span style="color: #804000;">12</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span> Get<span style="color: pink;">-</span>WsusSaturday <span style="color: #800000;">&quot;$_/1/$year&quot;</span> <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/when-are-windows-patches-happening/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashtables: Item has already been added</title>
		<link>http://enterpriseadmins.org/blog/scripting/hashtables-item-has-already-been-added/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/hashtables-item-has-already-been-added/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 13:30:41 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1249</guid>
		<description><![CDATA[In my previous two posts about hashtables I provided examples for creating a hashtable, returning a specific value and a description around performance. This post will focus on the errors]]></description>
				<content:encoded><![CDATA[<p>In my previous two posts about hashtables I provided examples for creating a hashtable, returning a specific value and a description around performance.  This post will focus on the errors you should expect if you start using a hashtable.</p>
<p>The most common exception I see happens when the data I&#8217;m storing in the hashtable is not unique.  For example, in the first post in the series we created a simple hashtable from a list of HTML colors.  If my input list had the color &#8216;red&#8217; listed on two different lines, I would have seen an error similar to this:</p>
<p><font color='red'>Add : Exception calling &#8220;Add&#8221; with &#8220;2&#8243; argument(s): &#8220;Item has already been added. Key in dictionary: &#8216;Red&#8217;  Key being<br />
 added: &#8216;Red&#8217;&#8221;<br />
At line:1 char:17<br />
+ $colorCodeHT.Add <<<< ('Red','123456')<br />
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException<br />
    + FullyQualifiedErrorId : DotNetMethodException<br />
</font></p>
<p>This is an easy error message to generate if you want to see the actual error.  Follow the examples in the first post and then try and re-add the color red using the following line:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$colorCodeHT</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Red'</span><span style="color: pink;">,</span><span style="color: #800000;">'123456'</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>
<p>The hashtable object includes a .Contains method, which can be used in an if statement to prevent this exception from happening:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$colorCodeHT</span>.Contains<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Red'</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800000;">&quot;Color 'red' has already been added&quot;</span> <span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$colorCodeHT</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Red'</span><span style="color: pink;">,</span><span style="color: #800000;">'123456'</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>This statement checks for the presence of a &#8216;Red&#8217; item and only attempts to add if a value does not already exist.</p>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/hashtables-item-has-already-been-added/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashtables: Adding, Updating and Removing Items</title>
		<link>http://enterpriseadmins.org/blog/scripting/hashtables-adding-updating-and-removing-items/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/hashtables-adding-updating-and-removing-items/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 13:20:15 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1252</guid>
		<description><![CDATA[To help describe these concepts, I have listed a few examples based on a CSV file containing HTML color codes. For purposes of sample data, create an array object of]]></description>
				<content:encoded><![CDATA[<p>To help describe these concepts, I have listed a few examples based on <a title="HTML Color Codes" href="http://enterpriseadmins.org/blog/wp-content/uploads/2013/04/ColorCodes.csv" target="_blank">a CSV file containing HTML color codes</a>.</p>
<p>For purposes of sample data, create an array object of colors and HTML color codes.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$colorCodes</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Import-Csv</span> ColorCodes.csv</div></td></tr></tbody></table></div>
<p>Define a hashtable object:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$colorCodeHT</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Examples for adding to a hashtable:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;"># For the old vbscripter (this is the method I use)</span><br />
<span style="color: #008000;"># $colorCodeHT.Add('key','value')</span><br />
<span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$colorCodeHT</span>.Add<span style="color: #000000;">&#40;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName<span style="color: pink;">,</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Code<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008000;"># For the person who likes equal signs</span><br />
<span style="color: #008000;"># $colorCodeHT['key'] = 'Value'</span><br />
<span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span><span style="color: #800080;">$colorCodeHT</span><span style="color: #000000;">&#91;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName<span style="color: #000000;">&#93;</span> <span style="color: pink;">=</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Code<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Examples for updating existing entries</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;"># Using square brackets, just like the above 'add' example</span><br />
<span style="color: #800080;">$colorCodeHT</span><span style="color: #000000;">&#91;</span><span style="color: #800000;">'Red'</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">=</span> <span style="color: #800000;">'#123456'</span></div></td></tr></tbody></table></div>
<p>Examples for removing from a hashtable:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;"># Remove a single item by key</span><br />
<span style="color: #800080;">$colorCodeHT</span>.Remove<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Red'</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;"># Remove all of the entries from the hashtable:</span><br />
<span style="color: #800080;">$colorCodeHT</span>.<span style="color: #008080; font-weight: bold;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/hashtables-adding-updating-and-removing-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashtables: Performance</title>
		<link>http://enterpriseadmins.org/blog/scripting/hashtables-performance/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/hashtables-performance/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 13:10:44 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1245</guid>
		<description><![CDATA[In the previous post I provided a quick introduction to creating and using a hashtable object. If you are paying attention, you might have asked &#8220;Why would I go to]]></description>
				<content:encoded><![CDATA[<p>In the previous post I provided a quick introduction to creating and using a hashtable object.  If you are paying attention, you might have asked &#8220;Why would I go to extra work to create a hashtable when I can make the original object work?&#8221; The answer is performance&#8230;but lets expand on this answer.</p>
<p>We can use Measure-Command to show how long each of these statements takes to execute.  Here is a quick refresher on using Measure-Command to show how long it takes to execute a command&#8230;just replace &#8220;PUT EACH COMMAND HERE&#8221; with your actual command:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Measure-Command</span> <span style="color: #000000;">&#123;</span> <span style="color: #800000;">&quot;PUT EACH COMMAND HERE&quot;</span> <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.TotalMilliseconds</div></td></tr></tbody></table></div>
<p>Using the examples from the previous post, we return Total Millisecond execution times of:</p>
<table border="1">
<tr>
<td>Example</td>
<td>Execution Time (ms)</td>
</tr>
<tr>
<td>2: Select item from array object</td>
<td>19.0030</td>
</tr>
<tr>
<td>3: Create a hashtable from array object</td>
<td>19.2045</td>
</tr>
<tr>
<td>4: Select item from hashtable</td>
<td>0.0311</td>
</tr>
</table>
<p>In this sample, returning a value from the hashtable (example 4) is 600 times faster than using the array object (example 2)!  Just because this step was faster, it doesn&#8217;t mean hashtables are always best.  If we take into account the overhead from creating the hashtable (add the execution times of example 3 and 4 together), then using the array object is actually more efficient.  The performance gain is only noticeable if you plan to re-use the hashtable over several iterations.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;"># Example 5: Selecting multiple times from array object</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Measure-Command</span> <span style="color: #000000;">&#123;</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'Red'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.Code<br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'Blue'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.Code<br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'Green'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.Code<br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'Black'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.Code<br />
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.TotalMilliseconds<br />
<br />
<span style="color: #008000;"># Example 6: Creating hashtable and selecting from it multiple times</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Measure-Command</span> <span style="color: #000000;">&#123;</span><br />
<span style="color: #800080;">$colorCodeHT</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span> <span style="color: #800080;">$colorCodeHT</span>.Add<span style="color: #000000;">&#40;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName<span style="color: pink;">,</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Code<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$colorCodeHT</span><span style="color: #000000;">&#91;</span><span style="color: #800000;">'Red'</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #800080;">$colorCodeHT</span><span style="color: #000000;">&#91;</span><span style="color: #800000;">'Blue'</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #800080;">$colorCodeHT</span><span style="color: #000000;">&#91;</span><span style="color: #800000;">'Green'</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #800080;">$colorCodeHT</span><span style="color: #000000;">&#91;</span><span style="color: #800000;">'Black'</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.TotalMilliseconds</div></td></tr></tbody></table></div>
<table border="1">
<tr>
<td>Example</td>
<td>Execution Time (ms)</td>
</tr>
<tr>
<td>5: Select from array object multiple times</td>
<td>57.7053</td>
</tr>
<tr>
<td>6: Create hashtable and select from it multiple times</td>
<td>17.8322</td>
</tr>
</table>
<p>Even though a hashtable requires a bit of setup, it becomes more efficient with repetitive use.  The example with HTML color codes only has around 290 items in the hashtable.  This performance improvement is more noticeable with larger hashtables, especially when they are used many times within the script.</p>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/hashtables-performance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hashtables: Introduction</title>
		<link>http://enterpriseadmins.org/blog/scripting/hashtables-introduction/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/hashtables-introduction/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 13:00:14 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1237</guid>
		<description><![CDATA[I was recently working on a script for a co-worker who is trying to learn more powershell. In the script I had used a couple of hashtables to store information&#8230;which]]></description>
				<content:encoded><![CDATA[<p>I was recently working on a script for a co-worker who is trying to learn more powershell. In the script I had used a couple of hashtables to store information&#8230;which caused a couple of questions as he was reviewing the code. This post is an introduction to powershell hashtables.</p>
<p>A hashtable stores indexed key-value pairs in memory and is similar to the vbscript dictionary object. To help describe these concepts, I have listed a few examples based on <a title="HTML Color Codes" href="http://enterpriseadmins.org/blog/wp-content/uploads/2013/04/ColorCodes.csv" target="_blank">a CSV file containing HTML color codes</a>.</p>
<p>The examples below will:<br />
1.) Import the CSV into a powershell array object,<br />
2.) Show how to use the array object to return a specific code given a color name<br />
3.) Convert the object from step 1 into a hashtable<br />
4.) Show how to use the hashtable to return a specific code given a color name</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;"># Example 1:</span><br />
<span style="color: #800080;">$colorCodes</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Import-Csv</span> ColorCodes.csv<br />
<br />
<span style="color: #008000;"># Example 2:</span><br />
<span style="color: #008000;"># Using just the array object created from Import-CSV</span><br />
<span style="color: #008000;"># we can select the color code for Red with just one line</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Where-Object</span> <span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'Red'</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.Code<br />
<br />
<span style="color: #008000;"># Example 3:</span><br />
<span style="color: #008000;"># We could also create a hash table and store each item</span><br />
<span style="color: #008000;"># from the array using a couple lines of code</span><br />
<span style="color: #800080;">$colorCodeHT</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$colorCodes</span> <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span> <span style="color: #800080;">$colorCodeHT</span>.Add<span style="color: #000000;">&#40;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ColorName<span style="color: pink;">,</span> <a href="about:blank"><span style="color: #000080;">$_</span></a>.Code<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008000;"># Example 4</span><br />
<span style="color: #008000;"># And then we can retreive the code for red using either of the</span><br />
<span style="color: #008000;"># examples below. Note: you only need one as they return the same</span><br />
<span style="color: #008000;"># value. &nbsp;The first sample is my preferred method, but either works.</span><br />
<span style="color: #800080;">$colorCodeHT</span><span style="color: #000000;">&#91;</span><span style="color: #800000;">'Red'</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #800080;">$colorCodeHT</span>.Item<span style="color: #000000;">&#40;</span><span style="color: #800000;">'Red'</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/hashtables-introduction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ADSI to clear an attribute</title>
		<link>http://enterpriseadmins.org/blog/scripting/using-adsi-to-clear-an-attribute/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/using-adsi-to-clear-an-attribute/#comments</comments>
		<pubDate>Thu, 21 Mar 2013 13:00:06 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Messaging]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1232</guid>
		<description><![CDATA[I have many scripts that write information into Active Directory. Sometimes I need to do the opposite &#8212; remove or blank out an attribute. All of the following examples will]]></description>
				<content:encoded><![CDATA[<p>I have many scripts that write information into Active Directory.  Sometimes I need to do the opposite &#8212; remove or blank out an attribute.  </p>
<p>All of the following examples will require a distinguishedName value in AD, so I will set a common variable here.  You will need a valid distinguishedName defined in a varible like this if you want to follow along.</p>
<pre>
$distinguishedName = "CN=Brian Wuchner,OU=Test Users,DC=bwuch,DC=local"
</pre>
<p>The first test we will do is to update the displayName of the user.  This is easy&#8230;we don&#8217;t care what the existing value is, we are just going to set it to whatever string value we want.  We will do this by creating an object representing the Directory Entry of my user, updating the displayName attribute of that object and finally updating/committing that change back to the directory as follows.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$objUser</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> DirectoryServices.DirectoryEntry <span style="color: #800000;">&quot;LDAP://$distinguishedName&quot;</span><br />
<span style="color: #800080;">$objUser</span>.displayName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Wuchner, Brian&quot;</span><br />
<span style="color: #800080;">$objUser</span>.SetInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>
<p>That is a rather straight forward process.  However, it becomes slightly more complex if we want to clear the attribute and make it null.  One would think you could simply think you could set the displayName equal to $null using something like this:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$objUser</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> DirectoryServices.DirectoryEntry <span style="color: #800000;">&quot;LDAP://$distinguishedName&quot;</span><br />
<span style="color: #800080;">$objUser</span>.displayName<span style="color: pink;">=</span>$null</div></td></tr></tbody></table></div>
<p>However, if you try that you will most likely get a chance to see the following error message:</p>
<pre>Exception setting "displayName": "Value cannot be null.</pre>
<p>As a follow up, you might think &#8220;I&#8217;ll just set the attribute to an empty string&#8221; like this:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$objUser</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> DirectoryServices.DirectoryEntry <span style="color: #800000;">&quot;LDAP://$distinguishedName&quot;</span><br />
<span style="color: #800080;">$objUser</span>.displayName<span style="color: pink;">=</span><span style="color: #800000;">&quot;&quot;</span><br />
<span style="color: #800080;">$objUser</span>.SetInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>
<p>The only problem with that&#8230;setinfo will fail with the following error.</p>
<pre>setinfo : Exception calling "setinfo" with "0" argument(s): "The attribute syntax specified to the directory service is invalid.</pre>
<p>Does that mean its time to give up?  Are we just going to have to live with bad data in AD?  Never!</p>
<p>There are at least two ways to clean this up.  The first way is my favorite (I&#8217;ve been using it since vbscript).  You simply need to refer to the Microsoft article <a href="http://support.microsoft.com/kb/260251">HOW TO: Use ADSI to Set LDAP Directory Attributes</a> and you&#8217;ll realize this can be accomplished with PutEx.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$objUser</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> DirectoryServices.DirectoryEntry <span style="color: #800000;">&quot;LDAP://$distinguishedName&quot;</span><br />
<span style="color: #800080;">$objUser</span>.PutEx<span style="color: #000000;">&#40;</span><span style="color: #804000;">1</span><span style="color: pink;">,</span> <span style="color: #800000;">'displayName'</span><span style="color: pink;">,</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$objUser</span>.SetInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></div></td></tr></tbody></table></div>
<p>In the above example, we use the constant ADS_PROPERTY_CLEAR by placing a &#8217;1&#8242; as the first argument in our method, then specifying the displayName as the attribute we want to clear, and finishing up by providing the desired value.  Since we want the value to be clear, and we&#8217;ve already specified the &#8217;1&#8242; to clear, we just need to specify something so the method has enough parameters.  I use 0 just for fun.</p>
<p>Another option is to call the Remove method and specify the value we want to remove.  The downside is the attribute MUST have a value or you get an error when trying to clear it.  We can overcome that with a simple if statement like this:</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$objUser</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> DirectoryServices.DirectoryEntry <span style="color: #800000;">&quot;LDAP://$distinguishedName&quot;</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$objUser</span>.displayName<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; <span style="color: #800080;">$objUser</span>.displayName.Remove<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;$($objUser.displayName)&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #800080;">$objUser</span>.SetInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>It doesn&#8217;t matter which of the options I use, the end result is the same &#8212; a clear attribute.  I hope this post helps if you ever need to clear out an attribute.</p>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/using-adsi-to-clear-an-attribute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Remove vCenter Scheduled Tasks with PowerCLI (Part 3)</title>
		<link>http://enterpriseadmins.org/blog/scripting/remove-vcenter-scheduled-tasks-with-powercli-part-3/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/remove-vcenter-scheduled-tasks-with-powercli-part-3/#comments</comments>
		<pubDate>Wed, 06 Mar 2013 14:00:33 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1222</guid>
		<description><![CDATA[In my most recent series on vCenter Scheduled Tasks with PowerCLI, I have provided three functions&#8230;Get-VIScheduledTasks, Get-VMScheduledSnapshots, and New-VMScheduledSnapshot. To complete the series, I have a final function Remove-VIScheduledTask. I]]></description>
				<content:encoded><![CDATA[<p>In my most recent series on vCenter Scheduled Tasks with PowerCLI, I have provided three functions&#8230;<strong>Get-VIScheduledTasks</strong>, <strong>Get-VMScheduledSnapshots</strong>, and <strong>New-VMScheduledSnapshot</strong>.  To complete the series, I have a final function <strong>Remove-VIScheduledTask</strong>.  I don&#8217;t really see the need for this one, as you can easily bulk select scheduled tasks in the vCenter UI and delete them with a single click.  However, in the interest of completeness, here is a rough function that will delete a vSphere scheduled task.  [A more robust/efficient/complete function could be written that would accept input from the pipeline. If there is a good use case for this please leave a comment below.]</p>
<p>NOTE: This function requires an additional function: <strong>Get-VIScheduledTasks</strong> to find the task by name.  In addition the usage example below requires <strong>Get-VMScheduledSnapshots</strong>.  Both functions are available here: <a href="http://enterpriseadmins.org/blog/scripting/get-vcenter-scheduled-tasks-with-powercli-part-1">New vCenter Scheduled Tasks with PowerCLI (Part 1)</a>.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> Remove<span style="color: pink;">-</span>VIScheduledTask <span style="color: #000000;">&#123;</span><br />
<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;">$taskName</span><span style="color: #000000;">&#41;</span><br />
&nbsp; <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View <span style="color: #008080; font-style: italic;">-Id</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VIScheduledTasks <span style="color: #008080; font-style: italic;">-Full</span> <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$taskName</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.ScheduledTask<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.RemoveScheduledTask<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Usage example:</p>
<pre>
# This example will find all VM Scheduled Snapshots which 
# are not scheduled to run again, then remove each one by name.
Get-VMScheduledSnapshots | 
?{$_.NextRunTime -eq $null} | %{ Remove-VIScheduledTask $_.Name }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/remove-vcenter-scheduled-tasks-with-powercli-part-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New vCenter Scheduled Tasks with PowerCLI (Part 2)</title>
		<link>http://enterpriseadmins.org/blog/scripting/new-vcenter-scheduled-tasks-with-powercli-part-2/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/new-vcenter-scheduled-tasks-with-powercli-part-2/#comments</comments>
		<pubDate>Tue, 05 Mar 2013 14:00:02 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1218</guid>
		<description><![CDATA[In a recent post New vCenter Scheduled Tasks with PowerCLI (Part 1), I provided two functions that return information related to vCenter Scheduled Tasks. This was my first step towards]]></description>
				<content:encoded><![CDATA[<p>In a recent post <a href="http://enterpriseadmins.org/blog/scripting/get-vcenter-scheduled-tasks-with-powercli-part-1">New vCenter Scheduled Tasks with PowerCLI (Part 1)</a>, I provided two functions that return information related to vCenter Scheduled Tasks.  This was my first step towards creating a PowerShell function that I could run to create scheduled snapshot tasks.  This post will cover the create scheduled snapshot function.</p>
<p>NOTE: This function requires two additional functions, <strong>Get-VMScheduledSnapshots</strong> and <strong>Get-VIScheduledTasks</strong>, available here: <a href="http://enterpriseadmins.org/blog/scripting/get-vcenter-scheduled-tasks-with-powercli-part-1">New vCenter Scheduled Tasks with PowerCLI (Part 1)</a>.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> New<span style="color: pink;">-</span>VMScheduledSnapshot <span style="color: #000000;">&#123;</span><br />
<span style="color: #0000FF;">PARAM</span> <span style="color: #000000;">&#40;</span><br />
&nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$vmName</span><span style="color: pink;">,</span><br />
&nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$runTime</span><span style="color: pink;">,</span><br />
&nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$notifyEmail</span><span style="color: pink;">=</span><span style="color: #800080;">$null</span><span style="color: pink;">,</span><br />
&nbsp; <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;$vmName Scheduled Snapshot&quot;</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;"># Verify we found a single VM</span><br />
<span style="color: #800080;">$vm</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span>get<span style="color: pink;">-</span>view <span style="color: pink;">-</span>viewtype virtualmachine <span style="color: #008080; font-style: italic;">-property</span> Name <span style="color: pink;">-</span><span style="color: #0000FF;">Filter</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><span style="color: #800000;">&quot;Name&quot;</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;^$($vmName)$&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span>.MoRef<br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span> <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: #FF0000;">-ne</span> <span style="color: #804000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800000;">&quot;Unable to locate a specific VM $vmName&quot;</span>; <span style="color: #0000FF;">break</span> <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008000;"># Validate datetime value and convert to UTC</span><br />
try <span style="color: #000000;">&#123;</span> <span style="color: #800080;">$castRunTime</span> <span style="color: pink;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$runTime</span><span style="color: #000000;">&#41;</span>.ToUniversalTime<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#125;</span> catch <span style="color: #000000;">&#123;</span> <span style="color: #800000;">&quot;Unable to convert runtime parameter to date time value&quot;</span>; <span style="color: #0000FF;">break</span> <span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$runTime</span> <span style="color: #FF0000;">-lt</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800000;">&quot;Single run tasks can not be scheduled to run in the past. &nbsp;Please adjust start time and try again.&quot;</span>; <span style="color: #0000FF;">break</span> <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008000;"># Verify the scheduled task name is not already in use</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>VIScheduledTasks <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$taskName</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: #000000;">&#41;</span>.Count <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">1</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #800000;">&quot;Task Name <span style="color: #008080; font-weight: bold;">`&quot;</span>$taskName<span style="color: #008080; font-weight: bold;">`&quot;</span> already exists. &nbsp;Please try again and specify the taskname parameter&quot;</span>; <span style="color: #0000FF;">break</span> <span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #800080;">$spec</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.ScheduledTaskSpec<br />
<span style="color: #800080;">$spec</span>.name <span style="color: pink;">=</span> <span style="color: #800080;">$taskName</span><br />
<span style="color: #800080;">$spec</span>.description <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Snapshot of $vmName scheduled for $runTime&quot;</span><br />
<span style="color: #800080;">$spec</span>.enabled <span style="color: pink;">=</span> <span style="color: #800080;">$true</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span> <span style="color: #800080;">$notifyEmail</span> <span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$spec</span>.notification <span style="color: pink;">=</span> <span style="color: #800080;">$notifyEmail</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$spec</span>.scheduler <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.OnceTaskScheduler<span style="color: #000000;">&#41;</span>.runAt <span style="color: pink;">=</span> <span style="color: #800080;">$castRunTime</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$spec</span>.action <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.MethodAction<span style="color: #000000;">&#41;</span>.Name <span style="color: pink;">=</span> <span style="color: #800000;">&quot;CreateSnapshot_Task&quot;</span><br />
<span style="color: #800080;">$spec</span>.action.argument <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.MethodActionArgument<span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#40;</span><span style="color: #804000;">4</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$spec</span>.action.argument<span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.MethodActionArgument<span style="color: #000000;">&#41;</span>.Value <span style="color: pink;">=</span> <span style="color: #800000;">&quot;$vmName scheduled snapshot&quot;</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$spec</span>.action.argument<span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.MethodActionArgument<span style="color: #000000;">&#41;</span>.Value <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Snapshot created using $taskName&quot;</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$spec</span>.action.argument<span style="color: #000000;">&#91;</span><span style="color: #804000;">2</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.MethodActionArgument<span style="color: #000000;">&#41;</span>.Value <span style="color: pink;">=</span> <span style="color: #800080;">$false</span> <span style="color: #008000;"># Snapshot memory</span><br />
<span style="color: #000000;">&#40;</span><span style="color: #800080;">$spec</span>.action.argument<span style="color: #000000;">&#91;</span><span style="color: #804000;">3</span><span style="color: #000000;">&#93;</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> VMware.Vim.MethodActionArgument<span style="color: #000000;">&#41;</span>.Value <span style="color: pink;">=</span> <span style="color: #800080;">$false</span> <span style="color: #008000;"># quiesce guest file system (requires VMware Tools)</span><br />
<br />
<span style="color: #000000;">&#91;</span>Void<span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View <span style="color: #008080; font-style: italic;">-Id</span> <span style="color: #800000;">'ScheduledTaskManager-ScheduledTaskManager'</span><span style="color: #000000;">&#41;</span>.CreateScheduledTask<span style="color: #000000;">&#40;</span><span style="color: #800080;">$vm</span><span style="color: pink;">,</span> <span style="color: #800080;">$spec</span><span style="color: #000000;">&#41;</span><br />
Get<span style="color: pink;">-</span>VMScheduledSnapshots <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$taskName</span> <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<pre>
# Create a snapshot of the VM test002 at 9:40AM on 3/2/13
New-VMScheduledSnapshot test002 "3/2/13 9:40AM"

# Create a snapshot and send an email notification
New-VMScheduledSnapshot test002 "3/2/13 9:40AM" myemail@mydomain.com

# Use all of the options and name the parameters
New-VMScheduledSnapshot -vmname 'test001' -runtime '3/2/13 9:40am' -notifyemail 'myemail@mydomain.com' -taskname 'My scheduled task of test001'
</pre>
<p>I hope someone finds this function useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/new-vcenter-scheduled-tasks-with-powercli-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get vCenter Scheduled Tasks with PowerCLI (Part 1)</title>
		<link>http://enterpriseadmins.org/blog/scripting/get-vcenter-scheduled-tasks-with-powercli-part-1/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/get-vcenter-scheduled-tasks-with-powercli-part-1/#comments</comments>
		<pubDate>Mon, 04 Mar 2013 14:00:02 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Virtualization]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1211</guid>
		<description><![CDATA[I work with a lot of scheduled tasks. Typically, these tasks run powershell scripts from the Windows Task Scheduler. However, when working with simple VMware tasks (like creating snapshots right]]></description>
				<content:encoded><![CDATA[<p>I work with a lot of scheduled tasks.  Typically, these tasks run powershell scripts from the Windows Task Scheduler.  However, when working with simple VMware tasks (like creating snapshots right before a maintenance window) I like to use the Scheduled Tasks feature from right inside vCenter.  The other day I thought it would be interesting if I had a PowerShell function that I could run to create these snapshot tasks.  The first step in this process is to figure out what tasks we already have&#8230;and understand where some of these properties are located using PowerCLI.</p>
<p>The following two functions can be used to get information on Scheduled Tasks inside vCenter.  The first function <strong>Get-VIScheduledTasks</strong> will simply return a list of all scheduled tasks that exist in a vCenter environment.  I picked out a handful of properties that I figured would be needed and return those by default, casting the date/time values into local time.  If you need all of the properties (the native .Net view of the Scheduled Task Info objects) you can include the parameter <strong>-Full</strong> and all of the properties will be returned.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>VIScheduledTasks <span style="color: #000000;">&#123;</span><br />
<span style="color: #0000FF;">PARAM</span> <span style="color: #000000;">&#40;</span> <span style="color: #000000;">&#91;</span><span style="color: #0000FF;">switch</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Full</span> <span style="color: #000000;">&#41;</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Full</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #008000;"># Note: When returning the full View of each Scheduled Task, all date times are in UTC</span><br />
&nbsp; <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View ScheduledTaskManager<span style="color: #000000;">&#41;</span>.ScheduledTask <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View <a href="about:blank"><span style="color: #000080;">$_</span></a><span style="color: #000000;">&#41;</span>.Info <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #008000;"># By default, lets only return common headers and convert all date/times to local values</span><br />
&nbsp; <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View ScheduledTaskManager<span style="color: #000000;">&#41;</span>.ScheduledTask <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: #008080; font-style: italic;">-Property</span> Info<span style="color: #000000;">&#41;</span>.Info <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span><br />
&nbsp; <span style="color: #008080; font-weight: bold;">Select-Object</span> Name<span style="color: pink;">,</span> Description<span style="color: pink;">,</span> Enabled<span style="color: pink;">,</span> Notification<span style="color: pink;">,</span> LastModifiedUser<span style="color: pink;">,</span> State<span style="color: pink;">,</span> Entity<span style="color: pink;">,</span><br />
&nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>N<span style="color: pink;">=</span><span style="color: #800000;">&quot;EntityName&quot;</span>;E<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>View <a href="about:blank"><span style="color: #000080;">$_</span></a>.Entity <span style="color: #008080; font-style: italic;">-Property</span> Name<span style="color: #000000;">&#41;</span>.Name <span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>N<span style="color: pink;">=</span><span style="color: #800000;">&quot;LastModifiedTime&quot;</span>;E<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.LastModifiedTime.ToLocalTime<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>N<span style="color: pink;">=</span><span style="color: #800000;">&quot;NextRunTime&quot;</span>;E<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.NextRunTime.ToLocalTime<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>N<span style="color: pink;">=</span><span style="color: #800000;">&quot;PrevRunTime&quot;</span>;E<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.LastModifiedTime.ToLocalTime<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> <br />
&nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>N<span style="color: pink;">=</span><span style="color: #800000;">&quot;ActionName&quot;</span>;E<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.Action.Name<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>This next function calls above function, but only returns the tasks whose action is &#8220;CreateSnapshot_Task&#8221;</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>VMScheduledSnapshots <span style="color: #000000;">&#123;</span><br />
&nbsp; Get<span style="color: pink;">-</span>VIScheduledTasks <span style="color: pink;">|</span> <span style="color: pink;">?</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.ActionName <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">'CreateSnapshot_Task'</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>N<span style="color: pink;">=</span><span style="color: #800000;">&quot;VMName&quot;</span>;E<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.EntityName<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span> Name<span style="color: pink;">,</span> NextRunTime<span style="color: pink;">,</span> Notification<br />
<span style="color: #000000;">&#125;</span></div></td></tr></tbody></table></div>
<p>Sample usage would be:</p>
<pre>
# To find all tasks that failed to execute last run
Get-VIScheduledTasks | ?{$_.State -ne 'success'}

# To find all snapshots that are not scheduled to run again:
Get-VMScheduledSnapshots | ?{$_.NextRunTime -eq $null}
</pre>
<p>I hope you find these functions useful.  Be sure to check out the next post &#8211; on creating scheduled snapshots with PowerCLI!</p>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/get-vcenter-scheduled-tasks-with-powercli-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Compare two CSV files to trend mailbox growth</title>
		<link>http://enterpriseadmins.org/blog/scripting/compare-two-csv-files-to-trend-mailbox-growth/</link>
		<comments>http://enterpriseadmins.org/blog/scripting/compare-two-csv-files-to-trend-mailbox-growth/#comments</comments>
		<pubDate>Mon, 25 Feb 2013 14:00:03 +0000</pubDate>
		<dc:creator>brian.wuchner</dc:creator>
				<category><![CDATA[Messaging]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://enterpriseadmins.org/blog/?p=1205</guid>
		<description><![CDATA[I had an interesting request the other day. A co-worker had two CSV files containing mailbox information from the same Exchange server, but from different parts of the day. He]]></description>
				<content:encoded><![CDATA[<p>I had an interesting request the other day.  A co-worker had two CSV files containing mailbox information from the same Exchange server, but from different parts of the day.  He wanted to know if there was any way to find which users had the most growth in their mailbox size.</p>
<p>Here is an example of how to get mailbox size for all users on the same Exchange server:</p>
<pre>
Get-MailboxStatistics -Server EXCHANGE01 | 
Select-Object -Property DisplayName, 
@{N="SizeMB";E={$_.TotalItemSize.Value.ToMB()}}, Identity | 
Export-Csv file2.csv -NoTypeInformation
</pre>
<p>The first thought that came to mind had involved Group-Object and Measure-Object.  I threw something together that got the job done, but decided to clean it up a bit and thought I&#8217;d share it here.</p>
<div class="codecolorer-container powershell twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008080; font-weight: bold;">Import-Csv</span> file1.csv<span style="color: pink;">,</span> file2.csv <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Group-Object</span> <span style="color: #008080; font-style: italic;">-Property</span> Identity <span style="color: pink;">|</span> <span style="color: pink;">%</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #800080;">$thisDetail</span> <span style="color: pink;">=</span> <a href="about:blank"><span style="color: #000080;">$_</span></a> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-ExpandProperty</span> <span style="color: #008080; font-weight: bold;">Group</span><span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span> SizeMB <span style="color: #008080; font-style: italic;">-Maximum</span> <span style="color: #008080; font-style: italic;">-Minimum</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Object</span> psobject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DisplayName <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: #000000;">&#40;</span><a href="about:blank"><span style="color: #000080;">$_</span></a>.<span style="color: #008080; font-weight: bold;">Group</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.DisplayName<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; GrowthMB <span style="color: pink;">=</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">float</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$thisDetail</span>.Maximum <span style="color: pink;">-</span> <span style="color: #800080;">$thisDetail</span>.Minimum<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> DisplayName<span style="color: pink;">,</span> GrowthMB<br />
<span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort-Object</span> GrowthMB <span style="color: #008080; font-style: italic;">-Descending</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-Object</span> <span style="color: #008080; font-style: italic;">-First</span> <span style="color: #804000;">10</span></div></td></tr></tbody></table></div>
<p>Hope someone else finds this helpful!</p>
]]></content:encoded>
			<wfw:commentRss>http://enterpriseadmins.org/blog/scripting/compare-two-csv-files-to-trend-mailbox-growth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
