<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>The Lonely Administrator</title>
	
	<link>http://jdhitsolutions.com/blog</link>
	<description>Advice, solutions, tips and more for the lonely Windows administrator with too much to do and not enough time.</description>
	<lastBuildDate>Fri, 03 Feb 2012 14:45:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JeffsScriptingBlogAndMore" /><feedburner:info uri="jeffsscriptingblogandmore" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Training Down Under</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/xYfwPZFcwoE/</link>
		<comments>http://jdhitsolutions.com/blog/2012/02/training-down-under/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 14:45:14 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Training]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2067</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
I will be doing a private #PowerShell training class in Canberra, Australia in March. Since it is a long trek I&#8217;d love to add a second week of work, either training or speaking. I had a second training gig lined &#8230; <a href="http://jdhitsolutions.com/blog/2012/02/training-down-under/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>I will be doing a private #PowerShell training class in Canberra, Australia in March. Since it is a long trek I&#8217;d love to add a second week of work, either training or speaking. I had a second training gig lined up but it fell through. I realize it might be short notice but I&#8217;d love to find someone who would like 3-5 days of training the week of March 26, 2012. I&#8217;m also open to speaking engagements if I can at least get my expenses covered. I&#8217;m willing to travel anywhere in the region: Australia, New Zealand, Indonesia or even Singapore.</p>
<p>If you are interested <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=bWFpbHRvOmpoaWNrc0BqZGhpdHNvbHV0aW9ucy5jb20/U3ViamVjdD1BdXN0cmFsaWEgVHJhaW5pbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk">contact me</a>. I need to make final travel plans in the next few weeks so please don&#8217;t wait. This is more or less first come, first served, but I will try to accommodate people as much as I can.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVRyYWluaW5nK0Rvd24rVW5kZXIraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDIlMkZ0cmFpbmluZy1kb3duLXVuZGVyJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3RyYWluaW5nLWRvd24tdW5kZXIvJmFtcDtoZWFkbGluZT1UcmFpbmluZytEb3duK1VuZGVy" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvdHJhaW5pbmctZG93bi11bmRlci8mYW1wO3RpdGxlPVRyYWluaW5nK0Rvd24rVW5kZXI=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvdHJhaW5pbmctZG93bi11bmRlci8mYW1wO3RpdGxlPVRyYWluaW5nK0Rvd24rVW5kZXI=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvdHJhaW5pbmctZG93bi11bmRlci8mYW1wO3Q9VHJhaW5pbmcrRG93bitVbmRlcg==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1UcmFpbmluZytEb3duK1VuZGVyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3RyYWluaW5nLWRvd24tdW5kZXIv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvdHJhaW5pbmctZG93bi11bmRlci8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1UcmFpbmluZytEb3duK1VuZGVyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3RyYWluaW5nLWRvd24tdW5kZXIv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi90cmFpbmluZy1kb3duLXVuZGVyLyZhbXA7dGl0bGU9VHJhaW5pbmcrRG93bitVbmRlcg==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvdHJhaW5pbmctZG93bi11bmRlci8mYW1wO3RpdGxlPVRyYWluaW5nK0Rvd24rVW5kZXI=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3RyYWluaW5nLWRvd24tdW5kZXIvJmFtcDt0aXRsZT1UcmFpbmluZytEb3duK1VuZGVy" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi90cmFpbmluZy1kb3duLXVuZGVyLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2067" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/KkuKlQAvppRyWqySU_2u2kZnCW4/0/da"><img src="http://feedads.g.doubleclick.net/~a/KkuKlQAvppRyWqySU_2u2kZnCW4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/KkuKlQAvppRyWqySU_2u2kZnCW4/1/da"><img src="http://feedads.g.doubleclick.net/~a/KkuKlQAvppRyWqySU_2u2kZnCW4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/xYfwPZFcwoE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/02/training-down-under/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/02/training-down-under/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=training-down-under</feedburner:origLink></item>
		<item>
		<title>Export and Import Hash Tables</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/Aaq5aREErbI/</link>
		<comments>http://jdhitsolutions.com/blog/2012/02/export-and-import-hash-tables/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 15:25:41 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[CSV]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[hashtable]]></category>
		<category><![CDATA[import]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2062</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
I use hash tables quite a bit and with the impending arrival of PowerShell 3.0 I expect even more so. PowerShell v3 allows you to define a hash table of default parameter values. I&#8217;m not going to to cover that &#8230; <a href="http://jdhitsolutions.com/blog/2012/02/export-and-import-hash-tables/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>I use hash tables quite a bit and with the impending arrival of PowerShell 3.0 I expect even more so. PowerShell v3 allows you to define a hash table of default parameter values. I&#8217;m not going to to cover that feature specifically, but it made me realize I needed a better way to export a hash table, say to a CSV file. So I put together a few functions to do just that.</p>
<p>To walk you through them, here&#8217;s a simple hash table.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$hash</span><span style="color: pink;">=@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;jeff&quot;</span>;pi<span style="color: pink;">=</span><span style="color: #804000;">3.14</span>;date<span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Date</span>;size<span style="color: pink;">=</span><span style="color: #804000;">3</span> <span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$hash</span><br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value<br />
<span style="color: pink;">----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">-----</span><br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jeff<br />
pi &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">3.14</span><br />
date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">2</span><span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: pink;">/</span><span style="color: #804000;">2012</span> <span style="color: #804000;">10</span>:04:<span style="color: #804000;">54</span> AM<br />
size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">3</span></div></div>
<p>I want to export this to a CSV file, but because PowerShell is all about the objects, I want to be sure to get the type information as well. Otherwise when I go to importing, everything will be a string.  Here&#8217;s what I can expect to export:</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$hash</span>.GetEnumerator<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> &nbsp;<span style="color: #008080; font-weight: bold;">Select</span> Key<span style="color: pink;">,</span>Value<span style="color: pink;">,@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Type&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.value.gettype<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.name<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><br />
<br />
Key &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Value &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-weight: bold;">Type</span><br />
<span style="color: pink;">---</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: pink;">-----</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: pink;">----</span><br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jeff &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String<br />
pi &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">3.14</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Double<br />
date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">2</span><span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: pink;">/</span><span style="color: #804000;">2012</span> <span style="color: #804000;">10</span>:05:<span style="color: #804000;">57</span> AM &nbsp; &nbsp; &nbsp; DateTime<br />
size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #804000;">3</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Int32</div></div>
<p>That looks good. I can take this command and run it through Export-CSV which gives me this file:</p>
<div class="codecolorer-container dos geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#TYPE Selected.System.Collections.DictionaryEntry<br />
&quot;Key&quot;,&quot;Value&quot;,&quot;Type&quot;<br />
&quot;Name&quot;,&quot;jeff&quot;,&quot;String&quot;<br />
&quot;pi&quot;,&quot;3.14&quot;,&quot;Double&quot;<br />
&quot;date&quot;,&quot;2/2/2012 10:05:57 AM&quot;,&quot;DateTime&quot;<br />
&quot;size&quot;,&quot;3&quot;,&quot;Int32&quot;</div></div>
<p>Perfect. Later, I will need to import this file and recreate my hash table.  I can use Import-CSV as a starting point.</p>
<div class="codecolorer-container dos geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\<span style="color: #33cc33;">&gt;</span> import-csv hash.csv<br />
<br />
Key &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Value &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Type<br />
--- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;----- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;----<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jeff &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String<br />
pi &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3.14 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Double<br />
date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2/2/2012 10:05:57 AM &nbsp; &nbsp; &nbsp; DateTime<br />
size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Int32</div></div>
<p>Good so far. All I need to do is create a hash table and add each entry to it. I could do something like this:</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><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> hash.csv <span style="color: pink;">|</span> <span style="color: #0000FF;">foreach</span> <span style="color: #008080; font-style: italic;">-begin</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$hash</span><span style="color: pink;">=@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">-process</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$hash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Key<span style="color: pink;">,</span><span style="color: #000080;">$_</span>.Value<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">-end</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$hash</span><span style="color: #000000;">&#125;</span></div></div>
<p>But if I do this, everything will be a string. Since I have Type information, let&#8217;s use it.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$path</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ForEach-Object</span> <span style="color: #008080; font-style: italic;">-begin</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #008000;">#define an empty hash table</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #800080;">$hash</span><span style="color: pink;">=@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">-process</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">&lt;#<br />
&nbsp; &nbsp; &nbsp; &nbsp;if there is a type column, then add the entry as that type<br />
&nbsp; &nbsp; &nbsp; &nbsp;otherwise we'll treat it as a string<br />
&nbsp; &nbsp; &nbsp; &nbsp;#&gt;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.<span style="color: #008080; font-weight: bold;">Type</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$type</span><span style="color: pink;">=</span><span style="color: #000000;">&#91;</span><span style="color: #008080; font-weight: bold;">type</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;$($_.type)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$type</span><span style="color: pink;">=</span><span style="color: #000000;">&#91;</span><span style="color: #008080; font-weight: bold;">type</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;string&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Adding $($_.key)&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Setting type to $type&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$hash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Key<span style="color: pink;">,</span><span style="color: #000000;">&#40;</span>$<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Value<span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-as</span> <span style="color: #800080;">$type</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008080; font-style: italic;">-end</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">#write hash to the pipeline</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Output</span> <span style="color: #800080;">$hash</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></div>
<p>Here I&#8217;m taking the Type value from the import and turning it into a System.Type object which I can then use to cast each value to the correct type. I&#8217;m checking for the Type property because I might have a CSV file without it. But as long as I have column headings for Key and Value this will work.</p>
<p>I turned all of this into a pair of advanced functions, Export-HashtoCSV and Import-CSVtoHash.</p>
<div class="codecolorer-container dos geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="dos codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\<span style="color: #33cc33;">&gt;</span> $hash <span style="color: #33cc33;">|</span> Export-HashtoCSV myhash.csv<br />
PS C:\<span style="color: #33cc33;">&gt;</span> $newhash=Import-CSVtoHash .\myhash.csv -verbose<br />
VERBOSE: Importing data from .\myhash.csv<br />
VERBOSE: Adding Name<br />
VERBOSE: Setting type to string<br />
VERBOSE: Adding pi<br />
VERBOSE: Setting type to double<br />
VERBOSE: Adding date<br />
VERBOSE: Setting type to System.DateTime<br />
VERBOSE: Adding size<br />
VERBOSE: Setting type to int<br />
VERBOSE: Import complete<br />
PS C:\<span style="color: #33cc33;">&gt;</span> $newhash<br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value<br />
---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -----<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; jeff<br />
pi &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3.14<br />
date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2/2/2012 10:05:57 AM<br />
size &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 3<br />
PS C:\<span style="color: #33cc33;">&gt;</span> $newhash.date<br />
<br />
Thursday, February 02, 2012 10:05:57 AM<br />
PS C:\<span style="color: #33cc33;">&gt;</span> $newhash.pi.gettype<span style="color: #33cc33;">()</span>.name<br />
Double</div></div>
<p>This certainly fulfills my needs. You can <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAyL0hhc2hDU1ZGdW5jdGlvbnMudHh0" target='_blank'>download a script file</a> with both functions, including help. As always, enjoy and I hope you&#8217;ll let me know how these work out for you.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUV4cG9ydCthbmQrSW1wb3J0K0hhc2grVGFibGVzK2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjAyJTJGZXhwb3J0LWFuZC1pbXBvcnQtaGFzaC10YWJsZXMlMkY=" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL2V4cG9ydC1hbmQtaW1wb3J0LWhhc2gtdGFibGVzLyZhbXA7aGVhZGxpbmU9RXhwb3J0K2FuZCtJbXBvcnQrSGFzaCtUYWJsZXM=" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvZXhwb3J0LWFuZC1pbXBvcnQtaGFzaC10YWJsZXMvJmFtcDt0aXRsZT1FeHBvcnQrYW5kK0ltcG9ydCtIYXNoK1RhYmxlcw==" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvZXhwb3J0LWFuZC1pbXBvcnQtaGFzaC10YWJsZXMvJmFtcDt0aXRsZT1FeHBvcnQrYW5kK0ltcG9ydCtIYXNoK1RhYmxlcw==" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvZXhwb3J0LWFuZC1pbXBvcnQtaGFzaC10YWJsZXMvJmFtcDt0PUV4cG9ydCthbmQrSW1wb3J0K0hhc2grVGFibGVz" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1FeHBvcnQrYW5kK0ltcG9ydCtIYXNoK1RhYmxlcyZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi9leHBvcnQtYW5kLWltcG9ydC1oYXNoLXRhYmxlcy8=" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvZXhwb3J0LWFuZC1pbXBvcnQtaGFzaC10YWJsZXMvJmFtcDtpbWFnZXVybD0=" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1FeHBvcnQrYW5kK0ltcG9ydCtIYXNoK1RhYmxlcyZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi9leHBvcnQtYW5kLWltcG9ydC1oYXNoLXRhYmxlcy8=" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi9leHBvcnQtYW5kLWltcG9ydC1oYXNoLXRhYmxlcy8mYW1wO3RpdGxlPUV4cG9ydCthbmQrSW1wb3J0K0hhc2grVGFibGVz" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvZXhwb3J0LWFuZC1pbXBvcnQtaGFzaC10YWJsZXMvJmFtcDt0aXRsZT1FeHBvcnQrYW5kK0ltcG9ydCtIYXNoK1RhYmxlcw==" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL2V4cG9ydC1hbmQtaW1wb3J0LWhhc2gtdGFibGVzLyZhbXA7dGl0bGU9RXhwb3J0K2FuZCtJbXBvcnQrSGFzaCtUYWJsZXM=" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi9leHBvcnQtYW5kLWltcG9ydC1oYXNoLXRhYmxlcy8=" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2062" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/6qd44iHed5ogpWZGAKxcBAf1kZ0/0/da"><img src="http://feedads.g.doubleclick.net/~a/6qd44iHed5ogpWZGAKxcBAf1kZ0/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/6qd44iHed5ogpWZGAKxcBAf1kZ0/1/da"><img src="http://feedads.g.doubleclick.net/~a/6qd44iHed5ogpWZGAKxcBAf1kZ0/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/Aaq5aREErbI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/02/export-and-import-hash-tables/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/02/export-and-import-hash-tables/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=export-and-import-hash-tables</feedburner:origLink></item>
		<item>
		<title>PowerShell 3.0 Easy Rider</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/fKtCpdYXbcE/</link>
		<comments>http://jdhitsolutions.com/blog/2012/02/powershell-3-0-easy-rider/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 20:41:28 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Powershell 3.0]]></category>
		<category><![CDATA[Professional]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Help]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[User group]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2051</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
Today I gave an Live Meeting presentation for the PowerShell Virtual User Group. When the recording is posted I&#8217;ll update this post. I spoke about new features in Windows PowerShell 3.0 that I think will make it easier for people &#8230; <a href="http://jdhitsolutions.com/blog/2012/02/powershell-3-0-easy-rider/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDExLzEwL3RhbGtidWJibGUucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img class="alignleft size-full wp-image-1688" title="talkbubble" src="http://jdhitsolutions.com/blog/wp-content/uploads/2011/10/talkbubble.png" alt="" width="198" height="208" /></a>Today I gave an Live Meeting presentation for the PowerShell Virtual User Group. When the recording is posted I&#8217;ll update this post. I spoke about new features in Windows PowerShell 3.0 that I think will make it easier for people to use PowerShell more efficiently. I think they even might find it fun. Here is what I covered.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>AGENDA<br />
 New Help Options<br />
 Default Parameter Values<br />
 Simplified Syntax<br />
 Improved Tab Completion<br />
 Redirection Options<br />
 Improved ISE Experience</p>
<p>The presentation started with some introductory slides, but most of the presentation was demo. As promised here is my <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAyL1Bvd2VyU2hlbGwtRWFzeS1SaWRlci5wZGYjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk" target=\"_blank\">presentation</a> and a <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAyL1Bvd2VyU2hlbGxFYXN5UmlkZXItRGVtb3MuemlwI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA==">zip files</a> with my demos and sample script.</p>
<p>Here is the <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly93d3czMTEubGl2ZW1lZXRpbmcuY29tL2NjL212cC92aWV3P2lkPUplZmZIaWNrc0ZlYjIwMTI=" target=\"_blank\">link to the recording</a></p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVBvd2VyU2hlbGwrMy4wK0Vhc3krUmlkZXIraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDIlMkZwb3dlcnNoZWxsLTMtMC1lYXN5LXJpZGVyJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3Bvd2Vyc2hlbGwtMy0wLWVhc3ktcmlkZXIvJmFtcDtoZWFkbGluZT1Qb3dlclNoZWxsKzMuMCtFYXN5K1JpZGVy" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvcG93ZXJzaGVsbC0zLTAtZWFzeS1yaWRlci8mYW1wO3RpdGxlPVBvd2VyU2hlbGwrMy4wK0Vhc3krUmlkZXI=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvcG93ZXJzaGVsbC0zLTAtZWFzeS1yaWRlci8mYW1wO3RpdGxlPVBvd2VyU2hlbGwrMy4wK0Vhc3krUmlkZXI=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvcG93ZXJzaGVsbC0zLTAtZWFzeS1yaWRlci8mYW1wO3Q9UG93ZXJTaGVsbCszLjArRWFzeStSaWRlcg==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Qb3dlclNoZWxsKzMuMCtFYXN5K1JpZGVyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3Bvd2Vyc2hlbGwtMy0wLWVhc3ktcmlkZXIv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvcG93ZXJzaGVsbC0zLTAtZWFzeS1yaWRlci8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Qb3dlclNoZWxsKzMuMCtFYXN5K1JpZGVyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3Bvd2Vyc2hlbGwtMy0wLWVhc3ktcmlkZXIv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi9wb3dlcnNoZWxsLTMtMC1lYXN5LXJpZGVyLyZhbXA7dGl0bGU9UG93ZXJTaGVsbCszLjArRWFzeStSaWRlcg==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDIvcG93ZXJzaGVsbC0zLTAtZWFzeS1yaWRlci8mYW1wO3RpdGxlPVBvd2VyU2hlbGwrMy4wK0Vhc3krUmlkZXI=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAyL3Bvd2Vyc2hlbGwtMy0wLWVhc3ktcmlkZXIvJmFtcDt0aXRsZT1Qb3dlclNoZWxsKzMuMCtFYXN5K1JpZGVy" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMi9wb3dlcnNoZWxsLTMtMC1lYXN5LXJpZGVyLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2051" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/uDgx_LwmGUk0FhhSr2MtpAn3Zgs/0/da"><img src="http://feedads.g.doubleclick.net/~a/uDgx_LwmGUk0FhhSr2MtpAn3Zgs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/uDgx_LwmGUk0FhhSr2MtpAn3Zgs/1/da"><img src="http://feedads.g.doubleclick.net/~a/uDgx_LwmGUk0FhhSr2MtpAn3Zgs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/fKtCpdYXbcE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/02/powershell-3-0-easy-rider/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/02/powershell-3-0-easy-rider/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-3-0-easy-rider</feedburner:origLink></item>
		<item>
		<title>Maximizing the PowerShell Console Title Bar</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/q8YGpeBt1PE/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 15:54:46 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[eventsubscriber]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Register-ObjectEvent]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2044</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
