<?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>Wed, 16 May 2012 13:58:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</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>Introducing the ScriptingHelp PowerShell Module</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/DXIOARGuB_o/</link>
		<comments>http://jdhitsolutions.com/blog/2012/05/introducing-the-scriptinghelp-powershell-module/#comments</comments>
		<pubDate>Wed, 16 May 2012 13:47:58 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[ScriptingHelp]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2318</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>
Over the last few weeks I&#8217;ve posted articles on the different parameter validation options in Windows PowerShell. More than one person suggested consolidating the articles. That seemed like a good idea. There were a variety of ways to handle this &#8230; <a href="http://jdhitsolutions.com/blog/2012/05/introducing-the-scriptinghelp-powershell-module/">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=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDExLzAzL2hlbHBidWJibGUucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2011/03/helpbubble.png" alt="" title="helpbubble" width="180" height="180" class="alignleft size-full wp-image-1294" /></a>Over the last few weeks I&#8217;ve posted articles on the different parameter validation options in Windows PowerShell. More than one person suggested consolidating the articles. That seemed like a good idea. There were a variety of ways to handle this but I wanted something more PowerShell-oriented. Then I realized, why not produce PowerShell About topics? I could create a module that primarily was a collection of about topics on scripting in PowerShell. Import the module and you get the documentation. </p>
<p>In fact, this is a slick idea you might want to take advantage of: create a PowerShell module with nothing but documentation delivered via About_* files. If you are spending a lot of time in the shell, stay there! But before I get sidetracked, let&#8217;s look at the module I&#8217;m calling ScriptingHelp.</p>
<p>As I said the module is mostly a collection of About_* topics based on some of my blog articles. Then I realized I wanted to make it easier to expose them so I threw together a brief function called Get-ScriptingHelp.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L2dldC1zY3JpcHRpbmdoZWxwLnBuZyN1dG1fc291cmNlPWZlZWQmYW1wO3V0bV9tZWRpdW09ZmVlZCZhbXA7dXRtX2NhbXBhaWduPWZlZWQ="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/get-scriptinghelp-300x185.png" alt="" title="get-scriptinghelp" width="300" height="185" class="aligncenter size-medium wp-image-2320" /></a></p>
<p>The About topics are edited and revised versions of material previously posted on my blog.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L3NjcmlwdGluZ2hlbHAtdmFsaWRhdGVzZXQucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/scriptinghelp-validateset-300x185.png" alt="" title="scriptinghelp-validateset" width="300" height="185" class="aligncenter size-medium wp-image-2321" /></a></p>
<p>I plan on contributing additional content over time based on previous blog articles, suggestions or anything that comes to mind that I think can help you write more effective PowerShell scripts and functions.</p>
<p>To that end, I have also included a function to help you start scripting even faster. It is a new function wizard called Invoke-FunctionWizard. When you run the wizard, you will be prompted for information about your new function such as its name and parameter information. The wizard will then write a string object with the skeletal outline of your new function, complete with comment-based help. If you run the wizard in the ISE it will automatically insert the text into the currently open file. </p>
<p>But perhaps you&#8217;d like to see all of this in action.</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/a_6QXihUS0c" frameborder="0" allowfullscreen></iframe></p>
<p>I hope you&#8217;ll let me know what you think and if you find this useful or worthy of continued development. You can download a zip file of <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L1NjcmlwdGluZ0hlbHBfMF85LnppcA==">ScriptingHelp_0_9</a>. Extract the folder as a subfolder under C:\Users\<you>\Documents\WindowsPowerShell\Modules. Then import the ScriptingHelp module. This should work in both the console and the PowerShell ISE.  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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUludHJvZHVjaW5nK3RoZStTY3JpcHRpbmdIZWxwK1Bvd2VyU2hlbGwrTW9kdWxlK2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjA1JTJGaW50cm9kdWNpbmctdGhlLXNjcmlwdGluZ2hlbHAtcG93ZXJzaGVsbC1tb2R1bGUlMkY=" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L2ludHJvZHVjaW5nLXRoZS1zY3JpcHRpbmdoZWxwLXBvd2Vyc2hlbGwtbW9kdWxlLyZhbXA7aGVhZGxpbmU9SW50cm9kdWNpbmcrdGhlK1NjcmlwdGluZ0hlbHArUG93ZXJTaGVsbCtNb2R1bGU=" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvaW50cm9kdWNpbmctdGhlLXNjcmlwdGluZ2hlbHAtcG93ZXJzaGVsbC1tb2R1bGUvJmFtcDt0aXRsZT1JbnRyb2R1Y2luZyt0aGUrU2NyaXB0aW5nSGVscCtQb3dlclNoZWxsK01vZHVsZQ==" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvaW50cm9kdWNpbmctdGhlLXNjcmlwdGluZ2hlbHAtcG93ZXJzaGVsbC1tb2R1bGUvJmFtcDt0aXRsZT1JbnRyb2R1Y2luZyt0aGUrU2NyaXB0aW5nSGVscCtQb3dlclNoZWxsK01vZHVsZQ==" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvaW50cm9kdWNpbmctdGhlLXNjcmlwdGluZ2hlbHAtcG93ZXJzaGVsbC1tb2R1bGUvJmFtcDt0PUludHJvZHVjaW5nK3RoZStTY3JpcHRpbmdIZWxwK1Bvd2VyU2hlbGwrTW9kdWxl" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1JbnRyb2R1Y2luZyt0aGUrU2NyaXB0aW5nSGVscCtQb3dlclNoZWxsK01vZHVsZSZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9pbnRyb2R1Y2luZy10aGUtc2NyaXB0aW5naGVscC1wb3dlcnNoZWxsLW1vZHVsZS8=" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvaW50cm9kdWNpbmctdGhlLXNjcmlwdGluZ2hlbHAtcG93ZXJzaGVsbC1tb2R1bGUvJmFtcDtpbWFnZXVybD0=" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1JbnRyb2R1Y2luZyt0aGUrU2NyaXB0aW5nSGVscCtQb3dlclNoZWxsK01vZHVsZSZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9pbnRyb2R1Y2luZy10aGUtc2NyaXB0aW5naGVscC1wb3dlcnNoZWxsLW1vZHVsZS8=" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9pbnRyb2R1Y2luZy10aGUtc2NyaXB0aW5naGVscC1wb3dlcnNoZWxsLW1vZHVsZS8mYW1wO3RpdGxlPUludHJvZHVjaW5nK3RoZStTY3JpcHRpbmdIZWxwK1Bvd2VyU2hlbGwrTW9kdWxl" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvaW50cm9kdWNpbmctdGhlLXNjcmlwdGluZ2hlbHAtcG93ZXJzaGVsbC1tb2R1bGUvJmFtcDt0aXRsZT1JbnRyb2R1Y2luZyt0aGUrU2NyaXB0aW5nSGVscCtQb3dlclNoZWxsK01vZHVsZQ==" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L2ludHJvZHVjaW5nLXRoZS1zY3JpcHRpbmdoZWxwLXBvd2Vyc2hlbGwtbW9kdWxlLyZhbXA7dGl0bGU9SW50cm9kdWNpbmcrdGhlK1NjcmlwdGluZ0hlbHArUG93ZXJTaGVsbCtNb2R1bGU=" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9pbnRyb2R1Y2luZy10aGUtc2NyaXB0aW5naGVscC1wb3dlcnNoZWxsLW1vZHVsZS8=" 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=2318" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/bPrwjGyer-2PR8V2WzZquvr2pjc/0/da"><img src="http://feedads.g.doubleclick.net/~a/bPrwjGyer-2PR8V2WzZquvr2pjc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/bPrwjGyer-2PR8V2WzZquvr2pjc/1/da"><img src="http://feedads.g.doubleclick.net/~a/bPrwjGyer-2PR8V2WzZquvr2pjc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/DXIOARGuB_o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/05/introducing-the-scriptinghelp-powershell-module/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/05/introducing-the-scriptinghelp-powershell-module/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=introducing-the-scriptinghelp-powershell-module</feedburner:origLink></item>
		<item>
		<title>PowerShell Scripting with [ValidateNotNullorEmpty]</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/RnseaRNYESk/</link>
		<comments>http://jdhitsolutions.com/blog/2012/05/powershell-scripting-with-validatenotnullorempty/#comments</comments>
		<pubDate>Tue, 15 May 2012 12:18:41 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2306</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 been writing about the different parameter validation attributes that you can use in your PowerShell scripting. One that I use in practically every script is [ValidateNotNullorEmpty()]. This validation will ensure that something is passed as a parameter value. I&#8217;m &#8230; <a href="http://jdhitsolutions.com/blog/2012/05/powershell-scripting-with-validatenotnullorempty/">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 been writing about the different parameter validation attributes that you can use in your PowerShell scripting. One that I use in practically every script is [ValidateNotNullorEmpty()]. This validation will ensure that something is passed as a parameter value. I&#8217;m not talking about making a parameter mandatory; only that if the user decides to use the parameter that something is passed.  Let&#8217;s look at my demo.</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: #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 process name like lsass&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><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Name</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;">$Computername</span><span style="color: pink;">=</span><span style="color: #800080;">$env</span>:computername<br />