A few days ago Boe Prox posted some very nifty PowerShell modules for using the title bar as a ticker for RSS feeds like the weather. I thought this was an awesome idea and an easy way to take advantage &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>A few days ago <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL3Byb3hi" title=\"Follow on Twitter\" target=\"_blank\">Boe Prox</a> posted some very nifty PowerShell modules for using the <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2xlYXJuLXBvd2Vyc2hlbGwubmV0LzIwMTIvMDEvMjgvdHVybi15b3VyLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXItaW50by1hLXJzc3dlYXRoZXItdGlja2VyLw==" title=\"Read his blog\" target=\"_blank\">title bar as a ticker</a> for RSS feeds like the weather. I thought this was an awesome idea and an easy way to take advantage of what would otherwise be unused screen space. I was especially intrigued with his use of timer objects and event subscriptions to manage the updating.</p>
<p>Naturally I decided to run with this. My main goal was to take Boe&#8217;s fundamental idea and turn it into something more re-usable or extensible.  My result is a module called ConsoleTitle.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-command -Module ConsoleTitle | Select Name<br />
<br />
Name<br />
----<br />
Get-Inspiration<br />
Get-SystemStat<br />
Get-Timer<br />
New-Timer<br />
Remove-Timer<br />
Set-ConsoleTitle<br />
Set-TimerInterval<br />
Start-TitleTimer</div></div>
<p>The overall premise is pretty simple, define a global variable $PSConsoleTitle and use a timer to periodically update the console title bar with this value. During the refresh interval you can run whatever code you like, however you like, to provide a new value to the variable. In the module I&#8217;ve included two sample commands, Get-SystemStat and Get-Inspiration. The former uses WMI to gather system information from the local computer.<br />
<a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2NvbnNvbGUtdGl0bGUtc3lzc3RhdC5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/console-title-sysstat-300x85.png" alt="" title="System Status Title Bar" width="300" height="85" class="aligncenter size-medium wp-image-2045" /></a></p>
<p>The other command defines an array of slogans, sayings and suggestions and randomly selects one to use as the title bar text.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2NvbnNvbGUtdGl0bGUyLnBuZyN1dG1fc291cmNlPWZlZWQmYW1wO3V0bV9tZWRpdW09ZmVlZCZhbXA7dXRtX2NhbXBhaWduPWZlZWQ="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/console-title2-300x197.png" alt="" title="Inspiring Titles" width="300" height="197" class="aligncenter size-medium wp-image-2046" /></a></p>
<p>The module includes a few commands for working with timer objects. You can use New-Timer in your own scripts.  Here&#8217;s the function.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Function New-Timer {<br />
<br />
&lt;#<br />
.Synopsis<br />
Create an event timer object<br />
.Description<br />
Create an event timer object, primarily to be used by the ConsoleTitle module.<br />
Each timer job will automatically be added to the global variable, $ConsoleTitleEvents<br />
unless you use the -NoAdd parameter. This variable is used by Remove-Timer to clear<br />
console title related timers.<br />
<br />
This function is called from within other module functions but you can use it to <br />
create non-module timers.<br />
<br />
.Parameter Identifier<br />
A source identifier for your timer<br />
.Parameter Refresh<br />
The timer interval in Seconds. The default is 300 (5 minutes). Minimum<br />
value is 5 seconds.<br />
.Parameter Action<br />
The scriptblock to execute when the timer runs down.<br />
.Parameter NoAdd<br />
Don't add the timer object to the $ConsoleTitleEvents global variable.<br />
#&gt;<br />
<br />
Param(<br />
[Parameter(Position=0,Mandatory=$True,HelpMessage=&quot;Enter a source identifier for your timer&quot;)]<br />
[ValidateNotNullorEmpty()]<br />
[string]$Identifier,<br />
[Parameter(Position=1)]<br />
[validatescript({$_ -ge 5})]<br />
[int]$Refresh=300,<br />
[Parameter(Position=2,Mandatory=$True,HelpMessage=&quot;Enter an action scriptblock&quot;)]<br />
[scriptblock]$Action,<br />
[switch]$NoAdd<br />
)<br />
<br />
Write-Verbose (&quot;Creating a timer called {0} to refresh every {1} seconds.&quot; -f $Identifier,$Refresh)<br />
<br />
#create a timer object<br />
$timer = new-object timers.timer<br />
#timer interval is in milliseconds<br />
$timer.Interval = $Refresh*1000<br />
$timer.Enabled=$True<br />
<br />
#create the event subscription and add to the global variable<br />
$evt=Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier &nbsp;$Identifier &nbsp;-Action $Action <br />
<br />
if (-Not $NoAdd) {<br />
&nbsp; &nbsp; #add the event to a global variable to track all events<br />
&nbsp; &nbsp; $global:ConsoleTitleEvents+=$evt<br />
}<br />
#start the timer &nbsp; &nbsp;<br />
$timer.Start() <br />
<br />
} #Function</div></div>
<p>And here&#8217;s how you might use it.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Function Get-Inspiration {<br />
<br />
Param(<br />
[Parameter(Position=0)]<br />
[ValidateScript({$_ -ge 5})]<br />
[int]$Refresh=600<br />
)<br />
<br />
#Define an array of pithy sayings, slogans and quotes<br />
<br />
#we'll create as a globally scoped variable so you can add to it anytime you want from PowerShell<br />
$global:slogans=@(<br />
&quot;PowerShell Rocks!&quot;,<br />
&quot;Energize!!&quot;,<br />
&quot;To Shell and Back&quot;,<br />
&quot;I am the Shell&quot;,<br />
&quot;PowerShell to the People&quot;,<br />
&quot;Powered by PS&quot;,<br />
&quot;PowerShell Rulez!&quot;,<br />
&quot;PowerShell Fanboy&quot;,<br />
&quot;I am the walrus&quot;,<br />
&quot;Those who forget to script are doomed to repeat their work.&quot;,<br />
&quot;Have you backed up files lately?&quot;,<br />
&quot;Is your resume up to date?&quot;,<br />
&quot;Is it Beer O'Clock yet?&quot;,<br />
&quot;With great power comes great responsibility&quot;,<br />
&quot;I came, I saw, I scripted.&quot;,<br />
&quot;$env:username, Open the pod bay doors.&quot;<br />
)<br />
<br />
$sb={ $global:PSConsoleTitle=$global:slogans | get-random }<br />
#invoke the scriptblock<br />
Invoke-Command $sb<br />
<br />
New-Timer -identifier &quot;SloganUpdate&quot; -action $sb -refresh $refresh<br />
<br />
#start the update timer if not already running<br />
if (-Not (Get-EventSubscriber -SourceIdentifier &quot;TitleTimer&quot; -ea &quot;SilentlyContinue&quot;)) {<br />
&nbsp; &nbsp; Start-TitleTimer -refresh $refresh<br />
}<br />
<br />
} #function</div></div>
<p>Think of the module as a framework or SDK for building your own solutions. The module also includes an about topic. I hope you&#8217;ll download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0NvbnNvbGVUaXRsZS56aXA=">ConsoleTitle</a>and let me know what you think.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXIraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDElMkZtYXhpbWl6aW5nLXRoZS1wb3dlcnNoZWxsLWNvbnNvbGUtdGl0bGUtYmFyJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIvJmFtcDtoZWFkbGluZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFy" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3RpdGxlPU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXI=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3RpdGxlPU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXI=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3Q9TWF4aW1pemluZyt0aGUrUG93ZXJTaGVsbCtDb25zb2xlK1RpdGxlK0Jhcg==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9tYXhpbWl6aW5nLXRoZS1wb3dlcnNoZWxsLWNvbnNvbGUtdGl0bGUtYmFyLyZhbXA7dGl0bGU9TWF4aW1pemluZyt0aGUrUG93ZXJTaGVsbCtDb25zb2xlK1RpdGxlK0Jhcg==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3RpdGxlPU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXI=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIvJmFtcDt0aXRsZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFy" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9tYXhpbWl6aW5nLXRoZS1wb3dlcnNoZWxsLWNvbnNvbGUtdGl0bGUtYmFyLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2044" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/0/da"><img src="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/1/da"><img src="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/q8YGpeBt1PE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=maximizing-the-powershell-console-title-bar</feedburner:origLink></item>
		<item>
		<title>Friday Fun Get Content Words</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/e4zco8By24k/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 15:30:58 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Get-Content]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[Select-Object]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2033</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