<br />
<span style="color: #000000;">&#41;</span><br />
<br />
Try <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Get-Process</span> <span style="color: #008080; font-style: italic;">-Name</span> <span style="color: #800080;">$name</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span> <span style="color: #008080; font-style: italic;">-errorAction</span> <span style="color: #800000;">&quot;Stop&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: pink;">*,</span><br />
&nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Runtime&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</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>.StartTime<span style="color: #000000;">&#125;</span><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: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #000080;">$_</span>.Exception.Message<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>I&#8217;ve used the attribute on both parameters. The first parameter I&#8217;ve also made mandatory which makes it more likely that something will be entered. But if not, then the script will fail.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L3ZhbGlkYXRlbm90bnVsbG9yZW1wdHkucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/validatenotnullorempty-300x141.png" alt="" title="validatenotnullorempty" width="300" height="141" class="aligncenter size-medium wp-image-2307" /></a></p>
<p>I would get a similar message if the user forgot to complete the command.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L3ZhbGlkYXRlbm90bnVsbG9yZW1wdHktMi5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/validatenotnullorempty-2-300x91.png" alt="" title="validatenotnullorempty-2" width="300" height="91" class="aligncenter size-medium wp-image-2308" /></a></p>
<p>Even though I&#8217;m using a default value for Computername, as soon as the parameter is detected PowerShell assumes I&#8217;m going to use a different value.</p>
<p>Validation should work for missing values, a variable that might be null, or in general anything that is meaningless. However, it won&#8217;t prevent something quirky like this:</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 S:\<span style="color: #33cc33;">&gt;</span> $p=&quot; &quot;<br />
PS S:\<span style="color: #33cc33;">&gt;</span> .\demo-ValidateNotNull.ps1 -name $p<br />
WARNING: Cannot find a process with the name &quot; &quot;. <span style="color: #b1b100; font-weight: bold;">Verify</span> the process name and<br />
<span style="color: #00b100; font-weight: bold;">call</span> the cmdlet again.</div></div>
<p>The variable, while semantically meaningless to us, is not null or empty but a string of 1 space. If there&#8217;s the chance you might run into this situation then you can add additional validation checks to the parameter.</p>
<p>If you&#8217;d like, feel free to download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L2RlbW8tVmFsaWRhdGVOb3ROdWxsLnR4dA==" target='_blank'>Demo-ValidateNotNull</a> and see for yourself.</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVBvd2VyU2hlbGwrU2NyaXB0aW5nK3dpdGgrJTVCVmFsaWRhdGVOb3ROdWxsb3JFbXB0eSU1RCtodHRwJTNBJTJGJTJGYml0Lmx5JTJGSmdwZkNF" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3Bvd2Vyc2hlbGwtc2NyaXB0aW5nLXdpdGgtdmFsaWRhdGVub3RudWxsb3JlbXB0eS8mYW1wO2hlYWRsaW5lPVBvd2VyU2hlbGwrU2NyaXB0aW5nK3dpdGgrJTVCVmFsaWRhdGVOb3ROdWxsb3JFbXB0eSU1RA==" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZW5vdG51bGxvcmVtcHR5LyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtTY3JpcHRpbmcrd2l0aCslNUJWYWxpZGF0ZU5vdE51bGxvckVtcHR5JTVE" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZW5vdG51bGxvcmVtcHR5LyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtTY3JpcHRpbmcrd2l0aCslNUJWYWxpZGF0ZU5vdE51bGxvckVtcHR5JTVE" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZW5vdG51bGxvcmVtcHR5LyZhbXA7dD1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlTm90TnVsbG9yRW1wdHklNUQ=" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlTm90TnVsbG9yRW1wdHklNUQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZW5vdG51bGxvcmVtcHR5Lw==" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZW5vdG51bGxvcmVtcHR5LyZhbXA7aW1hZ2V1cmw9" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlTm90TnVsbG9yRW1wdHklNUQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZW5vdG51bGxvcmVtcHR5Lw==" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9wb3dlcnNoZWxsLXNjcmlwdGluZy13aXRoLXZhbGlkYXRlbm90bnVsbG9yZW1wdHkvJmFtcDt0aXRsZT1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlTm90TnVsbG9yRW1wdHklNUQ=" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZW5vdG51bGxvcmVtcHR5LyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtTY3JpcHRpbmcrd2l0aCslNUJWYWxpZGF0ZU5vdE51bGxvckVtcHR5JTVE" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3Bvd2Vyc2hlbGwtc2NyaXB0aW5nLXdpdGgtdmFsaWRhdGVub3RudWxsb3JlbXB0eS8mYW1wO3RpdGxlPVBvd2VyU2hlbGwrU2NyaXB0aW5nK3dpdGgrJTVCVmFsaWRhdGVOb3ROdWxsb3JFbXB0eSU1RA==" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9wb3dlcnNoZWxsLXNjcmlwdGluZy13aXRoLXZhbGlkYXRlbm90bnVsbG9yZW1wdHkv" 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=2306" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/1TcAaFVy0OVe94Tfz-UBS1ofaJE/0/da"><img src="http://feedads.g.doubleclick.net/~a/1TcAaFVy0OVe94Tfz-UBS1ofaJE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/1TcAaFVy0OVe94Tfz-UBS1ofaJE/1/da"><img src="http://feedads.g.doubleclick.net/~a/1TcAaFVy0OVe94Tfz-UBS1ofaJE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/RnseaRNYESk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/05/powershell-scripting-with-validatenotnullorempty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/05/powershell-scripting-with-validatenotnullorempty/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-scripting-with-validatenotnullorempty</feedburner:origLink></item>
		<item>
		<title>SQL Saturday 129 Session Material</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/v4vWNydTKrw/</link>
		<comments>http://jdhitsolutions.com/blog/2012/05/sql-saturday-129-session-material/#comments</comments>
		<pubDate>Mon, 14 May 2012 13:51:32 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Powershell 3.0]]></category>
		<category><![CDATA[Windows 8]]></category>
		<category><![CDATA[scheduled job]]></category>
		<category><![CDATA[scheduled task]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[SQLSat]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2297</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 spoke this past weekend at a SQL Saturday event in Rochester, NY. My first SQL Saturday event and it was a lot of fun. A great turnout and some very interested attendees. I did three PowerShell sessions on jobs, &#8230; <a href="http://jdhitsolutions.com/blog/2012/05/sql-saturday-129-session-material/">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 src="http://jdhitsolutions.com/blog/wp-content/uploads/2011/10/talkbubble-150x150.png" alt="" title="talkbubble" width="150" height="150" class="alignleft size-thumbnail wp-image-1688" /></a>I spoke this past weekend at a <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5zcWxzYXR1cmRheS5jb20vMTI5L2V2ZW50aG9tZS5hc3B4" target=\"_blank\">SQL Saturday event in Rochester, NY</a>. My first SQL Saturday event and it was a lot of fun. A great turnout and some very interested attendees. I did three PowerShell sessions on jobs, scheduled jobs/tasks and an intro to workflows. The latter talk I think blew out some neurons on a few people, but I believe they were still enthusiastic about it.</p>
<p>For SQL Saturday attendees, I&#8217;ve posted my slide deck and demo files on the conference site. For everyone else, if you are interested, I&#8217;ll also make them available here.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L1Bvd2VyU2hlbGwtMy1Kb2JzLWFuZC1UYXNrcy56aXA=">PowerShell 3 Jobs and Tasks</a><br />
<a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L1Bvd2VyU2hlbGwtQmFja2dyb3VuZC1Kb2JzLnppcA==">PowerShell Background Jobs</a><br />
<a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L1Bvd2VyU2hlbGwtV29ya2Zsb3ctQmFzaWNzLnppcA==">PowerShell Workflow Basics</a></p>
<p>I expect I&#8217;ll be covering this material again in the future here as well as in my Prof. PowerShell column. And as always, if your organization is thinking about some private PowerShell training or mentoring, <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=bWFpbHRvOmpoaWNrc0BqZGhpdHNvbHV0aW9ucy5jb20/U3ViamVjdD1XZSBOZWVkIFBvd2VyU2hlbGwgVHJhaW5pbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk" target=\"_blank\">let me know</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVNRTCtTYXR1cmRheSsxMjkrU2Vzc2lvbitNYXRlcmlhbCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwNSUyRnNxbC1zYXR1cmRheS0xMjktc2Vzc2lvbi1tYXRlcmlhbCUyRg==" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3NxbC1zYXR1cmRheS0xMjktc2Vzc2lvbi1tYXRlcmlhbC8mYW1wO2hlYWRsaW5lPVNRTCtTYXR1cmRheSsxMjkrU2Vzc2lvbitNYXRlcmlhbA==" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc3FsLXNhdHVyZGF5LTEyOS1zZXNzaW9uLW1hdGVyaWFsLyZhbXA7dGl0bGU9U1FMK1NhdHVyZGF5KzEyOStTZXNzaW9uK01hdGVyaWFs" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc3FsLXNhdHVyZGF5LTEyOS1zZXNzaW9uLW1hdGVyaWFsLyZhbXA7dGl0bGU9U1FMK1NhdHVyZGF5KzEyOStTZXNzaW9uK01hdGVyaWFs" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc3FsLXNhdHVyZGF5LTEyOS1zZXNzaW9uLW1hdGVyaWFsLyZhbXA7dD1TUUwrU2F0dXJkYXkrMTI5K1Nlc3Npb24rTWF0ZXJpYWw=" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1TUUwrU2F0dXJkYXkrMTI5K1Nlc3Npb24rTWF0ZXJpYWwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc3FsLXNhdHVyZGF5LTEyOS1zZXNzaW9uLW1hdGVyaWFsLw==" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc3FsLXNhdHVyZGF5LTEyOS1zZXNzaW9uLW1hdGVyaWFsLyZhbXA7aW1hZ2V1cmw9" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1TUUwrU2F0dXJkYXkrMTI5K1Nlc3Npb24rTWF0ZXJpYWwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc3FsLXNhdHVyZGF5LTEyOS1zZXNzaW9uLW1hdGVyaWFsLw==" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9zcWwtc2F0dXJkYXktMTI5LXNlc3Npb24tbWF0ZXJpYWwvJmFtcDt0aXRsZT1TUUwrU2F0dXJkYXkrMTI5K1Nlc3Npb24rTWF0ZXJpYWw=" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc3FsLXNhdHVyZGF5LTEyOS1zZXNzaW9uLW1hdGVyaWFsLyZhbXA7dGl0bGU9U1FMK1NhdHVyZGF5KzEyOStTZXNzaW9uK01hdGVyaWFs" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3NxbC1zYXR1cmRheS0xMjktc2Vzc2lvbi1tYXRlcmlhbC8mYW1wO3RpdGxlPVNRTCtTYXR1cmRheSsxMjkrU2Vzc2lvbitNYXRlcmlhbA==" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9zcWwtc2F0dXJkYXktMTI5LXNlc3Npb24tbWF0ZXJpYWwv" 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=2297" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/fUwgAe6NQaqQbAuG3ZAMMjDJiBE/0/da"><img src="http://feedads.g.doubleclick.net/~a/fUwgAe6NQaqQbAuG3ZAMMjDJiBE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/fUwgAe6NQaqQbAuG3ZAMMjDJiBE/1/da"><img src="http://feedads.g.doubleclick.net/~a/fUwgAe6NQaqQbAuG3ZAMMjDJiBE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/v4vWNydTKrw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/05/sql-saturday-129-session-material/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/05/sql-saturday-129-session-material/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=sql-saturday-129-session-material</feedburner:origLink></item>
		<item>
		<title>Friday Fun: PowerShell ISE Function Finder</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/xZE8pRl0gMk/</link>
		<comments>http://jdhitsolutions.com/blog/2012/05/friday-fun-powershell-ise-function-finder/#comments</comments>
		<pubDate>Fri, 11 May 2012 13:37:07 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell ISE]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[ISE]]></category>
		<category><![CDATA[Out-Gridview]]></category>
		<category><![CDATA[ShowUI]]></category>
		<category><![CDATA[WPF]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2287</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>
At the PowerShell Deep Dive in San Diego, I did a lightning session showing off something I had been working on. Sometimes I don&#8217;t know what possesses me, but I felt the need for a better way to navigate my &#8230; <a href="http://jdhitsolutions.com/blog/2012/05/friday-fun-powershell-ise-function-finder/">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>At the PowerShell Deep Dive in San Diego, I did a lightning session showing off something I had been working on. Sometimes I don&#8217;t know what possesses me, but I felt the need for a better way to navigate my PowerShell scripts files that had many functions. Some files, especially modules, can get quite long and contain a number of functions. When using the PowerShell ISE I wanted a faster way to jump to a function. The problem is I don&#8217;t always remember what I called a function or where it is in the file. It is very easy to jump to a particular line in the ISE using the Ctrl+G shortcut. </p>
<p>So I started with some basics.</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;">$Path</span><span style="color: pink;">=</span><span style="color: #800080;">$psise</span>.CurrentFile.FullPath</div></div>
<p>I decided I&#8217;d use a regular expression pattern to find my functions. I write my functions 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: #0000FF;">Function</span> Get<span style="color: pink;">-</span>Foo <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #0000FF;">Param</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
...</div></div>
<p>So I came up with a regex pattern to match the first line and to include the Filter keyword as well.</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: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$r</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;^(Function|Filter)\s\S+\s{&quot;</span></div></div>
<p>I first thought of searching the content of the current file, but that won&#8217;t give me a line number. Then I thought of Select-String. With my regex pattern, I can get the content of the current file and pipe it to Select-String. The match object that comes out the other end of the pipeline includes a line number property (awesome) and the matching line. I decided to do a little string parsing on the later to drop off the trailing curly brace.</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;">$list</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">get-content</span> <span style="color: #800080;">$path</span> <span style="color: pink;">|</span> <br />
&nbsp;<span style="color: #008080; font-weight: bold;">select-string</span> <span style="color: #800080;">$r</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> LineNumber<span style="color: pink;">,</span><br />
&nbsp;<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Function&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Line.Split<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span></div></div>
<p>Because I&#8217;m in the ISE I felt the need to stay graphical, so my first thought was to pipe the results to Out-Gridview.</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;">$list</span> <span style="color: pink;">|</span> out<span style="color: pink;">-</span>gridview <span style="color: #008080; font-style: italic;">-Title</span> <span style="color: #800080;">$psise</span>.CurrentFile.FullPath</div></div>
<p>Here&#8217;s a sample result.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L2Z1bmN0aW9ubGlzdC1ncmlkdmlldy5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/functionlist-gridview-252x300.png" alt="" title="functionlist-gridview" width="252" height="300" class="aligncenter size-medium wp-image-2288" /></a></p>
<p>Now I can see the function name and line number. In the ISE I can do Ctrl+G and jump to the function. Of course, if I modify the file and line numbers change I need to close the grid and re-run my command.  But wait, there&#8217;s more&#8230;.</p>
<p>I&#8217;ve never done much with the WPF and figured this would be a great opportunity to do something with the <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3Nob3d1aS5jb2RlcGxleC5jb20v" title=\"Get the module from CodePlex\" target=\"_blank\">ShowUI</a> module. I already had the data. All I had to do was create a form with ShowUI. This is what I ended 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: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$n</span><span style="color: pink;">=</span><span style="color: #800080;">$psise</span>.CurrentFile.DisplayName <br />
ScrollViewer <span style="color: pink;">-</span>ControlName <span style="color: #800080;">$n</span> <span style="color: pink;">-</span>CanContentScroll &nbsp;<span style="color: pink;">-</span>tag <span style="color: #800080;">$psise</span>.CurrentFile.FullPath <span style="color: pink;">-</span>content <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;StackPanel &nbsp;<span style="color: pink;">-</span>MinWidth <span style="color: #804000;">300</span> <span style="color: pink;">-</span>MaxHeight <span style="color: #804000;">250</span> &nbsp;`<br />
&nbsp; &nbsp; &nbsp;<span style="color: pink;">-</span>orientation Vertical <span style="color: pink;">-</span>Children <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#get longest number if more than one function is found</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$count</span> <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #800080;">$list</span>.Linenumber<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; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #800080;">$list</span><span style="color: #000000;">&#91;</span><span style="color: pink;">-</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.Linenumber<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$l</span><span style="color: pink;">=</span><span style="color: #800080;">$i</span>.length<br />
&nbsp; &nbsp; &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;">$list</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$text</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;{0:d$l} &nbsp; &nbsp;{1}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$item</span>.linenumber<span style="color: pink;">,</span><span style="color: #800080;">$item</span>.<span style="color: #0000FF;">function</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button <span style="color: #800080;">$text</span> <span style="color: pink;">-</span>HorizontalContentAlignment Left <span style="color: pink;">-</span>On_Click <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#get the line number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$num</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;^\d+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#parse out the line number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$goto</span> <span style="color: pink;">=</span> <span style="color: #800080;">$num</span>.match<span style="color: #000000;">&#40;</span><span style="color: #800080;">$this</span>.content<span style="color: #000000;">&#41;</span>.value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#grab the file name from the tab value of the parent control</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$f</span><span style="color: pink;">=</span> <span style="color: #800080;">$parent</span> <span style="color: pink;">|</span> get<span style="color: pink;">-</span>uivalue<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Open the file in the editor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; psedit <span style="color: #800080;">$f</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#goto the selected line</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$psise</span>.CurrentFile.Editor.SetCaretPosition<span style="color: #000000;">&#40;</span><span style="color: #800080;">$goto</span><span style="color: pink;">,</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#close the control</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Get<span style="color: pink;">-</span>ParentControl <span style="color: pink;">|</span> Set<span style="color: pink;">-</span>UIValue <span style="color: #008080; font-style: italic;">-PassThru</span> <span style="color: pink;">|</span>Close<span style="color: pink;">-</span>Control<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#onclick</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#foreach</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span> <span style="color: pink;">-</span>show</div></div>
<p>The result is a stack panel of buttons in a scroll control. The button shows the line number and function name.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L2Z1bmN0aW9ubGlzdC1zaG93dWkucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/functionlist-showui-300x259.png" alt="" title="functionlist-showui" width="300" height="259" class="aligncenter size-medium wp-image-2290" /></a></p>
<p>When a button is clicked, the function gets the line number and automatically jumps to it. Originally I was leaving the control open, but this means the function is still running. And if I change the script the line numbers are off so I simply close the form after jumping to the function. </p>
<p>In the end, I packaged all of this as a script file that adds a menu choice. If ShowUI is available, the function will use it. Otherwise the function defaults to Out-GridView.</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>ISEFunction <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 />
<span style="color: #0000FF;">Param</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Path</span><span style="color: pink;">=</span><span style="color: #800080;">$psise</span>.CurrentFile.FullPath<span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;">#import ShowUI if found and use it later in the functoin</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span>Get<span style="color: pink;">-</span>module <span style="color: #008080; font-style: italic;">-name</span> ShowUI <span style="color: pink;">-</span>listavailable<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Import<span style="color: pink;">-</span>Module ShowUI<br />
&nbsp; &nbsp; <span style="color: #800080;">$showui</span><span style="color: pink;">=</span><span style="color: #800080;">$True</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Using Out-GridView&quot;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$showui</span><span style="color: pink;">=</span><span style="color: #800080;">$False</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008000;">#define a regex to find &quot;function | filter NAME {&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;">$r</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;^(Function|Filter)\s\S+\s{&quot;</span><br />
<br />
<span style="color: #800080;">$list</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">get-content</span> <span style="color: #800080;">$path</span> <span style="color: pink;">|</span> <br />
&nbsp;<span style="color: #008080; font-weight: bold;">select-string</span> <span style="color: #800080;">$r</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> LineNumber<span style="color: pink;">,</span><br />
&nbsp;<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Function&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Line.Split<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008000;">#were any functions found?</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$list</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$count</span><span style="color: pink;">=</span><span style="color: #800080;">$list</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">measure-object</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select-object</span> <span style="color: #008080; font-style: italic;">-ExpandProperty</span> Count<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Found $count functions&quot;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$showui</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #008000;">&lt;#<br />
&nbsp; &nbsp; &nbsp; &nbsp; display function list with a WPF Form from ShowUI<br />
&nbsp; &nbsp; &nbsp; &nbsp; Include file name so the right tab can get selected<br />
&nbsp; &nbsp; &nbsp;#&gt;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$n</span><span style="color: pink;">=</span><span style="color: #800080;">$psise</span>.CurrentFile.DisplayName<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Building list for $n&quot;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; ScrollViewer <span style="color: pink;">-</span>ControlName <span style="color: #800080;">$n</span> <span style="color: pink;">-</span>CanContentScroll &nbsp;<span style="color: pink;">-</span>tag <span style="color: #800080;">$psise</span>.CurrentFile.FullPath <span style="color: pink;">-</span>content <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp;StackPanel &nbsp;<span style="color: pink;">-</span>MinWidth <span style="color: #804000;">300</span> <span style="color: pink;">-</span>MaxHeight <span style="color: #804000;">250</span> &nbsp;`<br />
&nbsp; &nbsp; &nbsp;<span style="color: pink;">-</span>orientation Vertical <span style="color: pink;">-</span>Children <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#get longest number if more than one function is found</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$count</span> <span style="color: #FF0000;">-eq</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #800080;">$list</span>.Linenumber<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; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #800080;">$list</span><span style="color: #000000;">&#91;</span><span style="color: pink;">-</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.Linenumber<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$l</span><span style="color: pink;">=</span><span style="color: #800080;">$i</span>.length<br />
&nbsp; &nbsp; &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;">$list</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$text</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;{0:d$l} &nbsp; &nbsp;{1}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$item</span>.linenumber<span style="color: pink;">,</span><span style="color: #800080;">$item</span>.<span style="color: #0000FF;">function</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800080;">$text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Button <span style="color: #800080;">$text</span> <span style="color: pink;">-</span>HorizontalContentAlignment Left <span style="color: pink;">-</span>On_Click <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#get the line number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$num</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;^\d+&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#parse out the line number</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$goto</span> <span style="color: pink;">=</span> <span style="color: #800080;">$num</span>.match<span style="color: #000000;">&#40;</span><span style="color: #800080;">$this</span>.content<span style="color: #000000;">&#41;</span>.value<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#grab the file name from the tab value of the parent control</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$f</span><span style="color: pink;">=</span> <span style="color: #800080;">$parent</span> <span style="color: pink;">|</span> get<span style="color: pink;">-</span>uivalue<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Open the file in the editor</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; psedit <span style="color: #800080;">$f</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#goto the selected line</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$psise</span>.CurrentFile.Editor.SetCaretPosition<span style="color: #000000;">&#40;</span><span style="color: #800080;">$goto</span><span style="color: pink;">,</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#close the control</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Get<span style="color: pink;">-</span>ParentControl <span style="color: pink;">|</span> Set<span style="color: pink;">-</span>UIValue <span style="color: #008080; font-style: italic;">-PassThru</span> <span style="color: pink;">|</span>Close<span style="color: pink;">-</span>Control<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#onclick</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#foreach</span><br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span> <span style="color: pink;">-</span>show <br />
<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#if $showui</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 ShowUI module so use Out-GridView</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$list</span> <span style="color: pink;">|</span> out<span style="color: pink;">-</span>gridview <span style="color: #008080; font-style: italic;">-Title</span> <span style="color: #800080;">$psise</span>.CurrentFile.FullPath<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp;<span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp;<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;No functions found in $($psise.CurrentFile.FullPath)&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Magenta<br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#close function</span><br />
<br />
<span style="color: #008000;">#Add to the Add-ons menu</span><br />
<span style="color: #800080;">$PSISE</span>.CurrentPowerShellTab.AddOnsMenu.Submenus.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;List Functions&quot;</span><span style="color: pink;">,</span><span style="color: #000000;">&#123;</span>Get<span style="color: pink;">-</span>ISEFunction<span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><span style="color: #800080;">$null</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;">#optional alias</span><br />
<span style="color: #008080; font-weight: bold;">set-alias</span> gif get<span style="color: pink;">-</span>isefunction</div></div>
<p>Now, I can click the List Functions menu choice and I&#8217;ll get a graphical list of any functions in the current file. I&#8217;m sure the regex could be tweaked. I&#8217;m also sure there are improvements I could make to the ShowUI code, but it works.</p>
<p>Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L0dldC1JU0VGdW5jdGlvbi50eHQ=" target='_blank'>Get-ISEFunction</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4lM0ErUG93ZXJTaGVsbCtJU0UrRnVuY3Rpb24rRmluZGVyK2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjA1JTJGZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWlzZS1mdW5jdGlvbi1maW5kZXIlMkY=" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L2ZyaWRheS1mdW4tcG93ZXJzaGVsbC1pc2UtZnVuY3Rpb24tZmluZGVyLyZhbXA7aGVhZGxpbmU9RnJpZGF5K0Z1biUzQStQb3dlclNoZWxsK0lTRStGdW5jdGlvbitGaW5kZXI=" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWlzZS1mdW5jdGlvbi1maW5kZXIvJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrSVNFK0Z1bmN0aW9uK0ZpbmRlcg==" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWlzZS1mdW5jdGlvbi1maW5kZXIvJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrSVNFK0Z1bmN0aW9uK0ZpbmRlcg==" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWlzZS1mdW5jdGlvbi1maW5kZXIvJmFtcDt0PUZyaWRheStGdW4lM0ErUG93ZXJTaGVsbCtJU0UrRnVuY3Rpb24rRmluZGVy" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrSVNFK0Z1bmN0aW9uK0ZpbmRlciZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9mcmlkYXktZnVuLXBvd2Vyc2hlbGwtaXNlLWZ1bmN0aW9uLWZpbmRlci8=" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWlzZS1mdW5jdGlvbi1maW5kZXIvJmFtcDtpbWFnZXVybD0=" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrSVNFK0Z1bmN0aW9uK0ZpbmRlciZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9mcmlkYXktZnVuLXBvd2Vyc2hlbGwtaXNlLWZ1bmN0aW9uLWZpbmRlci8=" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9mcmlkYXktZnVuLXBvd2Vyc2hlbGwtaXNlLWZ1bmN0aW9uLWZpbmRlci8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErUG93ZXJTaGVsbCtJU0UrRnVuY3Rpb24rRmluZGVy" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWlzZS1mdW5jdGlvbi1maW5kZXIvJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrSVNFK0Z1bmN0aW9uK0ZpbmRlcg==" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L2ZyaWRheS1mdW4tcG93ZXJzaGVsbC1pc2UtZnVuY3Rpb24tZmluZGVyLyZhbXA7dGl0bGU9RnJpZGF5K0Z1biUzQStQb3dlclNoZWxsK0lTRStGdW5jdGlvbitGaW5kZXI=" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9mcmlkYXktZnVuLXBvd2Vyc2hlbGwtaXNlLWZ1bmN0aW9uLWZpbmRlci8=" 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=2287" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/xVr_GSdmB6f0SbaJgd4hmv0tSek/0/da"><img src="http://feedads.g.doubleclick.net/~a/xVr_GSdmB6f0SbaJgd4hmv0tSek/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/xVr_GSdmB6f0SbaJgd4hmv0tSek/1/da"><img src="http://feedads.g.doubleclick.net/~a/xVr_GSdmB6f0SbaJgd4hmv0tSek/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/xZE8pRl0gMk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/05/friday-fun-powershell-ise-function-finder/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/05/friday-fun-powershell-ise-function-finder/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-powershell-ise-function-finder</feedburner:origLink></item>
		<item>
		<title>Quick and Dirty Excel from PowerShell</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/iA0zkOGBdF0/</link>
		<comments>http://jdhitsolutions.com/blog/2012/05/quick-and-dirty-excel-from-powershell/#comments</comments>
		<pubDate>Thu, 10 May 2012 12:56:43 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2281</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 continue to tinker with Office applications and Windows PowerShell. I was looking at an Excel issue related to opening a new workbook. To verify the problem wasn&#8217;t PowerShell related I offered a suggestion to try creating an Excel workbook &#8230; <a href="http://jdhitsolutions.com/blog/2012/05/quick-and-dirty-excel-from-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><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L2V4Y2VsXzIwMTBfbG9nby5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/excel_2010_logo-150x150.png" alt="" title="excel_2010_logo" width="150" height="150" class="alignleft size-thumbnail wp-image-2282" /></a> I continue to tinker with Office applications and Windows PowerShell. I was looking at an Excel issue related to opening a new workbook. To verify the problem wasn&#8217;t PowerShell related I offered a suggestion to try creating an Excel workbook in VBScript.</p>
<p>In VBScript creating a blank workbook in Microsoft Excel can be accomplished with three lines of code.</p>
<div class="codecolorer-container vb geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="vb codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #151B8D; font-weight: bold;">set</span> xl=wscript.<span style="color: #E56717; font-weight: bold;">createObject</span>(<span style="color: #800000;">&quot;Excel.Application&quot;</span>)<br />
<span style="color: #151B8D; font-weight: bold;">set</span> wb=xl.workbooks.add()<br />
xl.Visible=vbTrue</div></div>
<p>In Windows PowerShell we essentially use the same 3 lines.</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;">$xl</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">new-object</span> <span style="color: pink;">-</span>com <span style="color: #800000;">&quot;excel.application&quot;</span><br />
<span style="color: #800080;">$sb</span><span style="color: pink;">=</span><span style="color: #800080;">$xl</span>.Workbooks.Add<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$xl</span>.Visible<span style="color: pink;">=</span>$True</div></div>
<p>But PowerShell is all about the objects, so how about a quick and dirty approach? Something perhaps in one line:</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;">PS</span> S:\<span style="color: pink;">&gt;</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">new-object</span> <span style="color: pink;">-</span>com <span style="color: #800000;">&quot;excel.application&quot;</span><span style="color: #000000;">&#41;</span>.Workbooks.Add<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.application.Visible<span style="color: pink;">=</span>$True</div></div>
<p>You could easily build a simple function to run the 3 lines it takes to open a new Excel workbook but one-liners like this make me smile. Granted, I&#8217;m probably not likely to use it, but if nothing else I think it reinforces the object nature of Windows PowerShell. </p>
<p>Each expression nested in () is treated as an object. The inner most expression using New-Object, creates the Excel application object which has a Workbooks property that is an object with an Add() method. Invoking this method creates the workbook object. If I stopped there Excel would be running but not visible. So I get the Application property of the workbook object, and set the Visible property to True.</p>
<p>This command doesn&#8217;t offer any way to continue working with Excel from PowerShell; it only opens a new workbook. Let me be clear, I&#8217;m not advocating that this is how you work with Excel from PowerShell. I think you will need scripts like the ones I posted from my <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2JpdC5seS9JWVhwT0Y=" title=\"San Diego 2012 PowerShell Deep Dive Slides and Demos\" target=\"_blank\">Deep Dive session</a>. But this one-liner demonstrates what is possible with PowerShell and maybe it will add a little smile to your day as well.</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVF1aWNrK2FuZCtEaXJ0eStFeGNlbCtmcm9tK1Bvd2VyU2hlbGwraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDUlMkZxdWljay1hbmQtZGlydHktZXhjZWwtZnJvbS1wb3dlcnNoZWxsJTJG" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3F1aWNrLWFuZC1kaXJ0eS1leGNlbC1mcm9tLXBvd2Vyc2hlbGwvJmFtcDtoZWFkbGluZT1RdWljaythbmQrRGlydHkrRXhjZWwrZnJvbStQb3dlclNoZWxs" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcXVpY2stYW5kLWRpcnR5LWV4Y2VsLWZyb20tcG93ZXJzaGVsbC8mYW1wO3RpdGxlPVF1aWNrK2FuZCtEaXJ0eStFeGNlbCtmcm9tK1Bvd2VyU2hlbGw=" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcXVpY2stYW5kLWRpcnR5LWV4Y2VsLWZyb20tcG93ZXJzaGVsbC8mYW1wO3RpdGxlPVF1aWNrK2FuZCtEaXJ0eStFeGNlbCtmcm9tK1Bvd2VyU2hlbGw=" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcXVpY2stYW5kLWRpcnR5LWV4Y2VsLWZyb20tcG93ZXJzaGVsbC8mYW1wO3Q9UXVpY2srYW5kK0RpcnR5K0V4Y2VsK2Zyb20rUG93ZXJTaGVsbA==" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1RdWljaythbmQrRGlydHkrRXhjZWwrZnJvbStQb3dlclNoZWxsJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3F1aWNrLWFuZC1kaXJ0eS1leGNlbC1mcm9tLXBvd2Vyc2hlbGwv" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcXVpY2stYW5kLWRpcnR5LWV4Y2VsLWZyb20tcG93ZXJzaGVsbC8mYW1wO2ltYWdldXJsPQ==" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1RdWljaythbmQrRGlydHkrRXhjZWwrZnJvbStQb3dlclNoZWxsJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3F1aWNrLWFuZC1kaXJ0eS1leGNlbC1mcm9tLXBvd2Vyc2hlbGwv" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9xdWljay1hbmQtZGlydHktZXhjZWwtZnJvbS1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9UXVpY2srYW5kK0RpcnR5K0V4Y2VsK2Zyb20rUG93ZXJTaGVsbA==" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvcXVpY2stYW5kLWRpcnR5LWV4Y2VsLWZyb20tcG93ZXJzaGVsbC8mYW1wO3RpdGxlPVF1aWNrK2FuZCtEaXJ0eStFeGNlbCtmcm9tK1Bvd2VyU2hlbGw=" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3F1aWNrLWFuZC1kaXJ0eS1leGNlbC1mcm9tLXBvd2Vyc2hlbGwvJmFtcDt0aXRsZT1RdWljaythbmQrRGlydHkrRXhjZWwrZnJvbStQb3dlclNoZWxs" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9xdWljay1hbmQtZGlydHktZXhjZWwtZnJvbS1wb3dlcnNoZWxsLw==" 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=2281" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/qbZhmqUDrAb_8qdHIIp5T58i5FQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/qbZhmqUDrAb_8qdHIIp5T58i5FQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/qbZhmqUDrAb_8qdHIIp5T58i5FQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/qbZhmqUDrAb_8qdHIIp5T58i5FQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/iA0zkOGBdF0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/05/quick-and-dirty-excel-from-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/05/quick-and-dirty-excel-from-powershell/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=quick-and-dirty-excel-from-powershell</feedburner:origLink></item>
		<item>
		<title>San Diego 2012 PowerShell Deep Dive Slides and Demos</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/78lbqF9MLc8/</link>
		<comments>http://jdhitsolutions.com/blog/2012/05/san-diego-2012-powershell-deep-dive-slides-and-demos/#comments</comments>
		<pubDate>Tue, 08 May 2012 14:30:52 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[DeepDive]]></category>
		<category><![CDATA[Office]]></category>
		<category><![CDATA[TEC]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2273</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>
Last week at the PowerShell Deep Dive in San Diego, I did a short presentation on integrating Microsoft Office applications like Excel and Word with Windows PowerShell. I easily could have spoken much longer and probably tried to cram too &#8230; <a href="http://jdhitsolutions.com/blog/2012/05/san-diego-2012-powershell-deep-dive-slides-and-demos/">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=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L01pY3Jvc29mdF9Xb3JkX0ljb24ucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/05/Microsoft_Word_Icon-150x150.png" alt="" title="Microsoft_Word_Icon" width="150" height="150" class="alignleft size-thumbnail wp-image-2274" /></a> Last week at the PowerShell Deep Dive in San Diego, I did a short presentation on integrating Microsoft Office applications like Excel and Word with Windows PowerShell. I easily could have spoken much longer and probably tried to cram too much in. I spent a lot of time with my demos. I expect at some point a video of my talk will be posted on the TEC site.  In the mean time you can <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L0ludGVncmF0aW5nX09mZmljZV9Qb3dlclNoZWxsLnBkZg==">download a PDF of my slide deck</a> and a <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA1L1Bvd2VyU2hlbGwtT2ZmaWNlRGVtb3Muemlw">zip file</a> with all of my demos. Some of the scripts have been revised slightly since my presentation. The scripts are NOT intended for production use. They are demonstration and proof-of-concept scripts. Many of them have hard coded paths for additional files so read them carefully before you try to run. I&#8217;ve tried to comment extensively so you can understand what is going on, but this is admittedly a complicated topic. I&#8217;m hoping to create some additional videos around these demos, but if you have questions please post a comment.</p>
<p>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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVNhbitEaWVnbysyMDEyK1Bvd2VyU2hlbGwrRGVlcCtEaXZlK1NsaWRlcythbmQrRGVtb3MraHR0cCUzQSUyRiUyRmJpdC5seSUyRklZWHBPRg==" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3Nhbi1kaWVnby0yMDEyLXBvd2Vyc2hlbGwtZGVlcC1kaXZlLXNsaWRlcy1hbmQtZGVtb3MvJmFtcDtoZWFkbGluZT1TYW4rRGllZ28rMjAxMitQb3dlclNoZWxsK0RlZXArRGl2ZStTbGlkZXMrYW5kK0RlbW9z" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc2FuLWRpZWdvLTIwMTItcG93ZXJzaGVsbC1kZWVwLWRpdmUtc2xpZGVzLWFuZC1kZW1vcy8mYW1wO3RpdGxlPVNhbitEaWVnbysyMDEyK1Bvd2VyU2hlbGwrRGVlcCtEaXZlK1NsaWRlcythbmQrRGVtb3M=" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc2FuLWRpZWdvLTIwMTItcG93ZXJzaGVsbC1kZWVwLWRpdmUtc2xpZGVzLWFuZC1kZW1vcy8mYW1wO3RpdGxlPVNhbitEaWVnbysyMDEyK1Bvd2VyU2hlbGwrRGVlcCtEaXZlK1NsaWRlcythbmQrRGVtb3M=" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc2FuLWRpZWdvLTIwMTItcG93ZXJzaGVsbC1kZWVwLWRpdmUtc2xpZGVzLWFuZC1kZW1vcy8mYW1wO3Q9U2FuK0RpZWdvKzIwMTIrUG93ZXJTaGVsbCtEZWVwK0RpdmUrU2xpZGVzK2FuZCtEZW1vcw==" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1TYW4rRGllZ28rMjAxMitQb3dlclNoZWxsK0RlZXArRGl2ZStTbGlkZXMrYW5kK0RlbW9zJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3Nhbi1kaWVnby0yMDEyLXBvd2Vyc2hlbGwtZGVlcC1kaXZlLXNsaWRlcy1hbmQtZGVtb3Mv" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc2FuLWRpZWdvLTIwMTItcG93ZXJzaGVsbC1kZWVwLWRpdmUtc2xpZGVzLWFuZC1kZW1vcy8mYW1wO2ltYWdldXJsPQ==" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1TYW4rRGllZ28rMjAxMitQb3dlclNoZWxsK0RlZXArRGl2ZStTbGlkZXMrYW5kK0RlbW9zJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3Nhbi1kaWVnby0yMDEyLXBvd2Vyc2hlbGwtZGVlcC1kaXZlLXNsaWRlcy1hbmQtZGVtb3Mv" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9zYW4tZGllZ28tMjAxMi1wb3dlcnNoZWxsLWRlZXAtZGl2ZS1zbGlkZXMtYW5kLWRlbW9zLyZhbXA7dGl0bGU9U2FuK0RpZWdvKzIwMTIrUG93ZXJTaGVsbCtEZWVwK0RpdmUrU2xpZGVzK2FuZCtEZW1vcw==" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDUvc2FuLWRpZWdvLTIwMTItcG93ZXJzaGVsbC1kZWVwLWRpdmUtc2xpZGVzLWFuZC1kZW1vcy8mYW1wO3RpdGxlPVNhbitEaWVnbysyMDEyK1Bvd2VyU2hlbGwrRGVlcCtEaXZlK1NsaWRlcythbmQrRGVtb3M=" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA1L3Nhbi1kaWVnby0yMDEyLXBvd2Vyc2hlbGwtZGVlcC1kaXZlLXNsaWRlcy1hbmQtZGVtb3MvJmFtcDt0aXRsZT1TYW4rRGllZ28rMjAxMitQb3dlclNoZWxsK0RlZXArRGl2ZStTbGlkZXMrYW5kK0RlbW9z" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNS9zYW4tZGllZ28tMjAxMi1wb3dlcnNoZWxsLWRlZXAtZGl2ZS1zbGlkZXMtYW5kLWRlbW9zLw==" 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=2273" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/zQy67ZkIqVXsEcoE8KMtKEWVdBk/0/da"><img src="http://feedads.g.doubleclick.net/~a/zQy67ZkIqVXsEcoE8KMtKEWVdBk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/zQy67ZkIqVXsEcoE8KMtKEWVdBk/1/da"><img src="http://feedads.g.doubleclick.net/~a/zQy67ZkIqVXsEcoE8KMtKEWVdBk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/78lbqF9MLc8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/05/san-diego-2012-powershell-deep-dive-slides-and-demos/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/05/san-diego-2012-powershell-deep-dive-slides-and-demos/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=san-diego-2012-powershell-deep-dive-slides-and-demos</feedburner:origLink></item>
		<item>
		<title>Friday Fun: PowerShell Countdown</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/dzkK7PrZ68U/</link>
		<comments>http://jdhitsolutions.com/blog/2012/04/friday-fun-powershell-countdown/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 14:05:56 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2261</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, Josh Atwell posted a PowerShell script that performed a countdown. Naturally, I was inspired and did the whole &#8220;embrace and extend&#8221; thing. Don&#8217;t get me wrong: Josh&#8217;s script is perfectly fine. I saw some opportunities to try some things &#8230; <a href="http://jdhitsolutions.com/blog/2012/04/friday-fun-powershell-countdown/">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=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA0L2NvdW50ZG93bi5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/04/countdown-150x150.png" alt="" title="countdown" width="150" height="150" class="alignleft size-thumbnail wp-image-2262" /></a>Recently, <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy52dGVzc2VyYWN0LmNvbQ==" title=\"Visit Josh's blog\" target=\"_blank\">Josh Atwell</a> posted a PowerShell <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy52dGVzc2VyYWN0LmNvbS9wb3N0LzIxNDE0MjI3MTEzL3N0YXJ0LWNvdW50ZG93bi1mdW5jdGlvbi1hLXZpc3VhbC1mb3Itc3RhcnQtc2xlZXA=" title=\"Check out the original post\" target=\"_blank\">script </a>that performed a countdown. Naturally, I was inspired and did the whole &#8220;embrace and extend&#8221; thing. Don&#8217;t get me wrong: Josh&#8217;s script is perfectly fine. I saw some opportunities to try some things and use it as a teaching device. If nothing else, let&#8217;s have a little fun.</p>
<p>First off, here&#8217;s my version, then I&#8217;ll go over a few highlights.</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> Start<span style="color: pink;">-</span>Countdown <span style="color: #000000;">&#123;</span><br />
<span style="color: #008000;">&lt;#<br />
&nbsp;comment based help is in the download version<br />
#&gt;</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>HelpMessage<span style="color: pink;">=</span><span style="color: #800000;">&quot;Enter seconds to countdown from&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> <span style="color: #804000;">10</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>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$False</span><span style="color: pink;">,</span><br />
HelpMessage<span style="color: pink;">=</span><span style="color: #800000;">&quot;Enter a scriptblock to execute at the end of the countdown&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;">scriptblock</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Scriptblock</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #0000FF;">Switch</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$ProgressBar</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #0000FF;">Switch</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Clear</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">String</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Message</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;Blast Off!&quot;</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;">#save beginning value for total seconds</span><br />
<span style="color: #800080;">$TotalSeconds</span><span style="color: pink;">=</span><span style="color: #800080;">$Seconds</span><br />
<br />
<span style="color: #008000;">#get current cursor position</span><br />
<span style="color: #800080;">$Coordinate</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Management.Automation.Host.Coordinates<br />
<span style="color: #800080;">$Coordinate</span>.X<span style="color: pink;">=</span><span style="color: #800080;">$host</span>.ui.rawui.CursorPosition.X<br />
<span style="color: #800080;">$Coordinate</span>.Y<span style="color: pink;">=</span><span style="color: #800080;">$host</span>.ui.rawui.CursorPosition.Y<br />
<br />
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$clear</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Clear<span style="color: pink;">-</span>Host<br />
&nbsp; &nbsp; <span style="color: #008000;">#find the middle of the current window</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$Coordinate</span>.X<span style="color: pink;">=</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$host</span>.ui.rawui.WindowSize.Width<span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$Coordinate</span>.Y<span style="color: pink;">=</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$host</span>.ui.rawui.WindowSize.Height<span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008000;">#define the Escape key</span><br />
<span style="color: #800080;">$ESCKey</span> <span style="color: pink;">=</span> <span style="color: #804000;">27</span><br />
<br />
<span style="color: #008000;">#define a variable indicating if the user aborted the countdown</span><br />
<span style="color: #800080;">$Abort</span><span style="color: pink;">=</span><span style="color: #800080;">$False</span><br />
<br />
<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span> <span style="color: #FF0000;">-ge</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <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;">$host</span>.ui.RawUi.KeyAvailable<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$key</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.ui.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyUp,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$key</span>.VirtualKeyCode <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$ESCkey</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#ESC was pressed so quit the countdown and set abort flag to True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$Seconds</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$Abort</span><span style="color: pink;">=</span><span style="color: #800080;">$True</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000FF;">If</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ProgressBar</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#calculate percent time remaining, but in reverse so the progress bar</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#moves from left to right</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$percent</span><span style="color: pink;">=</span><span style="color: #804000;">100</span> <span style="color: pink;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span><span style="color: pink;">/</span><span style="color: #800080;">$TotalSeconds</span><span style="color: #000000;">&#41;</span><span style="color: pink;">*</span><span style="color: #804000;">100</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Progress</span> <span style="color: #008080; font-style: italic;">-Activity</span> <span style="color: #800000;">&quot;Countdown&quot;</span> <span style="color: #008080; font-style: italic;">-SecondsRemaining</span> <span style="color: #800080;">$Seconds</span> <span style="color: #008080; font-style: italic;">-Status</span> <span style="color: #800000;">&quot;Time Remaining&quot;</span> <span style="color: #008080; font-style: italic;">-PercentComplete</span> <span style="color: #800080;">$percent</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #804000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #0000FF;">Else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Clear</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Clear<span style="color: pink;">-</span>Host<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$host</span>.ui.rawui.CursorPosition<span style="color: pink;">=</span><span style="color: #800080;">$Coordinate</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#write the seconds with padded trailing spaces to overwrite any extra digits such</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#as moving from 10 to 9</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$pad</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$TotalSeconds</span> <span style="color: #FF0000;">-as</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>.Length<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span> <span style="color: #FF0000;">-le</span> <span style="color: #804000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$color</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Red&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; &nbsp; <span style="color: #800080;">$color</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Green&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-Host</span> <span style="color: #800000;">&quot;$(([string]$Seconds).Padright($pad))&quot;</span> <span style="color: #008080; font-style: italic;">-foregroundcolor</span> <span style="color: #800080;">$color</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #804000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#decrement $Seconds</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$Seconds</span><span style="color: pink;">--</span><br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#while</span><br />
<br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">-Not</span> <span style="color: #800080;">$Abort</span><span style="color: #000000;">&#41;</span> <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;">$clear</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#if $Clear was used, center the message in the console</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$Coordinate</span>.X<span style="color: pink;">=</span><span style="color: #800080;">$Coordinate</span>.X <span style="color: pink;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$message</span>.Length<span style="color: #000000;">&#41;</span><span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #800080;">$host</span>.ui.rawui.CursorPosition<span style="color: pink;">=</span><span style="color: #800080;">$Coordinate</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$Message</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green<br />
&nbsp; &nbsp; <span style="color: #008000;">#run the scriptblock if specified</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$scriptblock</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Invoke<span style="color: pink;">-</span>Command <span style="color: pink;">-</span>ScriptBlock <span style="color: #800080;">$Scriptblock</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #800000;">&quot;Countdown aborted&quot;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#end function</span></div></div>
<p>The basic premise hasn&#8217;t really changed. Run the function specifying the number of seconds to count down and at the end of the countdown display a message. I thought why not really do something? So I added an optional Scriptblock parameter. At the end of the countdown, it will be executed using Invoke-Command.</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: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$scriptblock</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; Invoke<span style="color: pink;">-</span>Command <span style="color: pink;">-</span>ScriptBlock <span style="color: #800080;">$Scriptblock</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>Next, I decided to add a way to abort the countdown. If you run the function in the ISE and use the Progress bar parameter, you can click the Stop button. In the console, you could press Ctrl+C but that seemed a little heavy handed to me so I inserted code to watch for a key press, specifically the ESC key. If the key press is detected, I set a flag variable to False and the seconds to 0 to break out of the While loop.</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 the Escape key</span><br />
<span style="color: #800080;">$ESCKey</span> <span style="color: pink;">=</span> <span style="color: #804000;">27</span><br />
<br />
<span style="color: #008000;">#define a variable indicating if the user aborted the countdown</span><br />
<span style="color: #800080;">$Abort</span><span style="color: pink;">=</span><span style="color: #800080;">$False</span><br />
<br />
<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span> <span style="color: #FF0000;">-ge</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span> <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;">$host</span>.ui.RawUi.KeyAvailable<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$key</span> <span style="color: pink;">=</span> <span style="color: #800080;">$host</span>.ui.RawUI.ReadKey<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;NoEcho,IncludeKeyUp,IncludeKeyDown&quot;</span><span style="color: #000000;">&#41;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$key</span>.VirtualKeyCode <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$ESCkey</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#ESC was pressed so quit the countdown and set abort flag to True</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$Seconds</span> <span style="color: pink;">=</span> <span style="color: #804000;">0</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$Abort</span><span style="color: pink;">=</span><span style="color: #800080;">$True</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
...</div></div>
<p>After the loop I inserted commands to check if the countdown was aborted or not. If not, then I display the message and run the scriptblock, if supplied.</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: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">-Not</span> <span style="color: #800080;">$Abort</span><span style="color: #000000;">&#41;</span> <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;">$clear</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#if $Clear was used, center the message in the console</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$Coordinate</span>.X<span style="color: pink;">=</span><span style="color: #800080;">$Coordinate</span>.X <span style="color: pink;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$message</span>.Length<span style="color: #000000;">&#41;</span><span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #800080;">$host</span>.ui.rawui.CursorPosition<span style="color: pink;">=</span><span style="color: #800080;">$Coordinate</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$Message</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Green<br />
&nbsp; &nbsp; <span style="color: #008000;">#run the scriptblock if specified</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$scriptblock</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; Invoke<span style="color: pink;">-</span>Command <span style="color: pink;">-</span>ScriptBlock <span style="color: #800080;">$Scriptblock</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #800000;">&quot;Countdown aborted&quot;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>I like the use of Write-Progress. I don&#8217;t think it gets enough attention. I decided to add in the progress bar which is incremented based on a percentage of how much time is to go.</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;">$percent</span><span style="color: pink;">=</span><span style="color: #804000;">100</span> <span style="color: pink;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span><span style="color: pink;">/</span><span style="color: #800080;">$TotalSeconds</span><span style="color: #000000;">&#41;</span><span style="color: pink;">*</span><span style="color: #804000;">100</span><br />
<span style="color: #008080; font-weight: bold;">Write-Progress</span> <span style="color: #008080; font-style: italic;">-Activity</span> <span style="color: #800000;">&quot;Countdown&quot;</span> <span style="color: #008080; font-style: italic;">-SecondsRemaining</span> <span style="color: #800080;">$Seconds</span> <span style="color: #008080; font-style: italic;">-Status</span> <span style="color: #800000;">&quot;Time Remaining&quot;</span> <span style="color: #008080; font-style: italic;">-PercentComplete</span> $percent</div></div>
<p>I&#8217;m subtracting the percent value from 100 so that the progress bar moves from left to right. It looked odd to me to move from &#8220;Full&#8221; to &#8220;Empty&#8221;, although I suppose for a countdown that is more accurate. You can switch this back.</p>
<p>My last change is how the countdown is handled in the console, if you don&#8217;t use the progress bar. In Josh&#8217;s version he cleared the screen and then wrote the current time, clearing the screen each time. The effect is you see the number change in the upper left corner of the console. But what if you don&#8217;t want to clear the screen? Writing the number will use a new line for each value. Using Write-Host with -NoNewLine will simply append to the current line and look ugly. So I decided to have some fun with raw host data.</p>
<p>First, I grab the coordinates of the cursor&#8217;s current position using the RawUI property from $host.</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;">#get current cursor position</span><br />
<span style="color: #800080;">$Coordinate</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">New-Object</span> System.Management.Automation.Host.Coordinates<br />
<span style="color: #800080;">$Coordinate</span>.X<span style="color: pink;">=</span><span style="color: #800080;">$host</span>.ui.rawui.CursorPosition.X<br />
<span style="color: #800080;">$Coordinate</span>.Y<span style="color: pink;">=</span><span style="color: #800080;">$host</span>.ui.rawui.CursorPosition.Y</div></div>
<p>I want this because I can use the coordinates to put the cursor to a specific location in the console.</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">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#write the seconds with padded trailing spaces to overwrite any extra digits such</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#as moving from 10 to 9</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$pad</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$TotalSeconds</span> <span style="color: #FF0000;">-as</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>.Length<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span> <span style="color: #FF0000;">-le</span> <span style="color: #804000;">10</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$color</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Red&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; &nbsp; <span style="color: #800080;">$color</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Green&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-Host</span> <span style="color: #800000;">&quot;$(([string]$Seconds).Padright($pad))&quot;</span> <span style="color: #008080; font-style: italic;">-foregroundcolor</span> <span style="color: #800080;">$color</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-Seconds</span> <span style="color: #804000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></div>
<p>I also added code and logic so that the number is displayed in Green using Write-Host until it reaches 10, at which point it is written to the console in red.</p>
<p>I also use the coordinates for some fun if you use -Clear. I put the countdown timer in the center of the console window. In order to do that I had to find the dimensions of the window and divide by 2, treating each value as an [INT].</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;">#find the middle of the current window</span><br />
<span style="color: #800080;">$Coordinate</span>.X<span style="color: pink;">=</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$host</span>.ui.rawui.WindowSize.Width<span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #800080;">$Coordinate</span>.Y<span style="color: pink;">=</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$host</span>.ui.rawui.WindowSize.Height<span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span></div></div>
<p>Finally, I decided to also center the message. This meant figuring out the message length and then adjusting the X coordinate.</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: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$clear</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #008000;">#if $Clear was used, center the message in the console</span><br />
&nbsp; &nbsp;<span style="color: #800080;">$Coordinate</span>.X<span style="color: pink;">=</span><span style="color: #800080;">$Coordinate</span>.X <span style="color: pink;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$message</span>.Length<span style="color: #000000;">&#41;</span><span style="color: pink;">/</span><span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #800080;">$host</span>.ui.rawui.CursorPosition<span style="color: pink;">=</span>$Coordinate</div></div>
<p>Curious to see what this looks like? (the clip has no audio)</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/WxwsbpNWAow" frameborder="0" allowfullscreen></iframe></p>
<p>You can download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA0L0NvdW50ZG93bjIudHh0" target='_blank'>Countdown2</a> and load the Start-Countdown function into your PowerShell session. Be sure to read the help.</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4lM0ErUG93ZXJTaGVsbCtDb3VudGRvd24raHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDQlMkZmcmlkYXktZnVuLXBvd2Vyc2hlbGwtY291bnRkb3duJTJG" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L2ZyaWRheS1mdW4tcG93ZXJzaGVsbC1jb3VudGRvd24vJmFtcDtoZWFkbGluZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrQ291bnRkb3du" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWNvdW50ZG93bi8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErUG93ZXJTaGVsbCtDb3VudGRvd24=" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWNvdW50ZG93bi8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErUG93ZXJTaGVsbCtDb3VudGRvd24=" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWNvdW50ZG93bi8mYW1wO3Q9RnJpZGF5K0Z1biUzQStQb3dlclNoZWxsK0NvdW50ZG93bg==" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrQ291bnRkb3duJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L2ZyaWRheS1mdW4tcG93ZXJzaGVsbC1jb3VudGRvd24v" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWNvdW50ZG93bi8mYW1wO2ltYWdldXJsPQ==" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrQ291bnRkb3duJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L2ZyaWRheS1mdW4tcG93ZXJzaGVsbC1jb3VudGRvd24v" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9mcmlkYXktZnVuLXBvd2Vyc2hlbGwtY291bnRkb3duLyZhbXA7dGl0bGU9RnJpZGF5K0Z1biUzQStQb3dlclNoZWxsK0NvdW50ZG93bg==" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZnJpZGF5LWZ1bi1wb3dlcnNoZWxsLWNvdW50ZG93bi8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErUG93ZXJTaGVsbCtDb3VudGRvd24=" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L2ZyaWRheS1mdW4tcG93ZXJzaGVsbC1jb3VudGRvd24vJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK1Bvd2VyU2hlbGwrQ291bnRkb3du" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9mcmlkYXktZnVuLXBvd2Vyc2hlbGwtY291bnRkb3duLw==" 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=2261" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/PapkG9qvNpeNpk_NMWe0uqHiqJo/0/da"><img src="http://feedads.g.doubleclick.net/~a/PapkG9qvNpeNpk_NMWe0uqHiqJo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/PapkG9qvNpeNpk_NMWe0uqHiqJo/1/da"><img src="http://feedads.g.doubleclick.net/~a/PapkG9qvNpeNpk_NMWe0uqHiqJo/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/dzkK7PrZ68U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/04/friday-fun-powershell-countdown/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/04/friday-fun-powershell-countdown/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-powershell-countdown</feedburner:origLink></item>
		<item>
		<title>FZ8D4JAWU7Q3</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/TqtNPKOHI4E/</link>
		<comments>http://jdhitsolutions.com/blog/2012/04/fz8d4jawu7q3/#comments</comments>
		<pubDate>Fri, 27 Apr 2012 11:07:46 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2258</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>
claim post. Nothing to see here.]]></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>claim post. Nothing to see here.</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZaOEQ0SkFXVTdRMytodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwNCUyRmZ6OGQ0amF3dTdxMyUyRg==" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L2Z6OGQ0amF3dTdxMy8mYW1wO2hlYWRsaW5lPUZaOEQ0SkFXVTdRMw==" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZno4ZDRqYXd1N3EzLyZhbXA7dGl0bGU9Rlo4RDRKQVdVN1Ez" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZno4ZDRqYXd1N3EzLyZhbXA7dGl0bGU9Rlo4RDRKQVdVN1Ez" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZno4ZDRqYXd1N3EzLyZhbXA7dD1GWjhENEpBV1U3UTM=" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GWjhENEpBV1U3UTMmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZno4ZDRqYXd1N3EzLw==" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZno4ZDRqYXd1N3EzLyZhbXA7aW1hZ2V1cmw9" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GWjhENEpBV1U3UTMmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZno4ZDRqYXd1N3EzLw==" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9mejhkNGphd3U3cTMvJmFtcDt0aXRsZT1GWjhENEpBV1U3UTM=" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvZno4ZDRqYXd1N3EzLyZhbXA7dGl0bGU9Rlo4RDRKQVdVN1Ez" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L2Z6OGQ0amF3dTdxMy8mYW1wO3RpdGxlPUZaOEQ0SkFXVTdRMw==" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9mejhkNGphd3U3cTMv" 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=2258" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/iPfCYQBIdiuNfSxKRMxX9HWjroo/0/da"><img src="http://feedads.g.doubleclick.net/~a/iPfCYQBIdiuNfSxKRMxX9HWjroo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iPfCYQBIdiuNfSxKRMxX9HWjroo/1/da"><img src="http://feedads.g.doubleclick.net/~a/iPfCYQBIdiuNfSxKRMxX9HWjroo/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/TqtNPKOHI4E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/04/fz8d4jawu7q3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/04/fz8d4jawu7q3/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=fz8d4jawu7q3</feedburner:origLink></item>
		<item>
		<title>PowerShell Scripting with [ValidateCount]</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/dXn9I5Pzv_8/</link>
		<comments>http://jdhitsolutions.com/blog/2012/04/powershell-scripting-with-validatecount/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 13:38:41 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[parameter]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2247</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>