Recently I was tracking down a bug in script for a client. The problem turned out to be a simple typo. I could have easily avoided that by using Set-StrictMode, which I do now, but that&#8217;s not what this is &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>Recently I was tracking down a bug in script for a client. The problem turned out to be a simple typo. I could have easily avoided that by using Set-StrictMode, which I do now, but that&#8217;s not what this is about. What I realized I wanted was a way to look at all the for &#8220;words&#8221; in a script. If I could look at them sorted, then typos would jump out. At least in theory.</p>
<p>My plan was to get the content of a text file or script, use a regular expression pattern to identify all the &#8220;words&#8221; and then get a sorted and unique list. Here&#8217;s what I came up with.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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>ContentWords <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">Param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span><br />
HelpMessage<span style="color: pink;">=</span><span style="color: #800000;">&quot;Enter the filename for your text file&quot;</span><span style="color: pink;">,</span><br />
ValueFromPipeline<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Path</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
Begin <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Set<span style="color: pink;">-</span>StrictMode <span style="color: pink;">-</span>Version <span style="color: #804000;">2.0</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Starting $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">#define a regular expression pattern to detect &quot;words&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$word</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;\b\S+\b&quot;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$path</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;FileInfo&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">#$Path is a file object</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Getting content from $($Path.Fullname)&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #800080;">$content</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$path</span>.Fullname<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#$Path is a string</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Getting content from $path&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$content</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">get-content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$Path</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">#add a little information</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$stats</span><span style="color: pink;">=</span><span style="color: #800080;">$content</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span> <span style="color: #008080; font-style: italic;">-Word</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Found approximately $($stats.words) words&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">#write sorted unique values</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$word</span>.Matches<span style="color: #000000;">&#40;</span><span style="color: #800080;">$content</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Value <span style="color: #008080; font-style: italic;">-unique</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">sort</span> Value<br />
&nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp;<br />
End <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Ending $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#close function</span></div></div>
<p>The function uses Get-Content to retrieve the content (what else?!) of the specified file. At the beginning of the function I defined a regular expression object to find &#8220;words&#8221;.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">#define a regular expression pattern to detect &quot;words&quot;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$word</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;\b\S+\b&quot;</span></div></div>
<p>This is an intentionally broad pattern that searches for anything not a space. The \b element indicates a word boundary. Because this is a REGEX object, I can do a bit more than using a basic -match operator. Instead I&#8217;ll use the Matches() method which will return a collection of match objects. I can pipe these to Select-Object retrieving just the Value property. I also use the -Unique parameter to filter out duplicates. Finally the values are sorted.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$word</span>.Matches<span style="color: #000000;">&#40;</span><span style="color: #800080;">$content</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Value <span style="color: #008080; font-style: italic;">-unique</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">sort</span> Value</div></div>
<p>The matches and filtering are NOT case-sensitive, which is fine for me. With the list I can see where I might have used write-host instead of Write-Host and go back to clean up my code.  Let me show you how this works.  Here&#8217;s a demo script.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">#Requires -version 2.0</span><br />
<br />
<span style="color: #800080;">$comp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;Enter a computer name&quot;</span><br />
<br />
<span style="color: #008080; font-weight: bold;">write-host</span> <span style="color: #800000;">&quot;Querying services on $comp&quot;</span> <span style="color: pink;">-</span>fore Cyan<br />
<span style="color: #800080;">$svc</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">get-service</span> <span style="color: pink;">-</span>comp <span style="color: #800080;">$comp</span><br />
<br />
<span style="color: #800080;">$msg</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;I found {0} services on $comp&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$svc</span>.count<br />
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Results&quot;</span> <span style="color: pink;">-</span>fore Green<br />
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$mgs</span> <span style="color: pink;">-</span>fore Green</div></div>
<p>The script has some case inconsistencies as well as a typo.  I&#8217;ve dot sourced the function in my PowerShell session. Here&#8217;s what I end up with.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2dldC1jb250ZW50d29yZHMucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/get-contentwords-300x228.png" alt="" title="get-contentwords" width="300" height="228" class="aligncenter size-medium wp-image-2034" /></a></p>
<p>For best results, you need to make sure there are spaces around commands that use the = sign. But now I can scan through the list and pick out potential problems. Sure, Set-StrictMode would help with variable typos but if I had errors in say comment based help, that wouldn&#8217;t help. Maybe you&#8217;ll find this useful in your scripting work, maybe not. But I hope you learned a few things about working with REGEX objects and unique properties.</p>
<p>Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0dldC1Db250ZW50V29yZHMudHh0" target=\"_blank\">Get-ContentWords</a> and enjoy.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHMraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDElMkZmcmlkYXktZnVuLWdldC1jb250ZW50LXdvcmRzJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMvJmFtcDtoZWFkbGluZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRz" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3RpdGxlPUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHM=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3RpdGxlPUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHM=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3Q9RnJpZGF5K0Z1bitHZXQrQ29udGVudCtXb3Jkcw==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRzJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRzJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWdldC1jb250ZW50LXdvcmRzLyZhbXA7dGl0bGU9RnJpZGF5K0Z1bitHZXQrQ29udGVudCtXb3Jkcw==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3RpdGxlPUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHM=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMvJmFtcDt0aXRsZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRz" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWdldC1jb250ZW50LXdvcmRzLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2033" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/0/da"><img src="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/1/da"><img src="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/e4zco8By24k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-get-content-words</feedburner:origLink></item>
		<item>
		<title>PowerShell in a Nutshell</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/ZGWdQOE8qlk/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 12:56:33 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2025</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
This past weekend I did an online presentation for a friend of mine who teaches for ITT in Omaha, Nebraska. He wanted me to do a brief talk about what PowerShell is and show how to use it, especially for &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>This past weekend I did an online presentation for a friend of mine who teaches for ITT in Omaha, Nebraska. He wanted me to do a brief talk about what PowerShell is and show how to use it, especially for managing Active Directory. I probably went much longer than I needed but everyone seemed to get a lot out of it. The session was recorded via WebEx. I then transcoded the recording so I could get it up on YouTube. That&#8217;s why the screen layout is a little funky and the audio is far from perfect. Still, I hope you find it useful. The presentation has a some slides but is primarily demo, including using the Microsoft Active Directory cmdlets.</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/vvCtUwHN2XI" frameborder="0" allowfullscreen></iframe></p>
<p>You can also <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL1Bvd2VyU2hlbGwtTWFuYWdlbWVudC1pbi1hLU51dHNoZWxsLnBkZg==">download my presentation</a> and a <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL1Bvd2VyU2hlbGxfTWFuYWdlbWVudF9pbl9hX051dHNoZWxsLnppcA==">zip file</a>with my demo scripts. </p>
<p>If you are ready to learn more check out some of the books and training videos in the side bar. Or bring me in to run a private PowerShell class for your organization.  Good Luck and Enjoy!</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVBvd2VyU2hlbGwraW4rYStOdXRzaGVsbCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwMSUyRnBvd2Vyc2hlbGwtaW4tYS1udXRzaGVsbCUyRg==" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3Bvd2Vyc2hlbGwtaW4tYS1udXRzaGVsbC8mYW1wO2hlYWRsaW5lPVBvd2VyU2hlbGwraW4rYStOdXRzaGVsbA==" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtpbithK051dHNoZWxs" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtpbithK051dHNoZWxs" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dD1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGw=" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLw==" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7aW1hZ2V1cmw9" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLw==" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9wb3dlcnNoZWxsLWluLWEtbnV0c2hlbGwvJmFtcDt0aXRsZT1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGw=" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtpbithK051dHNoZWxs" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3Bvd2Vyc2hlbGwtaW4tYS1udXRzaGVsbC8mYW1wO3RpdGxlPVBvd2VyU2hlbGwraW4rYStOdXRzaGVsbA==" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9wb3dlcnNoZWxsLWluLWEtbnV0c2hlbGwv" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2025" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/0/da"><img src="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/1/da"><img src="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/ZGWdQOE8qlk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-in-a-nutshell</feedburner:origLink></item>
		<item>
		<title>Friday Fun: A PowerShell Alarm Clock</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/KRAy-pY-Mwc/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 14:28:42 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[FridayFun]]></category>
		<category><![CDATA[Jobs]]></category>
		<category><![CDATA[Start-Job]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2016</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
Today&#8217;s Friday Fun is a continuation of my exploration of ways to use Start-Job. A few weeks ago I wrote about using Start-Job to create &#8220;scheduled&#8221; tasks. I realized I could take this further and turn this into a sort &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>Today&#8217;s Friday Fun is a continuation of my exploration of ways to use Start-Job. A few weeks ago I wrote about <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2svI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA==" target=\"_blank\">using Start-Job to create &#8220;scheduled&#8221; tasks</a>. I realized I could take this further and turn this into a sort of alarm clock. The goal is to execute at command at a given time, but I wanted to make it easy to specify the time. What I have so far is a function called New-Alarm. I have some other ideas and hope to expand this into a module, but for now I thought I&#8217;d toss this out to you and get some feedback.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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>Alarm <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span>SupportsShouldProcess<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>DefaultParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">Param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullorEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Command</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Notepad&quot;</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">1</span><span style="color: pink;">,</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullorEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>Alias<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$Alarm</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>.AddMinutes<span style="color: #000000;">&#40;</span><span style="color: #804000;">5</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Seconds&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Seconds</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Minutes&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Minutes</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Hours&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Hours</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>Alias<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;init&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;is&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$InitializationScript</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$Alarm</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>.AddSeconds<span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$minutes</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$Alarm</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>.AddMinutes<span style="color: #000000;">&#40;</span><span style="color: #800080;">$minutes</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Hours</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$Alarm</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>.AddHours<span style="color: #000000;">&#40;</span><span style="color: #800080;">$hours</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;{0} Creating an alarm for {1} to execute {2}&quot;</span> <span style="color: #FF0000;">-f</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: pink;">,</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">,</span><span style="color: #800080;">$Command</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;">#define a scriptblock that takes parameters. Parameters are validated in the</span><br />
<span style="color: #008000;">#function so we don't need to do it here.</span><br />
<span style="color: #800080;">$sbText</span><span style="color: pink;">=@</span><span style="color: #800000;">&quot;<br />
&nbsp; &nbsp; Param ([string]<span style="color: #008080; font-weight: bold;">`$</span>Command,[datetime]<span style="color: #008080; font-weight: bold;">`$</span>Alarm,[string]<span style="color: #008080; font-weight: bold;">`$</span>Init)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #define a boolean flag<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>False<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #loop until the time is greater or equal to the alarm time<br />
&nbsp; &nbsp; #sleeping every 10 seconds<br />
&nbsp; &nbsp; do &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ((get-date) -ge <span style="color: #008080; font-weight: bold;">`$</span>Alarm) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #run the command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>ActualTime=Get-Date<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invoke-Expression <span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #set the flag to True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sleep -Seconds 10<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; } while (-Not <span style="color: #008080; font-weight: bold;">`$</span>Done)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #write an alarm summary object which can be retrieved with Receive-Job<br />
&nbsp; &nbsp; New-Object -TypeName PSObject -Property @{<br />
&nbsp; &nbsp; &nbsp; ScheduledTime=<span style="color: #008080; font-weight: bold;">`$</span>Alarm<br />
&nbsp; &nbsp; &nbsp; ActualTime=<span style="color: #008080; font-weight: bold;">`$</span>ActualTime<br />
&nbsp; &nbsp; &nbsp; Command=<span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; Initialization=<span style="color: #008080; font-weight: bold;">`$</span>Init<br />
&nbsp; &nbsp; }<br />
&quot;</span><span style="color: pink;">@</span><br />
<br />
<span style="color: #008000;">#append metadata to the scriptblock text so they can be parsed out with Get-Alarm</span><br />
<span style="color: #008000;">#to discover information for currently running alarm jobs</span><br />
<br />
<span style="color: #800080;">$meta</span><span style="color: pink;">=@</span><span style="color: #800000;">&quot;<br />
<br />
#Alarm Command::$Command<br />
#Alarm Time::$Alarm<br />
#Alarm Init::$InitializationScript<br />
#Alarm Created::$(Get-Date)<br />
<br />
&quot;</span><span style="color: pink;">@</span><br />
<br />
<span style="color: #008000;">#add meta data to scriptblock text</span><br />
<span style="color: #800080;">$sbText</span><span style="color: pink;">+=</span><span style="color: #800080;">$meta</span><br />
<br />
<span style="color: #008080; font-weight: bold;">Write-Debug</span> <span style="color: #800000;">&quot;Scriptblock text:&quot;</span><br />
<span style="color: #008080; font-weight: bold;">Write-Debug</span> <span style="color: #800080;">$sbText</span><br />
<span style="color: #008080; font-weight: bold;">Write-Debug</span> <span style="color: #800000;">&quot;Creating the scriptblock&quot;</span><br />
<br />
<span style="color: #008000;">#create a scriptblock to use with Start-Job</span><br />
<span style="color: #800080;">$sb</span><span style="color: pink;">=</span><span style="color: #800080;">$ExecutionContext</span>.InvokeCommand.NewScriptBlock<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sbText</span><span style="color: #000000;">&#41;</span><br />
<br />
Try <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$InitializationScript</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#turn $initializationscript into a script block</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$initsb</span><span style="color: pink;">=</span><span style="color: #800080;">$ExecutionContext</span>.InvokeCommand.NewScriptBlock<span style="color: #000000;">&#40;</span><span style="color: #800080;">$initializationscript</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;{0} Using an initialization script: {1}&quot;</span> <span style="color: #FF0000;">-f</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: pink;">,</span><span style="color: #800080;">$InitializationScript</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#no initialization command so create an empty scriptblock</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$initsb</span><span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">#WhatIf</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$pscmdlet</span>.ShouldProcess<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;$command at $Alarm&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#create a background job</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Start<span style="color: pink;">-</span>job <span style="color: pink;">-</span>ScriptBlock <span style="color: #800080;">$sb</span> <span style="color: #008080; font-style: italic;">-ArgumentList</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Command</span><span style="color: pink;">,</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">,</span><span style="color: #800080;">$InitializationScript</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-ErrorAction</span> <span style="color: #800000;">&quot;Stop&quot;</span> <span style="color: pink;">-</span>InitializationScript <span style="color: #800080;">$Initsb</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;{0} Alarm Created&quot;</span> <span style="color: #FF0000;">-f</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; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Catch <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$msg</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;{0} Exception creating the alarm job. {1}&quot;</span> <span style="color: #FF0000;">-f</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: pink;">,</span><span style="color: #000080;">$_</span>.Exception.Message<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #800080;">$msg</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#Process</span><br />
<br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#end function</span></div></div>
<p>The function includes full help.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL25ldy1hbGFybS1oZWxwLnBuZyN1dG1fc291cmNlPWZlZWQmYW1wO3V0bV9tZWRpdW09ZmVlZCZhbXA7dXRtX2NhbXBhaWduPWZlZWQ="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/new-alarm-help-300x197.png" alt="" title="new-alarm-help" width="300" height="197" class="aligncenter size-medium wp-image-2017" /></a></p>
<p>To use the function you specify a command string to execute at a given time. The default&#8217;s are to run Notepad in 5 minutes. You can either specify an exact time.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; new-alarm &quot;get-process | out-file c:\work\noonprocs.txt&quot; -alarm &quot;12:00PM&quot;</div></div>
<p>Or X number of seconds, minutes or hours.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; $s='$f=[system.io.path]::GetTempFilename(); &quot;Hey! Are you paying attention??&quot; &gt; $f;start-process notepad $f -wait;del $f'<br />
PS C:\&gt; new-alarm $s -minutes 15 -verbose</div></div>
<p>The first command defines a command string, $s. This creates a temporary file, writes some text to it, displays it with Notepad and then deletes it. The second command creates a new alarm that will invoke the expression in 15 minutes.</p>
<p>For now, the command is passed as text. This is so that I can create an internal scriptblock. I use a Do loop to compare the current time to the alarm time. When the time is right, the command string is executed using Invoke-Expression.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$sbText</span><span style="color: pink;">=@</span><span style="color: #800000;">&quot;<br />
&nbsp; &nbsp; Param ([string]<span style="color: #008080; font-weight: bold;">`$</span>Command,[datetime]<span style="color: #008080; font-weight: bold;">`$</span>Alarm,[string]<span style="color: #008080; font-weight: bold;">`$</span>Init)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #define a boolean flag<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>False<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #loop until the time is greater or equal to the alarm time<br />
&nbsp; &nbsp; #sleeping every 10 seconds<br />
&nbsp; &nbsp; do &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ((get-date) -ge <span style="color: #008080; font-weight: bold;">`$</span>Alarm) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #run the command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>ActualTime=Get-Date<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invoke-Expression <span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #set the flag to True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sleep -Seconds 10<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; } while (-Not <span style="color: #008080; font-weight: bold;">`$</span>Done)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #write an alarm summary object which can be retrieved with Receive-Job<br />
&nbsp; &nbsp; New-Object -TypeName PSObject -Property @{<br />
&nbsp; &nbsp; &nbsp; ScheduledTime=<span style="color: #008080; font-weight: bold;">`$</span>Alarm<br />
&nbsp; &nbsp; &nbsp; ActualTime=<span style="color: #008080; font-weight: bold;">`$</span>ActualTime<br />
&nbsp; &nbsp; &nbsp; Command=<span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; Initialization=<span style="color: #008080; font-weight: bold;">`$</span>Init<br />
&nbsp; &nbsp; }<br />
&quot;</span><span style="color: pink;">@</span></div></div>
<p>I also add some metadata to the script block which gets written as the job&#8217;s result.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#append metadata to the scriptblock text so they can be parsed out with Get-Alarm<br />
#to discover information for currently running alarm jobs<br />
<br />
$meta=@&quot;<br />
<br />
#Alarm Command::$Command<br />
#Alarm Time::$Alarm<br />
#Alarm Init::$InitializationScript<br />
#Alarm Created::$(Get-Date)<br />
<br />
&quot;@<br />
<br />
#add meta data to scriptblock text<br />
$sbText+=$meta<br />
<br />
Write-Debug &quot;Scriptblock text:&quot;<br />
Write-Debug $sbText<br />
Write-Debug &quot;Creating the scriptblock&quot;<br />
<br />
#create a scriptblock to use with Start-Job<br />
$sb=$ExecutionContext.InvokeCommand.NewScriptBlock($sbText)</div></div>
<p>Finally, the alarm function allows for an initialization command, like you might use with Start-Job. This permits you to run commands such as importing modules or dot sourcing scripts.  I have a function that displays a VB style message box. Here&#8217;s how I might use it as an alarm job.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; new-alarm &quot;get-messagebox 'It is time for that thing' -title 'Alert!'&quot; -init &quot;. c:\scripts\get-messagebox.ps1&quot; -min 5</div></div>
<p>In 5 minutes the alarm will go off and I&#8217;ll get this.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2FsZXJ0LnBuZyN1dG1fc291cmNlPWZlZWQmYW1wO3V0bV9tZWRpdW09ZmVlZCZhbXA7dXRtX2NhbXBhaWduPWZlZWQ="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/alert.png" alt="" title="alert" width="227" height="161" class="aligncenter size-full wp-image-2018" /></a></p>
<p>Remember, the function is creating new jobs with the Start-Job cmdlet. Which means I can get job results.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; receive-job 7 -keep<br />
<br />
Initialization : . c:\scripts\get-messagebox.ps1<br />
ActualTime &nbsp; &nbsp; : 1/20/2012 8:47:07 AM<br />
ScheduledTime &nbsp;: 1/20/2012 8:47:06 AM<br />
Command &nbsp; &nbsp; &nbsp; &nbsp;: get-messagebox 'It is time for that thing' -title 'Alert!'<br />
RunspaceId &nbsp; &nbsp; : d3461b78-11ce-4c84-a8ab-9e3fcd482637</div></div>
<p>What do you think? As I said, I have a few more ideas and there are certainly a few tweaks I can make even to this code. I&#8217;ve added my Get-MessageBox function in case you want to toy with that.  Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0FsYXJtU2NyaXB0cy56aXA=">AlarmScripts.zip</a> and let me know what you think.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4lM0ErQStQb3dlclNoZWxsK0FsYXJtK0Nsb2NrK2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjAxJTJGZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2slMkY=" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tYS1wb3dlcnNoZWxsLWFsYXJtLWNsb2NrLyZhbXA7aGVhZGxpbmU9RnJpZGF5K0Z1biUzQStBK1Bvd2VyU2hlbGwrQWxhcm0rQ2xvY2s=" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jaw==" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jaw==" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0PUZyaWRheStGdW4lM0ErQStQb3dlclNoZWxsK0FsYXJtK0Nsb2Nr" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jayZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8=" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDtpbWFnZXVybD0=" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jayZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8=" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErQStQb3dlclNoZWxsK0FsYXJtK0Nsb2Nr" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jaw==" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tYS1wb3dlcnNoZWxsLWFsYXJtLWNsb2NrLyZhbXA7dGl0bGU9RnJpZGF5K0Z1biUzQStBK1Bvd2VyU2hlbGwrQWxhcm0rQ2xvY2s=" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8=" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2016" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/0/da"><img src="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/1/da"><img src="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/KRAy-pY-Mwc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-a-powershell-alarm-clock</feedburner:origLink></item>
		<item>
		<title>Using Types with Imported CSV Data in PowerShell</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/EgKfMuYD3so/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 14:21:50 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Import-CSV]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[Where-Object]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2009</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
The Import-CSV cmdlet in PowerShell is incredibly useful. You can take any CSV file and pump objects to the pipeline. The cmdlet uses the CSV header as properties for the custom object. PS S:\&#62; import-csv .\testdata.csv Date &#160; &#160;: 1/18/2012 &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>The Import-CSV cmdlet in PowerShell is incredibly useful. You can take any CSV file and pump objects to the pipeline. The cmdlet uses the CSV header as properties for the custom object.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv .\testdata.csv<br />
<br />
<br />
Date &nbsp; &nbsp;: 1/18/2012 6:45:30 AM<br />
Name &nbsp; &nbsp;: Data_1<br />
Service : ALG<br />
Key &nbsp; &nbsp; : 1<br />
Size &nbsp; &nbsp;: 25<br />
<br />
Date &nbsp; &nbsp;: 1/18/2012 2:17:30 AM<br />
Name &nbsp; &nbsp;: Data_2<br />
Service : AppIDSvc<br />
Key &nbsp; &nbsp; : 2<br />
Size &nbsp; &nbsp;: -30<br />
...</div></div>
<p>But there is a downside: all of the properties are strings.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv .\testdata.csv | get-member<br />
<br />
<br />
&nbsp; &nbsp;TypeName: System.Management.Automation.PSCustomObject<br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;MemberType &nbsp; Definition<br />
---- &nbsp; &nbsp; &nbsp; &nbsp;---------- &nbsp; ----------<br />
Equals &nbsp; &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; bool Equals(System.Object obj)<br />
GetHashCode Method &nbsp; &nbsp; &nbsp; int GetHashCode()<br />
GetType &nbsp; &nbsp; Method &nbsp; &nbsp; &nbsp; type GetType()<br />
ToString &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; string ToString()<br />
Date &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Date=1/18/2012 6:45:30 AM<br />
Key &nbsp; &nbsp; &nbsp; &nbsp; NoteProperty System.String Key=1<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Name=Data_1<br />
Service &nbsp; &nbsp; NoteProperty System.String Service=ALG<br />
Size &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Size=25</div></div>
<p>The means some tasks such sorting or filtering will fail. But there are ways to get around this limitation. One way is to use an expression to cast a property to a different type. For example, I want to sort my test data on the Date property, but it needs to be a [DateTime] object to sort properly. Here&#8217;s how:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv testdata.csv &nbsp;| sort @{expression={$_.date -as [datetime]}} | Select Date,Name,Size<br />
<br />
Date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Size<br />
---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ----<br />
1/9/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; &nbsp;Data_25 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;26<br />
1/11/2012 11:13:30 AM &nbsp; &nbsp; &nbsp;Data_20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;44<br />
1/11/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; Data_23 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;33<br />
1/13/2012 12:13:30 AM &nbsp; &nbsp; &nbsp;Data_16 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;42<br />
1/13/2012 4:45:30 PM &nbsp; &nbsp; &nbsp; Data_24 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;47<br />
...</div></div>
<p>My output object properties are all still strings. All I did was cast the Date property in the Sort expression. Here&#8217;s an example using filtering.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv testdata.csv &nbsp;| where {($_.date -as [datetime]) -le (&quot;1/12/2012&quot; -as [datetime])} | Select Date,Name,Size<br />
<br />
Date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Size<br />
---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ----<br />
1/11/2012 11:13:30 AM &nbsp; &nbsp; &nbsp;Data_20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;44<br />
1/11/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; Data_23 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;33<br />
1/9/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; &nbsp;Data_25 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;26</div></div>
<p>These examples are only producing results. More likely I want to import the CSV file as typed objects.  Assuming you know in advance the property names and what types you want to use, here&#8217;s how you could achieve this.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $data=import-csv testdata.csv | Select @{Name=&quot;Date&quot;;Expression={[datetime]$_.Date}}, Name,Service,@{Name=&quot;Key&quot;;Expression={[int32]$_.Key}},@{Name=&quot;Size&quot;;Expression={[int32]$_.Size}}</div></div>
<p>I imported my CSV file and piped it to Select-Object, using hash tables to redefine the properties with appropriate types. Import-CSV writes a PSCustomObject to the pipeline anyway so using Select-Object has no effect other than giving me typed properties.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $data | get-member<br />
<br />
<br />
&nbsp; &nbsp;TypeName: Selected.System.Management.Automation.PSCustomObject<br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;MemberType &nbsp; Definition<br />
---- &nbsp; &nbsp; &nbsp; &nbsp;---------- &nbsp; ----------<br />
Equals &nbsp; &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; bool Equals(System.Object obj)<br />
GetHashCode Method &nbsp; &nbsp; &nbsp; int GetHashCode()<br />
GetType &nbsp; &nbsp; Method &nbsp; &nbsp; &nbsp; type GetType()<br />
ToString &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; string ToString()<br />
Date &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.DateTime Date=1/18/2012 6:45:30 AM<br />
Key &nbsp; &nbsp; &nbsp; &nbsp; NoteProperty System.Int32 Key=1<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Name=Data_1<br />
Service &nbsp; &nbsp; NoteProperty System.String Service=ALG<br />
Size &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.Int32 Size=25</div></div>
<p>Now I can use $data objects anyway I want.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $data | where {$_.size -ge 40 -AND $_.key -le 10}<br />
<br />
<br />
Date &nbsp; &nbsp;: 1/17/2012 11:57:30 PM<br />
Name &nbsp; &nbsp;: Data_3<br />
Service : Appinfo<br />
Key &nbsp; &nbsp; : 3<br />
Size &nbsp; &nbsp;: 42</div></div>
<p>I&#8217;m working on something that takes this idea to the next level but it isn&#8217;t quite ready for prime time. But I hope this will help manage imported objects a bit more efficiently and let you really take advantage of the PowerShell pipeline.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVVzaW5nK1R5cGVzK3dpdGgrSW1wb3J0ZWQrQ1NWK0RhdGEraW4rUG93ZXJTaGVsbCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwMSUyRnVzaW5nLXR5cGVzLXdpdGgtaW1wb3J0ZWQtY3N2LWRhdGEtaW4tcG93ZXJzaGVsbCUyRg==" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3VzaW5nLXR5cGVzLXdpdGgtaW1wb3J0ZWQtY3N2LWRhdGEtaW4tcG93ZXJzaGVsbC8mYW1wO2hlYWRsaW5lPVVzaW5nK1R5cGVzK3dpdGgrSW1wb3J0ZWQrQ1NWK0RhdGEraW4rUG93ZXJTaGVsbA==" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9VXNpbmcrVHlwZXMrd2l0aCtJbXBvcnRlZCtDU1YrRGF0YStpbitQb3dlclNoZWxs" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9VXNpbmcrVHlwZXMrd2l0aCtJbXBvcnRlZCtDU1YrRGF0YStpbitQb3dlclNoZWxs" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dD1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGw=" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLw==" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7aW1hZ2V1cmw9" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLw==" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy10eXBlcy13aXRoLWltcG9ydGVkLWNzdi1kYXRhLWluLXBvd2Vyc2hlbGwvJmFtcDt0aXRsZT1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGw=" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9VXNpbmcrVHlwZXMrd2l0aCtJbXBvcnRlZCtDU1YrRGF0YStpbitQb3dlclNoZWxs" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3VzaW5nLXR5cGVzLXdpdGgtaW1wb3J0ZWQtY3N2LWRhdGEtaW4tcG93ZXJzaGVsbC8mYW1wO3RpdGxlPVVzaW5nK1R5cGVzK3dpdGgrSW1wb3J0ZWQrQ1NWK0RhdGEraW4rUG93ZXJTaGVsbA==" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy10eXBlcy13aXRoLWltcG9ydGVkLWNzdi1kYXRhLWluLXBvd2Vyc2hlbGwv" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2009" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/0/da"><img src="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/1/da"><img src="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/EgKfMuYD3so" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-types-with-imported-csv-data-in-powershell</feedburner:origLink></item>
		<item>
		<title>Friday Fun: Output to 2 Places in 1</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/DbMbqeiOA90/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 13:50:58 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[FridayFun]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Tee-Object]]></category>
		<category><![CDATA[Write-Host]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2002</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
Today&#8217;s Friday Fun comes out of a short exchange I had yesterday with Hal Rottenberg on Google Plus. We were playing around with piping a PowerShell command to Clip.exe which dumps the output to the Windows Clipboard. I got to &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>Today&#8217;s Friday Fun comes out of a short exchange I had yesterday with <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9wbHVzLmdvb2dsZS5jb20vMTA2NDIzNDIyMzcyNDIxMzgwNzgwL3Bvc3Rz" target=\"_blank\">Hal Rottenberg on Google Plus</a>. We were playing around with piping a PowerShell command to Clip.exe which dumps the output to the Windows Clipboard. I got to thinking about taking this a step further based on my needs as a writer. Often I&#8217;d like to see the results of a command and then copy and paste the results into whatever I&#8217;m working on. In other words, I need to TEE the output to two places.</p>
<p>PowerShell has a cmdlet called Tee-Object that follows this principal. The default behavior is to write output to the pipeline AND send it to a text file.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-service | tee c:\work\svc.txt</div></div>
<p>I&#8217;ll see the results and save them to a text file. I can also use this cmdlet to save results to a variable.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-service | tee c:\work\svc.txt<br />
<br />
Status &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DisplayName<br />
------ &nbsp; ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -----------<br />
Running &nbsp;AeLookupSvc &nbsp; &nbsp; &nbsp; &nbsp;Application Experience<br />
Stopped &nbsp;ALG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application Layer Gateway Service<br />
Stopped &nbsp;AppIDSvc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application Identity<br />
Stopped &nbsp;Appinfo &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application Information<br />
...<br />
Running &nbsp;wudfsvc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Windows Driver Foundation - User-mo...<br />
Stopped &nbsp;WwanSvc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WWAN AutoConfig<br />
<br />
<br />
PS C:\&gt; $svc.count<br />
196<br />
PS C:\&gt;</div></div>
<p>One approach I came up with to incorporate with Clip.exe was this:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-service | tee -Variable svc | clip</div></div>
<p>I don&#8217;t get the results immediately to the screen; they are saved to the variable. But at the same time output has been directed to the Windows Clipboard. That could be useful. But you know me, I always have to tinker a bit more and I ended up with a function called Out-Tee.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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> Out<span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">Tee</span> <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">Param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ValueFromPipeline<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$InputObject</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>alias<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;foregroundcolor&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;fg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$TextColor</span><span style="color: pink;">=</span><span style="color: #800080;">$host</span>.ui.rawui.ForegroundColor<br />
<span style="color: #000000;">&#41;</span><br />
<br />
Begin <span style="color: #000000;">&#123;</span><br />
&nbsp;<span style="color: #008000;">#define an empty array to hold piped in objects</span><br />
&nbsp;<span style="color: #800080;">$a</span><span style="color: pink;">=@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#add each piped in object to the array</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$a</span><span style="color: pink;">+=</span><span style="color: #800080;">$inputobject</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
End <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#write the array to the pipeline as a string then pass to Write-Host</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$a</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-string</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">write-host</span> <span style="color: pink;">-</span>fore <span style="color: #800080;">$textColor</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#write the array again to Clip.exe</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$a</span> <span style="color: pink;">|</span> clip<br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#end function</span></div></div>
<p>This simple function takes a PowerShell expression and writes the results to the console using Write-Host and also to the clipboard.  The default output will use the current console foreground color. But you can specify any other color that you would use with Write-Host. I even added some alias properties so you can use -foregroundcolor or -fg.</p>
<p>With this function I can see the result and have it dumped to the clipboard. Because the default text color is the same as my session, I don&#8217;t see any difference when using Out-Tee.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; ps | where {$_.ws -gt 100mb} | out-tee</div></div>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL291dC10ZWUtMS5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/out-tee-1-300x141.png" alt="" title="out-tee-1" width="300" height="141" class="aligncenter size-medium wp-image-2003" /></a></p>
<p>Or if I want to pretty it up, I can add a little color.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; ps | where {$_.ws -gt 100mb} | out-tee -TextColor green</div></div>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL291dC10ZWUtMi5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/out-tee-2-300x141.png" alt="" title="out-tee-2" width="300" height="141" class="aligncenter size-medium wp-image-2004" /></a></p>
<p>Of course, the clipboard is just text. But now I have something easier to use to save output to the clipboard so I can paste it into my documents, assuming I like the output I see on the screen. The one caveat is that this function only works with successful commands. Errors, warnings, or verbose statements won&#8217;t get dumped to the clipboard. I can think of some ways around that which I might try in a future version. But for my immediate needs this works just fine.</p>
<p>Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL091dC1UZWUudHh0" target='_blank'>Out-Tee</a> and give it a try.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzEraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDElMkZmcmlkYXktZnVuLW91dHB1dC10by0yLXBsYWNlcy1pbi0xJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEvJmFtcDtoZWFkbGluZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisx" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzE=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzE=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3Q9RnJpZGF5K0Z1biUzQStPdXRwdXQrdG8rMitQbGFjZXMraW4rMQ==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisxJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisxJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLW91dHB1dC10by0yLXBsYWNlcy1pbi0xLyZhbXA7dGl0bGU9RnJpZGF5K0Z1biUzQStPdXRwdXQrdG8rMitQbGFjZXMraW4rMQ==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzE=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEvJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisx" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLW91dHB1dC10by0yLXBsYWNlcy1pbi0xLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2002" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/0/da"><img src="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/1/da"><img src="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/DbMbqeiOA90" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-output-to-2-places-in-1</feedburner:origLink></item>
		<item>
		<title>Convert Text to Object Updated</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/Y6a-OeREV-I/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 14:43:45 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[CommandLine]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Convert]]></category>
		<category><![CDATA[Split]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=1995</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
I&#8217;ve had a few comments and emails lately about my post and script on converting text to objects. I decided the function needed a little more lovin&#8217; so today I have an updated version, complete with comment based help. Function &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>I&#8217;ve had a few comments and emails lately about my post and script on <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTEvMTAvY29udmVydC10ZXh0LXRvLW9iamVjdC8jdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk" target=\"_blank\">converting text to objects</a>. I decided the function needed a little more lovin&#8217; so today I have an updated version, complete with comment based help.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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> Convert<span style="color: pink;">-</span>TextToObject <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #008000;">&lt;#<br />
.Synopsis<br />
Convert text to a PowerShell object<br />
.Description<br />
This function takes a collection of simple delimited lines and<br />
turns them into an object. The function assumes a single delimiter.<br />
The default delimiter is the colon (:). The item to the left will be <br />
the property and the item on the left will be the property value.<br />
<br />
By default the function will split on every delimiter, but you can use<br />
the -SplitCount parameter to control the number of strings. If you don't <br />
want to split at all use a value of 1. To split on the first delimiter <br />
only, use a value of 2.<br />
<br />
For example, if the string is: Foobar: &nbsp;01/11/2012 09:41:28 and you tried<br />
to split on the &quot;:&quot;, &nbsp;you would end up with 4 elements in the array. But <br />
using a -SplitCount value of 2 would give you this:<br />
<br />
Foobar<br />
01/11/2012 09:41:28<br />
<br />
Use $GroupCount to keep track of items that come in groups and write a new <br />
object when the count has been reached. For example, this allows you to <br />
pipe in a long collection of strings and turn every 5 into an object.<br />
<br />
This function works best with command line tools that write list-like<br />
output.<br />
<br />
.Parameter Text<br />
The text to be converted<br />
.Parameter Delimiter<br />
The text delimiter to split on. The colon (&quot;:&quot;) is the default.<br />
.Parameter SplitCount<br />
The number of strings to create when splitting. The default is to split<br />
on all delimiters. If you don't want to split at all use a value of 1. <br />
To split on the first delimiter only, use a value of 2.<br />
.Parameter GroupCount<br />
The number of piped in strings to group together to form a new object.<br />
.Example<br />
PS C:&gt; tasklist /s server01 /fo list | where {$_} | convert-texttoobject -group 5<br />
<br />
Take the output for Tasklist.exe as a list, strip out blank lines and pipe<br />
to Convert-TextToObject. Turn every 5 items into an object.<br />
.Example<br />
PS C:\&gt; get-content c:\work\data.txt | select -skip 4 | where {$_} | cto -group 4 -SplitCount 2 | format-list<br />
<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 5:44:56 AM<br />
DisplayName : 1394 OHCI Compliant Host Controller<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: 1394ohci<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:19:16 AM<br />
DisplayName : Microsoft ACPI Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: ACPI<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM<br />
DisplayName : ACPI Power Meter Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: AcpiPmi<br />
<br />
<br />
Get the Data.txt file, skipping the first 4 lines and stripping out blanks. <br />
Then create objects for every 4 lines. The SplitCount is set to 2 so that <br />
the LinkDate value is the complete datetime stamp.<br />
.Example<br />
PS C:\&gt; whoami /user /fo list | where {$_ -match &quot;:&quot;} | convert-texttoobject | format-table -auto<br />
<br />
UserName &nbsp; &nbsp; &nbsp;SID<br />
-------- &nbsp; &nbsp; &nbsp;---<br />
serenity\jeff S-1-5-21-2858895768-3673612314-3109562570-1000<br />
.Example<br />
PS C:\&gt; whoami /groups /fo list | where {$_ -match &quot;:&quot;} | cto -group 4 | format-list<br />
<br />
<br />
Attributes : Mandatory group, Enabled by default, Enabled group<br />
Type &nbsp; &nbsp; &nbsp; : Well-known group<br />
GroupName &nbsp;: Everyone<br />
SID &nbsp; &nbsp; &nbsp; &nbsp;: S-1-1-0<br />
<br />
Attributes : Mandatory group, Enabled by default, Enabled group, Group owner<br />
Type &nbsp; &nbsp; &nbsp; : Alias<br />
GroupName &nbsp;: BUILTIN\Administrators<br />
SID &nbsp; &nbsp; &nbsp; &nbsp;: S-1-5-32-544<br />
<br />
...<br />
<br />
Get group listing from Whoami.exe and filter out lines that don't have a colon.<br />
Create objects for every 4 lines. This example is using the cto alias for the<br />
Convert-TexttoObject function.<br />
.Link<br />
about_Split<br />
New-Object<br />
<br />
.Inputs<br />
Strings<br />
<br />
.Outputs<br />
Custom object<br />
#&gt;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span>SupportsShouldProcess<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>HelpMessage<span style="color: pink;">=</span><span style="color: #800000;">&quot;Enter a string to be parsed into an object&quot;</span><span style="color: pink;">,</span><br />
ValueFromPipeline<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullorEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Text</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullOrEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Delimiter</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>ValidateScript<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span> <span style="color: #FF0000;">-ge</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$SplitCount</span><span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$GroupCount</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
Begin <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Starting $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#define a hashtable</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$myHash</span><span style="color: pink;">=@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$GroupCount</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Grouping every $GroupCount items as an object&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#start an internal counter</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #804000;">0</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Skipping $Skip lines&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Using $Delimiter delimiter&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Splitting into $SplitCount lines. 0 means all.&quot;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000FF;">Foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$item</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$text</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$GroupCount</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$i</span><span style="color: pink;">++</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#reset</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #804000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#split each line at the delimiter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$data</span><span style="color: pink;">=</span><span style="color: #800080;">$item</span> <span style="color: pink;">-</span>Split <span style="color: #800080;">$delimiter</span><span style="color: pink;">,</span><span style="color: #800080;">$SplitCount</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#remove spaces from &quot;property&quot; name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$prop</span><span style="color: pink;">=</span><span style="color: #800080;">$data</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot; &quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#trim</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$prop</span><span style="color: pink;">=</span><span style="color: #800080;">$prop</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$val</span><span style="color: pink;">=</span><span style="color: #800080;">$data</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#add to hash table</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Adding $prop to hash table with a value of $val&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$myHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$prop</span><span style="color: pink;">,</span><span style="color: #800080;">$val</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#if internal counter is equal to the group count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#write the object and reset the hash table</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$groupCount</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> PSObject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: #800080;">$myHash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$myHash</span>.<span style="color: #008080; font-weight: bold;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#foreach</span><br />
<span style="color: #000000;">&#125;</span><br />
End <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#create new object from hash table</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$myHash</span>.count <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> PSObject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: #800080;">$myHash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Ending $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#end function</span></div></div>
<p>Check out the original article to understand the basics. The major change here is the SplitCount parameter. Often you might end up with a line of text like this:</p>
<p>LinkDate    : 11/20/2010 4:30:42 AM</p>
<p>The function needs to split the string into an array on the colon. But when you do that, the time stamp will &#8220;break&#8221;. The answer is to tell the Split operator how many strings to create. The default of 0 will split into all strings.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; &quot;DisplayName : ACPI Power Meter Driver&quot; -split &quot;:&quot;,0<br />
DisplayName<br />
&nbsp;ACPI Power Meter Driver</div></div>
<p>If I try that with the time stamp string you see the problem.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; &quot;LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM&quot; -split &quot;:&quot;,0<br />
LinkDate<br />
&nbsp;11/20/2010 4<br />
30<br />
42 AM</div></div>
<p>But now I can specify the number of strings and I get what I need.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; &quot;LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM&quot; -split &quot;:&quot;,2<br />
LinkDate<br />
&nbsp;11/20/2010 4:30:42 AM</div></div>
<p>The new version of the function incorporates this. I also received a comment about including a skip feature. I kicked that idea around for awhile, but decided in the end that PowerShell already had a mechanism for skipping lines. I wanted to keep my function limited to a single purpose. So if your text output includes a number of lines you want to skip, before you begin converting text to object, use something like this:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-content c:\work\data.txt | select -skip 4 | where {$_} | cto -group 4 -SplitCount 2 | format-list<br />
<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 5:44:56 AM<br />
DisplayName : 1394 OHCI Compliant Host Controller<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: 1394ohci<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:19:16 AM<br />
DisplayName : Microsoft ACPI Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: ACPI<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM<br />
DisplayName : ACPI Power Meter Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: AcpiPmi</div></div>
<p>The script file with the function, will also create an alias of cto. I hope you&#8217;ll download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0NvbnZlcnQtVGV4dHRvT2JqZWN0Li12MS41LnR4dA==" target='_blank'>Convert-TexttoObject.-v1.5</a> and let me know what you think.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUNvbnZlcnQrVGV4dCt0bytPYmplY3QrVXBkYXRlZCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwMSUyRmNvbnZlcnQtdGV4dC10by1vYmplY3QtdXBkYXRlZCUyRg==" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2NvbnZlcnQtdGV4dC10by1vYmplY3QtdXBkYXRlZC8mYW1wO2hlYWRsaW5lPUNvbnZlcnQrVGV4dCt0bytPYmplY3QrVXBkYXRlZA==" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dGl0bGU9Q29udmVydCtUZXh0K3RvK09iamVjdCtVcGRhdGVk" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dGl0bGU9Q29udmVydCtUZXh0K3RvK09iamVjdCtVcGRhdGVk" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dD1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQ=" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLw==" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7aW1hZ2V1cmw9" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLw==" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9jb252ZXJ0LXRleHQtdG8tb2JqZWN0LXVwZGF0ZWQvJmFtcDt0aXRsZT1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQ=" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dGl0bGU9Q29udmVydCtUZXh0K3RvK09iamVjdCtVcGRhdGVk" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2NvbnZlcnQtdGV4dC10by1vYmplY3QtdXBkYXRlZC8mYW1wO3RpdGxlPUNvbnZlcnQrVGV4dCt0bytPYmplY3QrVXBkYXRlZA==" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9jb252ZXJ0LXRleHQtdG8tb2JqZWN0LXVwZGF0ZWQv" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1995" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/Y6a-OeREV-I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=convert-text-to-object-updated</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 9.590 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-06 13:54:11 -->