Here&#8217;s another parameter validation attribute you might want to use in your PowerShell scripting and functions. If your parameter can take an array of values, you might want to limit that array to a certain size. For example, your parameter &#8230; <a href="http://jdhitsolutions.com/blog/2012/04/powershell-scripting-with-validatecount/">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>Here&#8217;s another parameter validation attribute you might want to use in your PowerShell scripting and functions. If your parameter can take an array of values, you might want to limit that array to a certain size. For example, your parameter can take an array of computer names but you don&#8217;t want to process more than 5 for some reason. This is where [ValidateCount()] comes in to play. </p>
<p>This attribute takes two values, the minimum number of accepted parameter values and the maximum.</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: #000000;">&#91;</span>ValidateCount<span style="color: #000000;">&#40;</span><span style="color: #804000;">1</span><span style="color: pink;">,</span><span style="color: #804000;">10</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>$Computername</div></div>
<p>If used, this would mean I would need at least one computername but no more than 10. You could also set both values the same if you wanted an exact number:</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: #000000;">&#91;</span>ValidateCount<span style="color: #000000;">&#40;</span><span style="color: #804000;">2</span><span style="color: pink;">,</span><span style="color: #804000;">2</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;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span>$Numbers</div></div>
<p>Now, I&#8217;d have to pass exactly 2 numbers as parameter values. Let&#8217;s look at a more complete example.</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: #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: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateCount<span style="color: #000000;">&#40;</span><span style="color: #804000;">1</span><span style="color: pink;">,</span><span style="color: #804000;">5</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;">$Name</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
<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;">$name</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">#display the name in a random color</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$item</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span>system.consoleColor<span style="color: #000000;">&#93;</span>::GetValues<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;system.consolecolor&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> get<span style="color: pink;">-</span>random<span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #000000;">&#125;</span></div></div>
<p>This simple script writes each name in a random color, assuming I pass no more than 5 names.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA0L3ZhbGlkYXRlY291bnQtb2sucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/04/validatecount-ok-300x66.png" alt="" title="validatecount-ok" width="300" height="66" class="aligncenter size-medium wp-image-2248" /></a></p>
<p>If I exceed that count, PowerShell will throw a tantrum (I mean exception).</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA0L3ZhbGlkYXRlY291bnQtZXJyb3IucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/04/validatecount-error-300x125.png" alt="" title="validatecount-error" width="300" height="125" class="aligncenter size-medium wp-image-2249" /></a></p>
<p>When you use this validation test, be sure your parameter is set to accept an array of values, e.g. [string[]]. If you&#8217;d like to try out my sample code feel free to download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA0L0RlbW8tVmFsaWRhdGVDb3VudC50eHQ=" target='_blank'>Demo-ValidateCount</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVBvd2VyU2hlbGwrU2NyaXB0aW5nK3dpdGgrJTVCVmFsaWRhdGVDb3VudCU1RCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwNCUyRnBvd2Vyc2hlbGwtc2NyaXB0aW5nLXdpdGgtdmFsaWRhdGVjb3VudCUyRg==" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L3Bvd2Vyc2hlbGwtc2NyaXB0aW5nLXdpdGgtdmFsaWRhdGVjb3VudC8mYW1wO2hlYWRsaW5lPVBvd2VyU2hlbGwrU2NyaXB0aW5nK3dpdGgrJTVCVmFsaWRhdGVDb3VudCU1RA==" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZWNvdW50LyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtTY3JpcHRpbmcrd2l0aCslNUJWYWxpZGF0ZUNvdW50JTVE" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZWNvdW50LyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtTY3JpcHRpbmcrd2l0aCslNUJWYWxpZGF0ZUNvdW50JTVE" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZWNvdW50LyZhbXA7dD1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlQ291bnQlNUQ=" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlQ291bnQlNUQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZWNvdW50Lw==" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZWNvdW50LyZhbXA7aW1hZ2V1cmw9" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlQ291bnQlNUQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZWNvdW50Lw==" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9wb3dlcnNoZWxsLXNjcmlwdGluZy13aXRoLXZhbGlkYXRlY291bnQvJmFtcDt0aXRsZT1Qb3dlclNoZWxsK1NjcmlwdGluZyt3aXRoKyU1QlZhbGlkYXRlQ291bnQlNUQ=" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvcG93ZXJzaGVsbC1zY3JpcHRpbmctd2l0aC12YWxpZGF0ZWNvdW50LyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtTY3JpcHRpbmcrd2l0aCslNUJWYWxpZGF0ZUNvdW50JTVE" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L3Bvd2Vyc2hlbGwtc2NyaXB0aW5nLXdpdGgtdmFsaWRhdGVjb3VudC8mYW1wO3RpdGxlPVBvd2VyU2hlbGwrU2NyaXB0aW5nK3dpdGgrJTVCVmFsaWRhdGVDb3VudCU1RA==" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9wb3dlcnNoZWxsLXNjcmlwdGluZy13aXRoLXZhbGlkYXRlY291bnQv" 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=2247" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/Ppa-__n5jedDOV5nyK7rpSnsKJs/0/da"><img src="http://feedads.g.doubleclick.net/~a/Ppa-__n5jedDOV5nyK7rpSnsKJs/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Ppa-__n5jedDOV5nyK7rpSnsKJs/1/da"><img src="http://feedads.g.doubleclick.net/~a/Ppa-__n5jedDOV5nyK7rpSnsKJs/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/dXn9I5Pzv_8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/04/powershell-scripting-with-validatecount/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/04/powershell-scripting-with-validatecount/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-scripting-with-validatecount</feedburner:origLink></item>
		<item>
		<title>Skipping WMI System Properties in PowerShell</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/28_r8KMJopw/</link>
		<comments>http://jdhitsolutions.com/blog/2012/04/skipping-wmi-system-properties-in-powershell/#comments</comments>
		<pubDate>Wed, 25 Apr 2012 13:15:06 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[Get-WMIObject]]></category>
		<category><![CDATA[ScriptBlock]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2241</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>
One of my favorite techniques when using WMI in PowerShell is to pipe an object to Select-Object and select all properties. Try this: get-wmiobject win32_bios &#124; select * It works, but it also gets all of the system properties like &#8230; <a href="http://jdhitsolutions.com/blog/2012/04/skipping-wmi-system-properties-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>One of my favorite techniques when using WMI in PowerShell is to pipe an object to Select-Object and select all properties. Try 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;">get-wmiobject</span> win32_bios <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> <span style="color: pink;">*</span></div></div>
<p>It works, but it also gets all of the system properties like __PATH which I rarely care about. I also get other properties like Site and Options which I typically don&#8217;t need. So here are some techniques you can use to view all WMI properties that probably matter most. Let&#8217;s begin with a typical command:</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;">$os</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">get-wmiobject</span> Win32_OperatingSystem</div></div>
<p>This object has a property called Properties which is a collection of WMI PropertyData objects. I could try something like:</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> $os.properties <span style="color: #33cc33;">|</span> select name,value<br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &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; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-----<br />
BootDevice &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\Device\HarddiskVolume1<br />
BuildNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 7601<br />
BuildType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Multiprocessor Free<br />
Caption &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Microsoft Windows 7 Ultimate<br />
CodeSet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1252<br />
CountryCode &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br />
...</div></div>
<p>Sure, I can see the properties and values but I don&#8217;t really have a good object to work with and this won&#8217;t help with multiple instances, at least not without a little extra work.</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;">$d</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> win32_logicaldisk <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #800000;">&quot;drivetype=3&quot;</span><br />
<span style="color: #800080;">$d</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> name<span style="color: pink;">,</span>value <span style="color: #000000;">&#125;</span></div></div>
<p>And maybe that&#8217;s all you need. If so, terrific. But I&#8217;m looking for an elegant solution. How about expanding the property names and saving them as an array of strings.</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: #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;">$prop</span><span style="color: pink;">=</span><span style="color: #800080;">$os</span>.properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-expand</span> name<br />
<span style="color: #800080;">$os</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-Property</span> $prop</div></div>
<p>Then I can use them with Select-Object</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> $os <span style="color: #33cc33;">|</span> Select -Property $prop<br />
<br />
PS C:\<span style="color: #33cc33;">&gt;</span> $os <span style="color: #33cc33;">|</span> Select -Property $prop<br />
<br />
<br />
BootDevice &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: <span style="color: #b100b1; font-weight: bold;">\Device\HarddiskVolume1</span><br />
BuildNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">7601</span><br />
BuildType &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">Multiprocessor</span> Free<br />
Caption &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">Microsoft</span> Windows 7 Ultimate<br />
CodeSet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">1252</span><br />
CountryCode &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">1</span><br />
...</div></div>
<p>That has promise. I could even turn this into a one-line command, assuming I&#8217;ve already defined $os.</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;">$os</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-property</span> <span style="color: #000000;">&#40;</span><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: #000000;">&#40;</span><span style="color: #800080;">$os</span>.properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-expand</span> name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></div></div>
<p>If I didn&#8217;t want to take the extra step, here&#8217;s a complex alternative:</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;">Get-WmiObject</span> win32_OperatingSystem <span style="color: pink;">|</span> <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp;<span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-InputObject</span> <span style="color: #000080;">$_</span> <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: #000000;">&#40;</span><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: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-InputObject</span> <span style="color: #000080;">$_</span> <span style="color: #008080; font-style: italic;">-expand</span> Properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-expand</span> Name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>But this leads to yet another option, using the [WMIClass] type accelerator. When used, PowerShell creates an empty object of the specified WMI class which includes a property list.</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> [wmiclass]&quot;win32_operatingsystem&quot; <span style="color: #33cc33;">|</span> Select -expand Properties <span style="color: #33cc33;">|</span> Select name<br />
<br />
Name<br />
----<br />
BootDevice<br />
BuildNumber<br />
BuildType<br />
Caption<br />
CodeSet<br />
CountryCode<br />
...</div></div>
<p>This can be further simplified:</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: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmiclass</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;win32_operatingsystem&quot;</span><span style="color: #000000;">&#41;</span>.Properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: #008080; font-style: italic;">-expand</span> Name</div></div>
<p>In fact, I can use this in an earlier expression to get the same non-System class results.</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;">get-wmiobject</span> win32_operatingsystem <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> <span style="color: #008080; font-style: italic;">-property</span> <span style="color: #000000;">&#40;</span><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: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmiclass</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;Win32_Operatingsystem&quot;</span><span style="color: #000000;">&#41;</span>.properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> <span style="color: #008080; font-style: italic;">-expand</span> name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span></div></div>
<p>I&#8217;ll admit that&#8217;s a lot to type. So I need a shortcut. What about turning this into a scriptblock?</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;">$p</span><span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><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: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmiclass</span><span style="color: #000000;">&#93;</span><span style="color: #800000;">&quot;Win32_Operatingsystem&quot;</span><span style="color: #000000;">&#41;</span>.properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> <span style="color: #008080; font-style: italic;">-expand</span> name<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span></div></div>
<p>When I invoke the scriptblock, I&#8217;ll get the array of property names. I can now use this in my Get-WMIObject expression:</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;">get-wmiobject</span> win32_operatingsystem <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> <span style="color: #008080; font-style: italic;">-property</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">&amp;</span><span style="color: #800080;">$p</span><span style="color: #000000;">&#41;</span></div></div>
<p>Definitely easier to type, but limited. I need the scriptblock to be more flexible so it can accommodate other WMI classes.</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;">$p</span><span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #0000FF;">Param</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$class</span><span style="color: #000000;">&#41;</span> <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: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#91;</span><span style="color: #008080;">wmiclass</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$class</span><span style="color: #000000;">&#41;</span>.properties <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> <span style="color: #008080; font-style: italic;">-expand</span> name<span style="color: #000000;">&#41;</span> &nbsp;<span style="color: #000000;">&#125;</span></div></div>
<p>I&#8217;ll test it in the shell.</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> <span style="color: #33cc33;">&amp;</span>$p &quot;win32_bios&quot;<br />
BiosCharacteristics<br />
BIOSVersion<br />
BuildNumber<br />
Caption<br />
CodeSet<br />
CurrentLanguage<br />
...</div></div>
<p>Excellent! Now for the real deal:</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> get-wmiobject win32_bios <span style="color: #33cc33;">|</span> select -property <span style="color: #33cc33;">(&amp;</span>$p &quot;win32_bios&quot;<span style="color: #33cc33;">)</span><br />
<br />
<br />
BiosCharacteristics &nbsp; : <span style="color: #b100b1; font-weight: bold;">{4,</span> 7, 8, 9...}<br />
BIOSVersion &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">{TOSQCI</span> - 6040000, Ver 1.00PARTTBL}<br />
BuildNumber &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :<br />
Caption &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">Ver</span> 1.00PARTTBL<br />
CodeSet &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; :<br />
CurrentLanguage &nbsp; &nbsp; &nbsp; :<br />
Description &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; : <span style="color: #b100b1; font-weight: bold;">Ver</span> 1.00PARTTBL<br />
...</div></div>
<p>That&#8217;s exactly what I wanted with minimal effort. All I need is to have that scriptblock loaded in my PowerShell session and remember to specify the class name.</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;">get-wmiobject</span> win32_logicaldisk <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #800000;">&quot;drivetype=3&quot;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> <span style="color: #008080; font-style: italic;">-property</span> <span style="color: #000000;">&#40;</span><span style="color: pink;">&amp;</span><span style="color: #800080;">$p</span> <span style="color: #800000;">&quot;win32_logicaldisk&quot;</span><span style="color: #000000;">&#41;</span></div></div>
<p>Another option would be to turn the scriptblock into a function, but I&#8217;ll leave that to you.</p>
<p>Naturally this isn&#8217;t perfect. If I need to query a remote computer with classes that aren&#8217;t on my computer, this won&#8217;t work; at least not without some revisions. But since I&#8217;d say 90% or more of WMI commands in PowerShell are with the Win32 classes, I think this is a handy trick to stick in your PowerShell toolbox.</p>
<p>If you&#8217;d like to try some of my code samples, you can download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzA0L2RlbW8td21pcHJvcGVydGllcy50eHQ=" target='_blank'>demo-wmiproperties</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVNraXBwaW5nK1dNSStTeXN0ZW0rUHJvcGVydGllcytpbitQb3dlclNoZWxsK2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjA0JTJGc2tpcHBpbmctd21pLXN5c3RlbS1wcm9wZXJ0aWVzLWluLXBvd2Vyc2hlbGwlMkY=" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L3NraXBwaW5nLXdtaS1zeXN0ZW0tcHJvcGVydGllcy1pbi1wb3dlcnNoZWxsLyZhbXA7aGVhZGxpbmU9U2tpcHBpbmcrV01JK1N5c3RlbStQcm9wZXJ0aWVzK2luK1Bvd2VyU2hlbGw=" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvc2tpcHBpbmctd21pLXN5c3RlbS1wcm9wZXJ0aWVzLWluLXBvd2Vyc2hlbGwvJmFtcDt0aXRsZT1Ta2lwcGluZytXTUkrU3lzdGVtK1Byb3BlcnRpZXMraW4rUG93ZXJTaGVsbA==" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvc2tpcHBpbmctd21pLXN5c3RlbS1wcm9wZXJ0aWVzLWluLXBvd2Vyc2hlbGwvJmFtcDt0aXRsZT1Ta2lwcGluZytXTUkrU3lzdGVtK1Byb3BlcnRpZXMraW4rUG93ZXJTaGVsbA==" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvc2tpcHBpbmctd21pLXN5c3RlbS1wcm9wZXJ0aWVzLWluLXBvd2Vyc2hlbGwvJmFtcDt0PVNraXBwaW5nK1dNSStTeXN0ZW0rUHJvcGVydGllcytpbitQb3dlclNoZWxs" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Ta2lwcGluZytXTUkrU3lzdGVtK1Byb3BlcnRpZXMraW4rUG93ZXJTaGVsbCZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9za2lwcGluZy13bWktc3lzdGVtLXByb3BlcnRpZXMtaW4tcG93ZXJzaGVsbC8=" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvc2tpcHBpbmctd21pLXN5c3RlbS1wcm9wZXJ0aWVzLWluLXBvd2Vyc2hlbGwvJmFtcDtpbWFnZXVybD0=" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Ta2lwcGluZytXTUkrU3lzdGVtK1Byb3BlcnRpZXMraW4rUG93ZXJTaGVsbCZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9za2lwcGluZy13bWktc3lzdGVtLXByb3BlcnRpZXMtaW4tcG93ZXJzaGVsbC8=" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9za2lwcGluZy13bWktc3lzdGVtLXByb3BlcnRpZXMtaW4tcG93ZXJzaGVsbC8mYW1wO3RpdGxlPVNraXBwaW5nK1dNSStTeXN0ZW0rUHJvcGVydGllcytpbitQb3dlclNoZWxs" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDQvc2tpcHBpbmctd21pLXN5c3RlbS1wcm9wZXJ0aWVzLWluLXBvd2Vyc2hlbGwvJmFtcDt0aXRsZT1Ta2lwcGluZytXTUkrU3lzdGVtK1Byb3BlcnRpZXMraW4rUG93ZXJTaGVsbA==" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzA0L3NraXBwaW5nLXdtaS1zeXN0ZW0tcHJvcGVydGllcy1pbi1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9U2tpcHBpbmcrV01JK1N5c3RlbStQcm9wZXJ0aWVzK2luK1Bvd2VyU2hlbGw=" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wNC9za2lwcGluZy13bWktc3lzdGVtLXByb3BlcnRpZXMtaW4tcG93ZXJzaGVsbC8=" 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=2241" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/o3zQTBBmzjbQkjiKI0EoNVpS3nk/0/da"><img src="http://feedads.g.doubleclick.net/~a/o3zQTBBmzjbQkjiKI0EoNVpS3nk/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/o3zQTBBmzjbQkjiKI0EoNVpS3nk/1/da"><img src="http://feedads.g.doubleclick.net/~a/o3zQTBBmzjbQkjiKI0EoNVpS3nk/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/28_r8KMJopw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/04/skipping-wmi-system-properties-in-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/04/skipping-wmi-system-properties-in-powershell/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=skipping-wmi-system-properties-in-powershell</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 4.675 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-05-17 06:26:38 -->

