<?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>Tue, 31 Jan 2012 15:54:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/JeffsScriptingBlogAndMore" /><feedburner:info uri="jeffsscriptingblogandmore" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Maximizing the PowerShell Console Title Bar</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/q8YGpeBt1PE/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 15:54:46 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[eventsubscriber]]></category>
		<category><![CDATA[module]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Register-ObjectEvent]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2044</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
A few days ago Boe Prox posted some very nifty PowerShell modules for using the title bar as a ticker for RSS feeds like the weather. I thought this was an awesome idea and an easy way to take advantage &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>A few days ago <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL3Byb3hi" title=\"Follow on Twitter\" target=\"_blank\">Boe Prox</a> posted some very nifty PowerShell modules for using the <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2xlYXJuLXBvd2Vyc2hlbGwubmV0LzIwMTIvMDEvMjgvdHVybi15b3VyLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXItaW50by1hLXJzc3dlYXRoZXItdGlja2VyLw==" title=\"Read his blog\" target=\"_blank\">title bar as a ticker</a> for RSS feeds like the weather. I thought this was an awesome idea and an easy way to take advantage of what would otherwise be unused screen space. I was especially intrigued with his use of timer objects and event subscriptions to manage the updating.</p>
<p>Naturally I decided to run with this. My main goal was to take Boe&#8217;s fundamental idea and turn it into something more re-usable or extensible.  My result is a module called ConsoleTitle.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-command -Module ConsoleTitle | Select Name<br />
<br />
Name<br />
----<br />
Get-Inspiration<br />
Get-SystemStat<br />
Get-Timer<br />
New-Timer<br />
Remove-Timer<br />
Set-ConsoleTitle<br />
Set-TimerInterval<br />
Start-TitleTimer</div></div>
<p>The overall premise is pretty simple, define a global variable $PSConsoleTitle and use a timer to periodically update the console title bar with this value. During the refresh interval you can run whatever code you like, however you like, to provide a new value to the variable. In the module I&#8217;ve included two sample commands, Get-SystemStat and Get-Inspiration. The former uses WMI to gather system information from the local computer.<br />
<a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2NvbnNvbGUtdGl0bGUtc3lzc3RhdC5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/console-title-sysstat-300x85.png" alt="" title="System Status Title Bar" width="300" height="85" class="aligncenter size-medium wp-image-2045" /></a></p>
<p>The other command defines an array of slogans, sayings and suggestions and randomly selects one to use as the title bar text.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2NvbnNvbGUtdGl0bGUyLnBuZyN1dG1fc291cmNlPWZlZWQmYW1wO3V0bV9tZWRpdW09ZmVlZCZhbXA7dXRtX2NhbXBhaWduPWZlZWQ="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/console-title2-300x197.png" alt="" title="Inspiring Titles" width="300" height="197" class="aligncenter size-medium wp-image-2046" /></a></p>
<p>The module includes a few commands for working with timer objects. You can use New-Timer in your own scripts.  Here&#8217;s the function.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Function New-Timer {<br />
<br />
&lt;#<br />
.Synopsis<br />
Create an event timer object<br />
.Description<br />
Create an event timer object, primarily to be used by the ConsoleTitle module.<br />
Each timer job will automatically be added to the global variable, $ConsoleTitleEvents<br />
unless you use the -NoAdd parameter. This variable is used by Remove-Timer to clear<br />
console title related timers.<br />
<br />
This function is called from within other module functions but you can use it to <br />
create non-module timers.<br />
<br />
.Parameter Identifier<br />
A source identifier for your timer<br />
.Parameter Refresh<br />
The timer interval in Seconds. The default is 300 (5 minutes). Minimum<br />
value is 5 seconds.<br />
.Parameter Action<br />
The scriptblock to execute when the timer runs down.<br />
.Parameter NoAdd<br />
Don't add the timer object to the $ConsoleTitleEvents global variable.<br />
#&gt;<br />
<br />
Param(<br />
[Parameter(Position=0,Mandatory=$True,HelpMessage=&quot;Enter a source identifier for your timer&quot;)]<br />
[ValidateNotNullorEmpty()]<br />
[string]$Identifier,<br />
[Parameter(Position=1)]<br />
[validatescript({$_ -ge 5})]<br />
[int]$Refresh=300,<br />
[Parameter(Position=2,Mandatory=$True,HelpMessage=&quot;Enter an action scriptblock&quot;)]<br />
[scriptblock]$Action,<br />
[switch]$NoAdd<br />
)<br />
<br />
Write-Verbose (&quot;Creating a timer called {0} to refresh every {1} seconds.&quot; -f $Identifier,$Refresh)<br />
<br />
#create a timer object<br />
$timer = new-object timers.timer<br />
#timer interval is in milliseconds<br />
$timer.Interval = $Refresh*1000<br />
$timer.Enabled=$True<br />
<br />
#create the event subscription and add to the global variable<br />
$evt=Register-ObjectEvent -InputObject $timer -EventName elapsed –SourceIdentifier &nbsp;$Identifier &nbsp;-Action $Action <br />
<br />
if (-Not $NoAdd) {<br />
&nbsp; &nbsp; #add the event to a global variable to track all events<br />
&nbsp; &nbsp; $global:ConsoleTitleEvents+=$evt<br />
}<br />
#start the timer &nbsp; &nbsp;<br />
$timer.Start() <br />
<br />
} #Function</div></div>
<p>And here&#8217;s how you might use it.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Function Get-Inspiration {<br />
<br />
Param(<br />
[Parameter(Position=0)]<br />
[ValidateScript({$_ -ge 5})]<br />
[int]$Refresh=600<br />
)<br />
<br />
#Define an array of pithy sayings, slogans and quotes<br />
<br />
#we'll create as a globally scoped variable so you can add to it anytime you want from PowerShell<br />
$global:slogans=@(<br />
&quot;PowerShell Rocks!&quot;,<br />
&quot;Energize!!&quot;,<br />
&quot;To Shell and Back&quot;,<br />
&quot;I am the Shell&quot;,<br />
&quot;PowerShell to the People&quot;,<br />
&quot;Powered by PS&quot;,<br />
&quot;PowerShell Rulez!&quot;,<br />
&quot;PowerShell Fanboy&quot;,<br />
&quot;I am the walrus&quot;,<br />
&quot;Those who forget to script are doomed to repeat their work.&quot;,<br />
&quot;Have you backed up files lately?&quot;,<br />
&quot;Is your resume up to date?&quot;,<br />
&quot;Is it Beer O'Clock yet?&quot;,<br />
&quot;With great power comes great responsibility&quot;,<br />
&quot;I came, I saw, I scripted.&quot;,<br />
&quot;$env:username, Open the pod bay doors.&quot;<br />
)<br />
<br />
$sb={ $global:PSConsoleTitle=$global:slogans | get-random }<br />
#invoke the scriptblock<br />
Invoke-Command $sb<br />
<br />
New-Timer -identifier &quot;SloganUpdate&quot; -action $sb -refresh $refresh<br />
<br />
#start the update timer if not already running<br />
if (-Not (Get-EventSubscriber -SourceIdentifier &quot;TitleTimer&quot; -ea &quot;SilentlyContinue&quot;)) {<br />
&nbsp; &nbsp; Start-TitleTimer -refresh $refresh<br />
}<br />
<br />
} #function</div></div>
<p>Think of the module as a framework or SDK for building your own solutions. The module also includes an about topic. I hope you&#8217;ll download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0NvbnNvbGVUaXRsZS56aXA=">ConsoleTitle</a>and let me know what you think.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXIraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDElMkZtYXhpbWl6aW5nLXRoZS1wb3dlcnNoZWxsLWNvbnNvbGUtdGl0bGUtYmFyJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIvJmFtcDtoZWFkbGluZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFy" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3RpdGxlPU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXI=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3RpdGxlPU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXI=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3Q9TWF4aW1pemluZyt0aGUrUG93ZXJTaGVsbCtDb25zb2xlK1RpdGxlK0Jhcg==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFyJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9tYXhpbWl6aW5nLXRoZS1wb3dlcnNoZWxsLWNvbnNvbGUtdGl0bGUtYmFyLyZhbXA7dGl0bGU9TWF4aW1pemluZyt0aGUrUG93ZXJTaGVsbCtDb25zb2xlK1RpdGxlK0Jhcg==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvbWF4aW1pemluZy10aGUtcG93ZXJzaGVsbC1jb25zb2xlLXRpdGxlLWJhci8mYW1wO3RpdGxlPU1heGltaXppbmcrdGhlK1Bvd2VyU2hlbGwrQ29uc29sZStUaXRsZStCYXI=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL21heGltaXppbmctdGhlLXBvd2Vyc2hlbGwtY29uc29sZS10aXRsZS1iYXIvJmFtcDt0aXRsZT1NYXhpbWl6aW5nK3RoZStQb3dlclNoZWxsK0NvbnNvbGUrVGl0bGUrQmFy" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9tYXhpbWl6aW5nLXRoZS1wb3dlcnNoZWxsLWNvbnNvbGUtdGl0bGUtYmFyLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2044" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/0/da"><img src="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/1/da"><img src="http://feedads.g.doubleclick.net/~a/mfUCiEGISEwEVZmz5IJdTLdp85s/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/q8YGpeBt1PE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/maximizing-the-powershell-console-title-bar/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=maximizing-the-powershell-console-title-bar</feedburner:origLink></item>
		<item>
		<title>Friday Fun Get Content Words</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/e4zco8By24k/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 15:30:58 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Get-Content]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[Select-Object]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2033</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
Recently I was tracking down a bug in script for a client. The problem turned out to be a simple typo. I could have easily avoided that by using Set-StrictMode, which I do now, but that&#8217;s not what this is &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>Recently I was tracking down a bug in script for a client. The problem turned out to be a simple typo. I could have easily avoided that by using Set-StrictMode, which I do now, but that&#8217;s not what this is about. What I realized I wanted was a way to look at all the for &#8220;words&#8221; in a script. If I could look at them sorted, then typos would jump out. At least in theory.</p>
<p>My plan was to get the content of a text file or script, use a regular expression pattern to identify all the &#8220;words&#8221; and then get a sorted and unique list. Here&#8217;s what I came up with.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> Get<span style="color: pink;">-</span>ContentWords <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">Param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span><br />
HelpMessage<span style="color: pink;">=</span><span style="color: #800000;">&quot;Enter the filename for your text file&quot;</span><span style="color: pink;">,</span><br />
ValueFromPipeline<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Path</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
Begin <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; Set<span style="color: pink;">-</span>StrictMode <span style="color: pink;">-</span>Version <span style="color: #804000;">2.0</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Starting $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">#define a regular expression pattern to detect &quot;words&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$word</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;\b\S+\b&quot;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$path</span>.gettype<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;FileInfo&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">#$Path is a file object</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Getting content from $($Path.Fullname)&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #800080;">$content</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$path</span>.Fullname<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#$Path is a string</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Getting content from $path&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$content</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">get-content</span> <span style="color: #008080; font-style: italic;">-Path</span> <span style="color: #800080;">$Path</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">#add a little information</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$stats</span><span style="color: pink;">=</span><span style="color: #800080;">$content</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Measure-Object</span> <span style="color: #008080; font-style: italic;">-Word</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Found approximately $($stats.words) words&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #008000;">#write sorted unique values</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$word</span>.Matches<span style="color: #000000;">&#40;</span><span style="color: #800080;">$content</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Value <span style="color: #008080; font-style: italic;">-unique</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">sort</span> Value<br />
&nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp;<br />
End <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Ending $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#close function</span></div></div>
<p>The function uses Get-Content to retrieve the content (what else?!) of the specified file. At the beginning of the function I defined a regular expression object to find &#8220;words&#8221;.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">#define a regular expression pattern to detect &quot;words&quot;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">regex</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$word</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;\b\S+\b&quot;</span></div></div>
<p>This is an intentionally broad pattern that searches for anything not a space. The \b element indicates a word boundary. Because this is a REGEX object, I can do a bit more than using a basic -match operator. Instead I&#8217;ll use the Matches() method which will return a collection of match objects. I can pipe these to Select-Object retrieving just the Value property. I also use the -Unique parameter to filter out duplicates. Finally the values are sorted.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$word</span>.Matches<span style="color: #000000;">&#40;</span><span style="color: #800080;">$content</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Value <span style="color: #008080; font-style: italic;">-unique</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">sort</span> Value</div></div>
<p>The matches and filtering are NOT case-sensitive, which is fine for me. With the list I can see where I might have used write-host instead of Write-Host and go back to clean up my code.  Let me show you how this works.  Here&#8217;s a demo script.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #008000;">#Requires -version 2.0</span><br />
<br />
<span style="color: #800080;">$comp</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">Read-Host</span> <span style="color: #800000;">&quot;Enter a computer name&quot;</span><br />
<br />
<span style="color: #008080; font-weight: bold;">write-host</span> <span style="color: #800000;">&quot;Querying services on $comp&quot;</span> <span style="color: pink;">-</span>fore Cyan<br />
<span style="color: #800080;">$svc</span> <span style="color: pink;">=</span> <span style="color: #008080; font-weight: bold;">get-service</span> <span style="color: pink;">-</span>comp <span style="color: #800080;">$comp</span><br />
<br />
<span style="color: #800080;">$msg</span> <span style="color: pink;">=</span> <span style="color: #800000;">&quot;I found {0} services on $comp&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #800080;">$svc</span>.count<br />
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Results&quot;</span> <span style="color: pink;">-</span>fore Green<br />
<span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800080;">$mgs</span> <span style="color: pink;">-</span>fore Green</div></div>
<p>The script has some case inconsistencies as well as a typo.  I&#8217;ve dot sourced the function in my PowerShell session. Here&#8217;s what I end up with.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2dldC1jb250ZW50d29yZHMucG5nI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA=="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/get-contentwords-300x228.png" alt="" title="get-contentwords" width="300" height="228" class="aligncenter size-medium wp-image-2034" /></a></p>
<p>For best results, you need to make sure there are spaces around commands that use the = sign. But now I can scan through the list and pick out potential problems. Sure, Set-StrictMode would help with variable typos but if I had errors in say comment based help, that wouldn&#8217;t help. Maybe you&#8217;ll find this useful in your scripting work, maybe not. But I hope you learned a few things about working with REGEX objects and unique properties.</p>
<p>Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0dldC1Db250ZW50V29yZHMudHh0" target=\"_blank\">Get-ContentWords</a> and enjoy.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHMraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDElMkZmcmlkYXktZnVuLWdldC1jb250ZW50LXdvcmRzJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMvJmFtcDtoZWFkbGluZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRz" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3RpdGxlPUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHM=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3RpdGxlPUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHM=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3Q9RnJpZGF5K0Z1bitHZXQrQ29udGVudCtXb3Jkcw==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRzJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRzJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWdldC1jb250ZW50LXdvcmRzLyZhbXA7dGl0bGU9RnJpZGF5K0Z1bitHZXQrQ29udGVudCtXb3Jkcw==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1nZXQtY29udGVudC13b3Jkcy8mYW1wO3RpdGxlPUZyaWRheStGdW4rR2V0K0NvbnRlbnQrV29yZHM=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tZ2V0LWNvbnRlbnQtd29yZHMvJmFtcDt0aXRsZT1GcmlkYXkrRnVuK0dldCtDb250ZW50K1dvcmRz" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWdldC1jb250ZW50LXdvcmRzLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2033" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/0/da"><img src="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/1/da"><img src="http://feedads.g.doubleclick.net/~a/ob0_gaW4i8sjcVaMcFMAS8nmTsw/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/e4zco8By24k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/friday-fun-get-content-words/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-get-content-words</feedburner:origLink></item>
		<item>
		<title>PowerShell in a Nutshell</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/ZGWdQOE8qlk/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 12:56:33 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2025</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
This past weekend I did an online presentation for a friend of mine who teaches for ITT in Omaha, Nebraska. He wanted me to do a brief talk about what PowerShell is and show how to use it, especially for &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>This past weekend I did an online presentation for a friend of mine who teaches for ITT in Omaha, Nebraska. He wanted me to do a brief talk about what PowerShell is and show how to use it, especially for managing Active Directory. I probably went much longer than I needed but everyone seemed to get a lot out of it. The session was recorded via WebEx. I then transcoded the recording so I could get it up on YouTube. That&#8217;s why the screen layout is a little funky and the audio is far from perfect. Still, I hope you find it useful. The presentation has a some slides but is primarily demo, including using the Microsoft Active Directory cmdlets.</p>
<p><iframe width="420" height="315" src="http://www.youtube.com/embed/vvCtUwHN2XI" frameborder="0" allowfullscreen></iframe></p>
<p>You can also <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL1Bvd2VyU2hlbGwtTWFuYWdlbWVudC1pbi1hLU51dHNoZWxsLnBkZg==">download my presentation</a> and a <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL1Bvd2VyU2hlbGxfTWFuYWdlbWVudF9pbl9hX051dHNoZWxsLnppcA==">zip file</a>with my demo scripts. </p>
<p>If you are ready to learn more check out some of the books and training videos in the side bar. Or bring me in to run a private PowerShell class for your organization.  Good Luck and Enjoy!</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVBvd2VyU2hlbGwraW4rYStOdXRzaGVsbCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwMSUyRnBvd2Vyc2hlbGwtaW4tYS1udXRzaGVsbCUyRg==" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3Bvd2Vyc2hlbGwtaW4tYS1udXRzaGVsbC8mYW1wO2hlYWRsaW5lPVBvd2VyU2hlbGwraW4rYStOdXRzaGVsbA==" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtpbithK051dHNoZWxs" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtpbithK051dHNoZWxs" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dD1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGw=" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLw==" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7aW1hZ2V1cmw9" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLw==" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9wb3dlcnNoZWxsLWluLWEtbnV0c2hlbGwvJmFtcDt0aXRsZT1Qb3dlclNoZWxsK2luK2ErTnV0c2hlbGw=" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvcG93ZXJzaGVsbC1pbi1hLW51dHNoZWxsLyZhbXA7dGl0bGU9UG93ZXJTaGVsbCtpbithK051dHNoZWxs" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3Bvd2Vyc2hlbGwtaW4tYS1udXRzaGVsbC8mYW1wO3RpdGxlPVBvd2VyU2hlbGwraW4rYStOdXRzaGVsbA==" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9wb3dlcnNoZWxsLWluLWEtbnV0c2hlbGwv" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2025" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/0/da"><img src="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/1/da"><img src="http://feedads.g.doubleclick.net/~a/tdQLUnbN-1ecd1ZFm82K018KHEE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/ZGWdQOE8qlk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/powershell-in-a-nutshell/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=powershell-in-a-nutshell</feedburner:origLink></item>
		<item>
		<title>Friday Fun: A PowerShell Alarm Clock</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/KRAy-pY-Mwc/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 14:28:42 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[FridayFun]]></category>
		<category><![CDATA[Jobs]]></category>
		<category><![CDATA[Start-Job]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2016</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
Today&#8217;s Friday Fun is a continuation of my exploration of ways to use Start-Job. A few weeks ago I wrote about using Start-Job to create &#8220;scheduled&#8221; tasks. I realized I could take this further and turn this into a sort &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>Today&#8217;s Friday Fun is a continuation of my exploration of ways to use Start-Job. A few weeks ago I wrote about <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2svI3V0bV9zb3VyY2U9ZmVlZCZhbXA7dXRtX21lZGl1bT1mZWVkJmFtcDt1dG1fY2FtcGFpZ249ZmVlZA==" target=\"_blank\">using Start-Job to create &#8220;scheduled&#8221; tasks</a>. I realized I could take this further and turn this into a sort of alarm clock. The goal is to execute at command at a given time, but I wanted to make it easy to specify the time. What I have so far is a function called New-Alarm. I have some other ideas and hope to expand this into a module, but for now I thought I&#8217;d toss this out to you and get some feedback.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> New<span style="color: pink;">-</span>Alarm <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span>SupportsShouldProcess<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>DefaultParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">Param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullorEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Command</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Notepad&quot;</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">1</span><span style="color: pink;">,</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullorEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>Alias<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;time&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>datetime<span style="color: #000000;">&#93;</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddMinutes<span style="color: #000000;">&#40;</span><span style="color: #804000;">5</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Seconds&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Seconds</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Minutes&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Minutes</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;Hours&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Hours</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ValueFromPipelineByPropertyName<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>Alias<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;init&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;is&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$InitializationScript</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddSeconds<span style="color: #000000;">&#40;</span><span style="color: #800080;">$seconds</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$minutes</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddMinutes<span style="color: #000000;">&#40;</span><span style="color: #800080;">$minutes</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$Hours</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddHours<span style="color: #000000;">&#40;</span><span style="color: #800080;">$hours</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;{0} Creating an alarm for {1} to execute {2}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">,</span><span style="color: #800080;">$Command</span><span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;">#define a scriptblock that takes parameters. Parameters are validated in the</span><br />
<span style="color: #008000;">#function so we don't need to do it here.</span><br />
<span style="color: #800080;">$sbText</span><span style="color: pink;">=@</span><span style="color: #800000;">&quot;<br />
&nbsp; &nbsp; Param ([string]<span style="color: #008080; font-weight: bold;">`$</span>Command,[datetime]<span style="color: #008080; font-weight: bold;">`$</span>Alarm,[string]<span style="color: #008080; font-weight: bold;">`$</span>Init)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #define a boolean flag<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>False<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #loop until the time is greater or equal to the alarm time<br />
&nbsp; &nbsp; #sleeping every 10 seconds<br />
&nbsp; &nbsp; do &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ((get-date) -ge <span style="color: #008080; font-weight: bold;">`$</span>Alarm) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #run the command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>ActualTime=Get-Date<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invoke-Expression <span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #set the flag to True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sleep -Seconds 10<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; } while (-Not <span style="color: #008080; font-weight: bold;">`$</span>Done)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #write an alarm summary object which can be retrieved with Receive-Job<br />
&nbsp; &nbsp; New-Object -TypeName PSObject -Property @{<br />
&nbsp; &nbsp; &nbsp; ScheduledTime=<span style="color: #008080; font-weight: bold;">`$</span>Alarm<br />
&nbsp; &nbsp; &nbsp; ActualTime=<span style="color: #008080; font-weight: bold;">`$</span>ActualTime<br />
&nbsp; &nbsp; &nbsp; Command=<span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; Initialization=<span style="color: #008080; font-weight: bold;">`$</span>Init<br />
&nbsp; &nbsp; }<br />
&quot;</span><span style="color: pink;">@</span><br />
<br />
<span style="color: #008000;">#append metadata to the scriptblock text so they can be parsed out with Get-Alarm</span><br />
<span style="color: #008000;">#to discover information for currently running alarm jobs</span><br />
<br />
<span style="color: #800080;">$meta</span><span style="color: pink;">=@</span><span style="color: #800000;">&quot;<br />
<br />
#Alarm Command::$Command<br />
#Alarm Time::$Alarm<br />
#Alarm Init::$InitializationScript<br />
#Alarm Created::$(Get-Date)<br />
<br />
&quot;</span><span style="color: pink;">@</span><br />
<br />
<span style="color: #008000;">#add meta data to scriptblock text</span><br />
<span style="color: #800080;">$sbText</span><span style="color: pink;">+=</span><span style="color: #800080;">$meta</span><br />
<br />
<span style="color: #008080; font-weight: bold;">Write-Debug</span> <span style="color: #800000;">&quot;Scriptblock text:&quot;</span><br />
<span style="color: #008080; font-weight: bold;">Write-Debug</span> <span style="color: #800080;">$sbText</span><br />
<span style="color: #008080; font-weight: bold;">Write-Debug</span> <span style="color: #800000;">&quot;Creating the scriptblock&quot;</span><br />
<br />
<span style="color: #008000;">#create a scriptblock to use with Start-Job</span><br />
<span style="color: #800080;">$sb</span><span style="color: pink;">=</span><span style="color: #800080;">$ExecutionContext</span>.InvokeCommand.NewScriptBlock<span style="color: #000000;">&#40;</span><span style="color: #800080;">$sbText</span><span style="color: #000000;">&#41;</span><br />
<br />
Try <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$InitializationScript</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#turn $initializationscript into a script block</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$initsb</span><span style="color: pink;">=</span><span style="color: #800080;">$ExecutionContext</span>.InvokeCommand.NewScriptBlock<span style="color: #000000;">&#40;</span><span style="color: #800080;">$initializationscript</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;{0} Using an initialization script: {1}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$InitializationScript</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#no initialization command so create an empty scriptblock</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$initsb</span><span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">#WhatIf</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$pscmdlet</span>.ShouldProcess<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;$command at $Alarm&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#create a background job</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Start<span style="color: pink;">-</span>job <span style="color: pink;">-</span>ScriptBlock <span style="color: #800080;">$sb</span> <span style="color: #008080; font-style: italic;">-ArgumentList</span> <span style="color: pink;">@</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$Command</span><span style="color: pink;">,</span><span style="color: #800080;">$Alarm</span><span style="color: pink;">,</span><span style="color: #800080;">$InitializationScript</span><span style="color: #000000;">&#41;</span> <span style="color: #008080; font-style: italic;">-ErrorAction</span> <span style="color: #800000;">&quot;Stop&quot;</span> <span style="color: pink;">-</span>InitializationScript <span style="color: #800080;">$Initsb</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;{0} Alarm Created&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Catch <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$msg</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;{0} Exception creating the alarm job. {1}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #000080;">$_</span>.Exception.Message<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #800080;">$msg</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#Process</span><br />
<br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#end function</span></div></div>
<p>The function includes full help.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL25ldy1hbGFybS1oZWxwLnBuZyN1dG1fc291cmNlPWZlZWQmYW1wO3V0bV9tZWRpdW09ZmVlZCZhbXA7dXRtX2NhbXBhaWduPWZlZWQ="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/new-alarm-help-300x197.png" alt="" title="new-alarm-help" width="300" height="197" class="aligncenter size-medium wp-image-2017" /></a></p>
<p>To use the function you specify a command string to execute at a given time. The default&#8217;s are to run Notepad in 5 minutes. You can either specify an exact time.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; new-alarm &quot;get-process | out-file c:\work\noonprocs.txt&quot; -alarm &quot;12:00PM&quot;</div></div>
<p>Or X number of seconds, minutes or hours.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; $s='$f=[system.io.path]::GetTempFilename(); &quot;Hey! Are you paying attention??&quot; &gt; $f;start-process notepad $f -wait;del $f'<br />
PS C:\&gt; new-alarm $s -minutes 15 -verbose</div></div>
<p>The first command defines a command string, $s. This creates a temporary file, writes some text to it, displays it with Notepad and then deletes it. The second command creates a new alarm that will invoke the expression in 15 minutes.</p>
<p>For now, the command is passed as text. This is so that I can create an internal scriptblock. I use a Do loop to compare the current time to the alarm time. When the time is right, the command string is executed using Invoke-Expression.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$sbText</span><span style="color: pink;">=@</span><span style="color: #800000;">&quot;<br />
&nbsp; &nbsp; Param ([string]<span style="color: #008080; font-weight: bold;">`$</span>Command,[datetime]<span style="color: #008080; font-weight: bold;">`$</span>Alarm,[string]<span style="color: #008080; font-weight: bold;">`$</span>Init)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #define a boolean flag<br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>False<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #loop until the time is greater or equal to the alarm time<br />
&nbsp; &nbsp; #sleeping every 10 seconds<br />
&nbsp; &nbsp; do &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; if ((get-date) -ge <span style="color: #008080; font-weight: bold;">`$</span>Alarm) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #run the command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>ActualTime=Get-Date<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Invoke-Expression <span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #set the flag to True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">`$</span>Done=<span style="color: #008080; font-weight: bold;">`$</span>True<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; else {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sleep -Seconds 10<br />
&nbsp; &nbsp; }<br />
&nbsp; &nbsp; } while (-Not <span style="color: #008080; font-weight: bold;">`$</span>Done)<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; #write an alarm summary object which can be retrieved with Receive-Job<br />
&nbsp; &nbsp; New-Object -TypeName PSObject -Property @{<br />
&nbsp; &nbsp; &nbsp; ScheduledTime=<span style="color: #008080; font-weight: bold;">`$</span>Alarm<br />
&nbsp; &nbsp; &nbsp; ActualTime=<span style="color: #008080; font-weight: bold;">`$</span>ActualTime<br />
&nbsp; &nbsp; &nbsp; Command=<span style="color: #008080; font-weight: bold;">`$</span>Command<br />
&nbsp; &nbsp; &nbsp; Initialization=<span style="color: #008080; font-weight: bold;">`$</span>Init<br />
&nbsp; &nbsp; }<br />
&quot;</span><span style="color: pink;">@</span></div></div>
<p>I also add some metadata to the script block which gets written as the job&#8217;s result.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#append metadata to the scriptblock text so they can be parsed out with Get-Alarm<br />
#to discover information for currently running alarm jobs<br />
<br />
$meta=@&quot;<br />
<br />
#Alarm Command::$Command<br />
#Alarm Time::$Alarm<br />
#Alarm Init::$InitializationScript<br />
#Alarm Created::$(Get-Date)<br />
<br />
&quot;@<br />
<br />
#add meta data to scriptblock text<br />
$sbText+=$meta<br />
<br />
Write-Debug &quot;Scriptblock text:&quot;<br />
Write-Debug $sbText<br />
Write-Debug &quot;Creating the scriptblock&quot;<br />
<br />
#create a scriptblock to use with Start-Job<br />
$sb=$ExecutionContext.InvokeCommand.NewScriptBlock($sbText)</div></div>
<p>Finally, the alarm function allows for an initialization command, like you might use with Start-Job. This permits you to run commands such as importing modules or dot sourcing scripts.  I have a function that displays a VB style message box. Here&#8217;s how I might use it as an alarm job.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; new-alarm &quot;get-messagebox 'It is time for that thing' -title 'Alert!'&quot; -init &quot;. c:\scripts\get-messagebox.ps1&quot; -min 5</div></div>
<p>In 5 minutes the alarm will go off and I&#8217;ll get this.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2FsZXJ0LnBuZyN1dG1fc291cmNlPWZlZWQmYW1wO3V0bV9tZWRpdW09ZmVlZCZhbXA7dXRtX2NhbXBhaWduPWZlZWQ="><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/alert.png" alt="" title="alert" width="227" height="161" class="aligncenter size-full wp-image-2018" /></a></p>
<p>Remember, the function is creating new jobs with the Start-Job cmdlet. Which means I can get job results.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; receive-job 7 -keep<br />
<br />
Initialization : . c:\scripts\get-messagebox.ps1<br />
ActualTime &nbsp; &nbsp; : 1/20/2012 8:47:07 AM<br />
ScheduledTime &nbsp;: 1/20/2012 8:47:06 AM<br />
Command &nbsp; &nbsp; &nbsp; &nbsp;: get-messagebox 'It is time for that thing' -title 'Alert!'<br />
RunspaceId &nbsp; &nbsp; : d3461b78-11ce-4c84-a8ab-9e3fcd482637</div></div>
<p>What do you think? As I said, I have a few more ideas and there are certainly a few tweaks I can make even to this code. I&#8217;ve added my Get-MessageBox function in case you want to toy with that.  Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0FsYXJtU2NyaXB0cy56aXA=">AlarmScripts.zip</a> and let me know what you think.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4lM0ErQStQb3dlclNoZWxsK0FsYXJtK0Nsb2NrK2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjAxJTJGZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2slMkY=" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tYS1wb3dlcnNoZWxsLWFsYXJtLWNsb2NrLyZhbXA7aGVhZGxpbmU9RnJpZGF5K0Z1biUzQStBK1Bvd2VyU2hlbGwrQWxhcm0rQ2xvY2s=" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jaw==" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jaw==" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0PUZyaWRheStGdW4lM0ErQStQb3dlclNoZWxsK0FsYXJtK0Nsb2Nr" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jayZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8=" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDtpbWFnZXVybD0=" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jayZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8=" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErQStQb3dlclNoZWxsK0FsYXJtK0Nsb2Nr" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1hLXBvd2Vyc2hlbGwtYWxhcm0tY2xvY2svJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK0ErUG93ZXJTaGVsbCtBbGFybStDbG9jaw==" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tYS1wb3dlcnNoZWxsLWFsYXJtLWNsb2NrLyZhbXA7dGl0bGU9RnJpZGF5K0Z1biUzQStBK1Bvd2VyU2hlbGwrQWxhcm0rQ2xvY2s=" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLWEtcG93ZXJzaGVsbC1hbGFybS1jbG9jay8=" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2016" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/0/da"><img src="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/1/da"><img src="http://feedads.g.doubleclick.net/~a/iWaB2bH10JNAW_jyM4ahwhZzUVc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/KRAy-pY-Mwc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/friday-fun-a-powershell-alarm-clock/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-a-powershell-alarm-clock</feedburner:origLink></item>
		<item>
		<title>Using Types with Imported CSV Data in PowerShell</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/EgKfMuYD3so/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 14:21:50 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Import-CSV]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Sort]]></category>
		<category><![CDATA[Where-Object]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2009</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
The Import-CSV cmdlet in PowerShell is incredibly useful. You can take any CSV file and pump objects to the pipeline. The cmdlet uses the CSV header as properties for the custom object. PS S:\&#62; import-csv .\testdata.csv Date &#160; &#160;: 1/18/2012 &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>The Import-CSV cmdlet in PowerShell is incredibly useful. You can take any CSV file and pump objects to the pipeline. The cmdlet uses the CSV header as properties for the custom object.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv .\testdata.csv<br />
<br />
<br />
Date &nbsp; &nbsp;: 1/18/2012 6:45:30 AM<br />
Name &nbsp; &nbsp;: Data_1<br />
Service : ALG<br />
Key &nbsp; &nbsp; : 1<br />
Size &nbsp; &nbsp;: 25<br />
<br />
Date &nbsp; &nbsp;: 1/18/2012 2:17:30 AM<br />
Name &nbsp; &nbsp;: Data_2<br />
Service : AppIDSvc<br />
Key &nbsp; &nbsp; : 2<br />
Size &nbsp; &nbsp;: -30<br />
...</div></div>
<p>But there is a downside: all of the properties are strings.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv .\testdata.csv | get-member<br />
<br />
<br />
&nbsp; &nbsp;TypeName: System.Management.Automation.PSCustomObject<br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;MemberType &nbsp; Definition<br />
---- &nbsp; &nbsp; &nbsp; &nbsp;---------- &nbsp; ----------<br />
Equals &nbsp; &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; bool Equals(System.Object obj)<br />
GetHashCode Method &nbsp; &nbsp; &nbsp; int GetHashCode()<br />
GetType &nbsp; &nbsp; Method &nbsp; &nbsp; &nbsp; type GetType()<br />
ToString &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; string ToString()<br />
Date &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Date=1/18/2012 6:45:30 AM<br />
Key &nbsp; &nbsp; &nbsp; &nbsp; NoteProperty System.String Key=1<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Name=Data_1<br />
Service &nbsp; &nbsp; NoteProperty System.String Service=ALG<br />
Size &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Size=25</div></div>
<p>The means some tasks such sorting or filtering will fail. But there are ways to get around this limitation. One way is to use an expression to cast a property to a different type. For example, I want to sort my test data on the Date property, but it needs to be a [DateTime] object to sort properly. Here&#8217;s how:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv testdata.csv &nbsp;| sort @{expression={$_.date -as [datetime]}} | Select Date,Name,Size<br />
<br />
Date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Size<br />
---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ----<br />
1/9/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; &nbsp;Data_25 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;26<br />
1/11/2012 11:13:30 AM &nbsp; &nbsp; &nbsp;Data_20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;44<br />
1/11/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; Data_23 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;33<br />
1/13/2012 12:13:30 AM &nbsp; &nbsp; &nbsp;Data_16 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;42<br />
1/13/2012 4:45:30 PM &nbsp; &nbsp; &nbsp; Data_24 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;47<br />
...</div></div>
<p>My output object properties are all still strings. All I did was cast the Date property in the Sort expression. Here&#8217;s an example using filtering.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; import-csv testdata.csv &nbsp;| where {($_.date -as [datetime]) -le (&quot;1/12/2012&quot; -as [datetime])} | Select Date,Name,Size<br />
<br />
Date &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Size<br />
---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ----<br />
1/11/2012 11:13:30 AM &nbsp; &nbsp; &nbsp;Data_20 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;44<br />
1/11/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; Data_23 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;33<br />
1/9/2012 6:28:30 PM &nbsp; &nbsp; &nbsp; &nbsp;Data_25 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;26</div></div>
<p>These examples are only producing results. More likely I want to import the CSV file as typed objects.  Assuming you know in advance the property names and what types you want to use, here&#8217;s how you could achieve this.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $data=import-csv testdata.csv | Select @{Name=&quot;Date&quot;;Expression={[datetime]$_.Date}}, Name,Service,@{Name=&quot;Key&quot;;Expression={[int32]$_.Key}},@{Name=&quot;Size&quot;;Expression={[int32]$_.Size}}</div></div>
<p>I imported my CSV file and piped it to Select-Object, using hash tables to redefine the properties with appropriate types. Import-CSV writes a PSCustomObject to the pipeline anyway so using Select-Object has no effect other than giving me typed properties.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $data | get-member<br />
<br />
<br />
&nbsp; &nbsp;TypeName: Selected.System.Management.Automation.PSCustomObject<br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;MemberType &nbsp; Definition<br />
---- &nbsp; &nbsp; &nbsp; &nbsp;---------- &nbsp; ----------<br />
Equals &nbsp; &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; bool Equals(System.Object obj)<br />
GetHashCode Method &nbsp; &nbsp; &nbsp; int GetHashCode()<br />
GetType &nbsp; &nbsp; Method &nbsp; &nbsp; &nbsp; type GetType()<br />
ToString &nbsp; &nbsp;Method &nbsp; &nbsp; &nbsp; string ToString()<br />
Date &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.DateTime Date=1/18/2012 6:45:30 AM<br />
Key &nbsp; &nbsp; &nbsp; &nbsp; NoteProperty System.Int32 Key=1<br />
Name &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.String Name=Data_1<br />
Service &nbsp; &nbsp; NoteProperty System.String Service=ALG<br />
Size &nbsp; &nbsp; &nbsp; &nbsp;NoteProperty System.Int32 Size=25</div></div>
<p>Now I can use $data objects anyway I want.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $data | where {$_.size -ge 40 -AND $_.key -le 10}<br />
<br />
<br />
Date &nbsp; &nbsp;: 1/17/2012 11:57:30 PM<br />
Name &nbsp; &nbsp;: Data_3<br />
Service : Appinfo<br />
Key &nbsp; &nbsp; : 3<br />
Size &nbsp; &nbsp;: 42</div></div>
<p>I&#8217;m working on something that takes this idea to the next level but it isn&#8217;t quite ready for prime time. But I hope this will help manage imported objects a bit more efficiently and let you really take advantage of the PowerShell pipeline.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVVzaW5nK1R5cGVzK3dpdGgrSW1wb3J0ZWQrQ1NWK0RhdGEraW4rUG93ZXJTaGVsbCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwMSUyRnVzaW5nLXR5cGVzLXdpdGgtaW1wb3J0ZWQtY3N2LWRhdGEtaW4tcG93ZXJzaGVsbCUyRg==" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3VzaW5nLXR5cGVzLXdpdGgtaW1wb3J0ZWQtY3N2LWRhdGEtaW4tcG93ZXJzaGVsbC8mYW1wO2hlYWRsaW5lPVVzaW5nK1R5cGVzK3dpdGgrSW1wb3J0ZWQrQ1NWK0RhdGEraW4rUG93ZXJTaGVsbA==" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9VXNpbmcrVHlwZXMrd2l0aCtJbXBvcnRlZCtDU1YrRGF0YStpbitQb3dlclNoZWxs" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9VXNpbmcrVHlwZXMrd2l0aCtJbXBvcnRlZCtDU1YrRGF0YStpbitQb3dlclNoZWxs" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dD1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGw=" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLw==" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7aW1hZ2V1cmw9" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGwmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLw==" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy10eXBlcy13aXRoLWltcG9ydGVkLWNzdi1kYXRhLWluLXBvd2Vyc2hlbGwvJmFtcDt0aXRsZT1Vc2luZytUeXBlcyt3aXRoK0ltcG9ydGVkK0NTVitEYXRhK2luK1Bvd2VyU2hlbGw=" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctdHlwZXMtd2l0aC1pbXBvcnRlZC1jc3YtZGF0YS1pbi1wb3dlcnNoZWxsLyZhbXA7dGl0bGU9VXNpbmcrVHlwZXMrd2l0aCtJbXBvcnRlZCtDU1YrRGF0YStpbitQb3dlclNoZWxs" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3VzaW5nLXR5cGVzLXdpdGgtaW1wb3J0ZWQtY3N2LWRhdGEtaW4tcG93ZXJzaGVsbC8mYW1wO3RpdGxlPVVzaW5nK1R5cGVzK3dpdGgrSW1wb3J0ZWQrQ1NWK0RhdGEraW4rUG93ZXJTaGVsbA==" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy10eXBlcy13aXRoLWltcG9ydGVkLWNzdi1kYXRhLWluLXBvd2Vyc2hlbGwv" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2009" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/0/da"><img src="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/1/da"><img src="http://feedads.g.doubleclick.net/~a/tgzY86wgk1aT2Iy0wKOhqvLVRow/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/EgKfMuYD3so" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/using-types-with-imported-csv-data-in-powershell/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-types-with-imported-csv-data-in-powershell</feedburner:origLink></item>
		<item>
		<title>Friday Fun: Output to 2 Places in 1</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/DbMbqeiOA90/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 13:50:58 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[FridayFun]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Tee-Object]]></category>
		<category><![CDATA[Write-Host]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=2002</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
Today&#8217;s Friday Fun comes out of a short exchange I had yesterday with Hal Rottenberg on Google Plus. We were playing around with piping a PowerShell command to Clip.exe which dumps the output to the Windows Clipboard. I got to &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>Today&#8217;s Friday Fun comes out of a short exchange I had yesterday with <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9wbHVzLmdvb2dsZS5jb20vMTA2NDIzNDIyMzcyNDIxMzgwNzgwL3Bvc3Rz" target=\"_blank\">Hal Rottenberg on Google Plus</a>. We were playing around with piping a PowerShell command to Clip.exe which dumps the output to the Windows Clipboard. I got to thinking about taking this a step further based on my needs as a writer. Often I&#8217;d like to see the results of a command and then copy and paste the results into whatever I&#8217;m working on. In other words, I need to TEE the output to two places.</p>
<p>PowerShell has a cmdlet called Tee-Object that follows this principal. The default behavior is to write output to the pipeline AND send it to a text file.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-service | tee c:\work\svc.txt</div></div>
<p>I&#8217;ll see the results and save them to a text file. I can also use this cmdlet to save results to a variable.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-service | tee c:\work\svc.txt<br />
<br />
Status &nbsp; Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; DisplayName<br />
------ &nbsp; ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -----------<br />
Running &nbsp;AeLookupSvc &nbsp; &nbsp; &nbsp; &nbsp;Application Experience<br />
Stopped &nbsp;ALG &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application Layer Gateway Service<br />
Stopped &nbsp;AppIDSvc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Application Identity<br />
Stopped &nbsp;Appinfo &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application Information<br />
...<br />
Running &nbsp;wudfsvc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Windows Driver Foundation - User-mo...<br />
Stopped &nbsp;WwanSvc &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;WWAN AutoConfig<br />
<br />
<br />
PS C:\&gt; $svc.count<br />
196<br />
PS C:\&gt;</div></div>
<p>One approach I came up with to incorporate with Clip.exe was this:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-service | tee -Variable svc | clip</div></div>
<p>I don&#8217;t get the results immediately to the screen; they are saved to the variable. But at the same time output has been directed to the Windows Clipboard. That could be useful. But you know me, I always have to tinker a bit more and I ended up with a function called Out-Tee.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> Out<span style="color: pink;">-</span><span style="color: #008080; font-weight: bold;">Tee</span> <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">Param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>ValueFromPipeline<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">object</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$InputObject</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>alias<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;foregroundcolor&quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;fg&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$TextColor</span><span style="color: pink;">=</span><span style="color: #800080;">$host</span>.ui.rawui.ForegroundColor<br />
<span style="color: #000000;">&#41;</span><br />
<br />
Begin <span style="color: #000000;">&#123;</span><br />
&nbsp;<span style="color: #008000;">#define an empty array to hold piped in objects</span><br />
&nbsp;<span style="color: #800080;">$a</span><span style="color: pink;">=@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#add each piped in object to the array</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$a</span><span style="color: pink;">+=</span><span style="color: #800080;">$inputobject</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
End <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#write the array to the pipeline as a string then pass to Write-Host</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$a</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-string</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">write-host</span> <span style="color: pink;">-</span>fore <span style="color: #800080;">$textColor</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#write the array again to Clip.exe</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$a</span> <span style="color: pink;">|</span> clip<br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#end function</span></div></div>
<p>This simple function takes a PowerShell expression and writes the results to the console using Write-Host and also to the clipboard.  The default output will use the current console foreground color. But you can specify any other color that you would use with Write-Host. I even added some alias properties so you can use -foregroundcolor or -fg.</p>
<p>With this function I can see the result and have it dumped to the clipboard. Because the default text color is the same as my session, I don&#8217;t see any difference when using Out-Tee.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; ps | where {$_.ws -gt 100mb} | out-tee</div></div>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL291dC10ZWUtMS5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/out-tee-1-300x141.png" alt="" title="out-tee-1" width="300" height="141" class="aligncenter size-medium wp-image-2003" /></a></p>
<p>Or if I want to pretty it up, I can add a little color.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; ps | where {$_.ws -gt 100mb} | out-tee -TextColor green</div></div>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL291dC10ZWUtMi5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/out-tee-2-300x141.png" alt="" title="out-tee-2" width="300" height="141" class="aligncenter size-medium wp-image-2004" /></a></p>
<p>Of course, the clipboard is just text. But now I have something easier to use to save output to the clipboard so I can paste it into my documents, assuming I like the output I see on the screen. The one caveat is that this function only works with successful commands. Errors, warnings, or verbose statements won&#8217;t get dumped to the clipboard. I can think of some ways around that which I might try in a future version. But for my immediate needs this works just fine.</p>
<p>Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL091dC1UZWUudHh0" target='_blank'>Out-Tee</a> and give it a try.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzEraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDElMkZmcmlkYXktZnVuLW91dHB1dC10by0yLXBsYWNlcy1pbi0xJTJG" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEvJmFtcDtoZWFkbGluZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisx" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzE=" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzE=" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3Q9RnJpZGF5K0Z1biUzQStPdXRwdXQrdG8rMitQbGFjZXMraW4rMQ==" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisxJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEv" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO2ltYWdldXJsPQ==" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisxJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEv" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLW91dHB1dC10by0yLXBsYWNlcy1pbi0xLyZhbXA7dGl0bGU9RnJpZGF5K0Z1biUzQStPdXRwdXQrdG8rMitQbGFjZXMraW4rMQ==" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi1vdXRwdXQtdG8tMi1wbGFjZXMtaW4tMS8mYW1wO3RpdGxlPUZyaWRheStGdW4lM0ErT3V0cHV0K3RvKzIrUGxhY2VzK2luKzE=" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4tb3V0cHV0LXRvLTItcGxhY2VzLWluLTEvJmFtcDt0aXRsZT1GcmlkYXkrRnVuJTNBK091dHB1dCt0bysyK1BsYWNlcytpbisx" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLW91dHB1dC10by0yLXBsYWNlcy1pbi0xLw==" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2002" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/0/da"><img src="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/1/da"><img src="http://feedads.g.doubleclick.net/~a/x5_T5am6lH5HiY0dXgrlZwxMeEo/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/DbMbqeiOA90" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/friday-fun-output-to-2-places-in-1/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-output-to-2-places-in-1</feedburner:origLink></item>
		<item>
		<title>Convert Text to Object Updated</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/Y6a-OeREV-I/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 14:43:45 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[CommandLine]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Convert]]></category>
		<category><![CDATA[Split]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=1995</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
I&#8217;ve had a few comments and emails lately about my post and script on converting text to objects. I decided the function needed a little more lovin&#8217; so today I have an updated version, complete with comment based help. Function &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>I&#8217;ve had a few comments and emails lately about my post and script on <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTEvMTAvY29udmVydC10ZXh0LXRvLW9iamVjdC8jdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk" target=\"_blank\">converting text to objects</a>. I decided the function needed a little more lovin&#8217; so today I have an updated version, complete with comment based help.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0000FF;">Function</span> Convert<span style="color: pink;">-</span>TextToObject <span style="color: #000000;">&#123;</span><br />
<br />
<span style="color: #008000;">&lt;#<br />
.Synopsis<br />
Convert text to a PowerShell object<br />
.Description<br />
This function takes a collection of simple delimited lines and<br />
turns them into an object. The function assumes a single delimiter.<br />
The default delimiter is the colon (:). The item to the left will be <br />
the property and the item on the left will be the property value.<br />
<br />
By default the function will split on every delimiter, but you can use<br />
the -SplitCount parameter to control the number of strings. If you don't <br />
want to split at all use a value of 1. To split on the first delimiter <br />
only, use a value of 2.<br />
<br />
For example, if the string is: Foobar: &nbsp;01/11/2012 09:41:28 and you tried<br />
to split on the &quot;:&quot;, &nbsp;you would end up with 4 elements in the array. But <br />
using a -SplitCount value of 2 would give you this:<br />
<br />
Foobar<br />
01/11/2012 09:41:28<br />
<br />
Use $GroupCount to keep track of items that come in groups and write a new <br />
object when the count has been reached. For example, this allows you to <br />
pipe in a long collection of strings and turn every 5 into an object.<br />
<br />
This function works best with command line tools that write list-like<br />
output.<br />
<br />
.Parameter Text<br />
The text to be converted<br />
.Parameter Delimiter<br />
The text delimiter to split on. The colon (&quot;:&quot;) is the default.<br />
.Parameter SplitCount<br />
The number of strings to create when splitting. The default is to split<br />
on all delimiters. If you don't want to split at all use a value of 1. <br />
To split on the first delimiter only, use a value of 2.<br />
.Parameter GroupCount<br />
The number of piped in strings to group together to form a new object.<br />
.Example<br />
PS C:&gt; tasklist /s server01 /fo list | where {$_} | convert-texttoobject -group 5<br />
<br />
Take the output for Tasklist.exe as a list, strip out blank lines and pipe<br />
to Convert-TextToObject. Turn every 5 items into an object.<br />
.Example<br />
PS C:\&gt; get-content c:\work\data.txt | select -skip 4 | where {$_} | cto -group 4 -SplitCount 2 | format-list<br />
<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 5:44:56 AM<br />
DisplayName : 1394 OHCI Compliant Host Controller<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: 1394ohci<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:19:16 AM<br />
DisplayName : Microsoft ACPI Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: ACPI<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM<br />
DisplayName : ACPI Power Meter Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: AcpiPmi<br />
<br />
<br />
Get the Data.txt file, skipping the first 4 lines and stripping out blanks. <br />
Then create objects for every 4 lines. The SplitCount is set to 2 so that <br />
the LinkDate value is the complete datetime stamp.<br />
.Example<br />
PS C:\&gt; whoami /user /fo list | where {$_ -match &quot;:&quot;} | convert-texttoobject | format-table -auto<br />
<br />
UserName &nbsp; &nbsp; &nbsp;SID<br />
-------- &nbsp; &nbsp; &nbsp;---<br />
serenity\jeff S-1-5-21-2858895768-3673612314-3109562570-1000<br />
.Example<br />
PS C:\&gt; whoami /groups /fo list | where {$_ -match &quot;:&quot;} | cto -group 4 | format-list<br />
<br />
<br />
Attributes : Mandatory group, Enabled by default, Enabled group<br />
Type &nbsp; &nbsp; &nbsp; : Well-known group<br />
GroupName &nbsp;: Everyone<br />
SID &nbsp; &nbsp; &nbsp; &nbsp;: S-1-1-0<br />
<br />
Attributes : Mandatory group, Enabled by default, Enabled group, Group owner<br />
Type &nbsp; &nbsp; &nbsp; : Alias<br />
GroupName &nbsp;: BUILTIN\Administrators<br />
SID &nbsp; &nbsp; &nbsp; &nbsp;: S-1-5-32-544<br />
<br />
...<br />
<br />
Get group listing from Whoami.exe and filter out lines that don't have a colon.<br />
Create objects for every 4 lines. This example is using the cto alias for the<br />
Convert-TexttoObject function.<br />
.Link<br />
about_Split<br />
New-Object<br />
<br />
.Inputs<br />
Strings<br />
<br />
.Outputs<br />
Custom object<br />
#&gt;</span><br />
<br />
<span style="color: #000000;">&#91;</span>cmdletbinding<span style="color: #000000;">&#40;</span>SupportsShouldProcess<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">param</span> <span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>Mandatory<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: pink;">,</span>HelpMessage<span style="color: pink;">=</span><span style="color: #800000;">&quot;Enter a string to be parsed into an object&quot;</span><span style="color: pink;">,</span><br />
ValueFromPipeline<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullorEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Text</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullOrEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Delimiter</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;:&quot;</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>ValidateScript<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span> <span style="color: #FF0000;">-ge</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$SplitCount</span><span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$GroupCount</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
Begin <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Starting $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#define a hashtable</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$myHash</span><span style="color: pink;">=@</span><span style="color: #000000;">&#123;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$GroupCount</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Grouping every $GroupCount items as an object&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#start an internal counter</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #804000;">0</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Skipping $Skip lines&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Using $Delimiter delimiter&quot;</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Splitting into $SplitCount lines. 0 means all.&quot;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
Process <span style="color: #000000;">&#123;</span> &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000FF;">Foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$item</span> <span style="color: #0000FF;">in</span> <span style="color: #800080;">$text</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: #FF0000;">-lt</span> <span style="color: #800080;">$GroupCount</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$i</span><span style="color: pink;">++</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#reset</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$i</span><span style="color: pink;">=</span><span style="color: #804000;">1</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#split each line at the delimiter</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$data</span><span style="color: pink;">=</span><span style="color: #800080;">$item</span> <span style="color: pink;">-</span>Split <span style="color: #800080;">$delimiter</span><span style="color: pink;">,</span><span style="color: #800080;">$SplitCount</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#remove spaces from &quot;property&quot; name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$prop</span><span style="color: pink;">=</span><span style="color: #800080;">$data</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">0</span><span style="color: #000000;">&#93;</span>.Replace<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot; &quot;</span><span style="color: pink;">,</span><span style="color: #800000;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#trim</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$prop</span><span style="color: pink;">=</span><span style="color: #800080;">$prop</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$val</span><span style="color: pink;">=</span><span style="color: #800080;">$data</span><span style="color: #000000;">&#91;</span><span style="color: #804000;">1</span><span style="color: #000000;">&#93;</span>.Trim<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#add to hash table</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Adding $prop to hash table with a value of $val&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$myHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800080;">$prop</span><span style="color: pink;">,</span><span style="color: #800080;">$val</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#if internal counter is equal to the group count</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#write the object and reset the hash table</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$i</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$groupCount</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> PSObject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: #800080;">$myHash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$myHash</span>.<span style="color: #008080; font-weight: bold;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#foreach</span><br />
<span style="color: #000000;">&#125;</span><br />
End <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#create new object from hash table</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$myHash</span>.count <span style="color: #FF0000;">-gt</span> <span style="color: #804000;">0</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> PSObject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: #800080;">$myHash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Verbose</span> <span style="color: #800000;">&quot;Ending $($myinvocation.mycommand)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#end function</span></div></div>
<p>Check out the original article to understand the basics. The major change here is the SplitCount parameter. Often you might end up with a line of text like this:</p>
<p>LinkDate    : 11/20/2010 4:30:42 AM</p>
<p>The function needs to split the string into an array on the colon. But when you do that, the time stamp will &#8220;break&#8221;. The answer is to tell the Split operator how many strings to create. The default of 0 will split into all strings.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; &quot;DisplayName : ACPI Power Meter Driver&quot; -split &quot;:&quot;,0<br />
DisplayName<br />
&nbsp;ACPI Power Meter Driver</div></div>
<p>If I try that with the time stamp string you see the problem.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; &quot;LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM&quot; -split &quot;:&quot;,0<br />
LinkDate<br />
&nbsp;11/20/2010 4<br />
30<br />
42 AM</div></div>
<p>But now I can specify the number of strings and I get what I need.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; &quot;LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM&quot; -split &quot;:&quot;,2<br />
LinkDate<br />
&nbsp;11/20/2010 4:30:42 AM</div></div>
<p>The new version of the function incorporates this. I also received a comment about including a skip feature. I kicked that idea around for awhile, but decided in the end that PowerShell already had a mechanism for skipping lines. I wanted to keep my function limited to a single purpose. So if your text output includes a number of lines you want to skip, before you begin converting text to object, use something like this:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; get-content c:\work\data.txt | select -skip 4 | where {$_} | cto -group 4 -SplitCount 2 | format-list<br />
<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 5:44:56 AM<br />
DisplayName : 1394 OHCI Compliant Host Controller<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: 1394ohci<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:19:16 AM<br />
DisplayName : Microsoft ACPI Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: ACPI<br />
<br />
LinkDate &nbsp; &nbsp;: 11/20/2010 4:30:42 AM<br />
DisplayName : ACPI Power Meter Driver<br />
DriverType &nbsp;: Kernel<br />
ModuleName &nbsp;: AcpiPmi</div></div>
<p>The script file with the function, will also create an alias of cto. I hope you&#8217;ll download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL0NvbnZlcnQtVGV4dHRvT2JqZWN0Li12MS41LnR4dA==" target='_blank'>Convert-TexttoObject.-v1.5</a> and let me know what you think.</p>
<div class="tweetthis" style="text-align:left;"><p> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUNvbnZlcnQrVGV4dCt0bytPYmplY3QrVXBkYXRlZCtodHRwJTNBJTJGJTJGamRoaXRzb2x1dGlvbnMuY29tJTJGYmxvZyUyRjIwMTIlMkYwMSUyRmNvbnZlcnQtdGV4dC10by1vYmplY3QtdXBkYXRlZCUyRg==" title=\"Post to Twitter\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/twitter/tt-twitter6.png" alt="Post to Twitter" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BsdXJrLmNvbS8/c3RhdHVzPSU1QkJMQU5LJTVE" title=\"Post to Plurk\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/plurk/tt-plurk.png" alt="Post to Plurk" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2J1enoueWFob28uY29tL2J1eno/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2NvbnZlcnQtdGV4dC10by1vYmplY3QtdXBkYXRlZC8mYW1wO2hlYWRsaW5lPUNvbnZlcnQrVGV4dCt0bytPYmplY3QrVXBkYXRlZA==" title=\"Post to Yahoo Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/buzz/tt-buzz.png" alt="Post to Yahoo Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dGl0bGU9Q29udmVydCtUZXh0K3RvK09iamVjdCtVcGRhdGVk" title=\"Post to Delicious\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/delicious/tt-delicious.png" alt="Post to Delicious" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dGl0bGU9Q29udmVydCtUZXh0K3RvK09iamVjdCtVcGRhdGVk" title=\"Post to Digg\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/digg/tt-digg.png" alt="Post to Digg" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dD1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQ=" title=\"Post to Facebook\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/facebook/tt-facebook.png" alt="Post to Facebook" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLw==" title=\"Post to FriendFeed\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ff/tt-ff.png" alt="Post to FriendFeed" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7aW1hZ2V1cmw9" title=\"Post to Google Buzz\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/gbuzz/tt-gbuzz.png" alt="Post to Google Buzz" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQmYW1wO2xpbms9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLw==" title=\"Post to Ping.fm\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/ping/tt-ping.png" alt="Post to Ping.fm" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9jb252ZXJ0LXRleHQtdG8tb2JqZWN0LXVwZGF0ZWQvJmFtcDt0aXRsZT1Db252ZXJ0K1RleHQrdG8rT2JqZWN0K1VwZGF0ZWQ=" title=\"Post to Reddit\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/reddit/tt-reddit.png" alt="Post to Reddit" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvY29udmVydC10ZXh0LXRvLW9iamVjdC11cGRhdGVkLyZhbXA7dGl0bGU9Q29udmVydCtUZXh0K3RvK09iamVjdCtVcGRhdGVk" title=\"Post to Slashdot\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/slashdot/tt-slashdot.png" alt="Post to Slashdot" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0dW1ibGV1cG9uLmNvbS9zdWJtaXQ/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2NvbnZlcnQtdGV4dC10by1vYmplY3QtdXBkYXRlZC8mYW1wO3RpdGxlPUNvbnZlcnQrVGV4dCt0bytPYmplY3QrVXBkYXRlZA==" title=\"Post to StumbleUpon\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/su/tt-su.png" alt="Post to StumbleUpon" /></a> <a target=\"_blank\" class=\"tt\" href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9jb252ZXJ0LXRleHQtdG8tb2JqZWN0LXVwZGF0ZWQv" title=\"Post to Technorati\"><img class="nothumb" src="http://jdhitsolutions.com/blog/wp-content/plugins/tweet-this/icons/en/technorati/tt-technorati.png" alt="Post to Technorati" /></a></p></div> <img src="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1995" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/D7okg93432f_TFrn0uPu2X75trQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/Y6a-OeREV-I" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/convert-text-to-object-updated/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=convert-text-to-object-updated</feedburner:origLink></item>
		<item>
		<title>The PowerShell Morning Report</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/5h-K06-T1gc/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/the-powershell-morning-report/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 18:18:31 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[Windows Server]]></category>
		<category><![CDATA[WMI]]></category>
		<category><![CDATA[ConvertTo-HTML]]></category>
		<category><![CDATA[Get-WMIObject]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=1977</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 love how easy it is to manage computers with Windows PowerShell. It is a great reporting tool, but often I find people getting locked into one approach. I&#8217;m a big believer in flexibility and re-use and using objects in &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/the-powershell-morning-report/">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><img src="http://www.lionking.org/imgarchive/Clip_Art/zazu03.gif" alt="Zazu" style='float:left' width='240' height='200' hspace=15 vspace=15/>I love how easy it is to manage computers with Windows PowerShell. It is a great reporting tool, but often I find people getting locked into one approach. I&#8217;m a big believer in flexibility and re-use and using objects in the pipeline wherever I can. So I put together a PowerShell script that I can run every morning on my computer and get a quick summary about what is happening, or perhaps not happening. My script, MorningReport.ps1, relies on WMI to gather a variety of system information. By default it connects to the local host, but I&#8217;ve provided a computername parameter. I&#8217;m assuming current credentials are good enough for any remote system, but you can always add support for alternate credentials, assuming I don&#8217;t in some future version.</p>
<p>By default the script writes a custom object to the pipeline that contains all of the other WMI information like disk utilization, service status, and event logs. But I wanted flexibility and ease of use, so the script also supports parameters of -Text and -HTML. The former creates nicely formatted text suitable for printing or saving to a file. The latter creates HTML code from the original objects. I rely heavily on creating HTML fragments with ConvertTo-HTML and then assembling everything at the end. The script writes the HTML code to the pipeline so if you want to save results to a file, simply pipe to Out-File. I did this because there may be times when you want the &#8220;raw&#8221; HTML code. You might want to save the HTML and create an HTML mail message with Send-MailMessage. Or maybe further tweak the HTML before saving it to a file. Again, I didn&#8217;t want to lock myself in. Here&#8217;s the main part of the script.</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>cmdletbinding<span style="color: #000000;">&#40;</span>DefaultParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;object&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<br />
<span style="color: #0000FF;">Param</span><span style="color: #000000;">&#40;</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>Position<span style="color: pink;">=</span><span style="color: #804000;">0</span><span style="color: pink;">,</span>ValueFromPipeline<span style="color: pink;">=</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullOrEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Computername</span><span style="color: pink;">=</span><span style="color: #800080;">$env</span>:computername<span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>ValidateNotNullOrEmpty<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span>alias<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;title&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$ReportTitle</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;System Report&quot;</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>ValidateScript<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span> <span style="color: #FF0000;">-ge</span> <span style="color: #804000;">1</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Hours</span><span style="color: pink;">=</span><span style="color: #804000;">24</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;HTML&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #0000FF;">switch</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$HTML</span><span style="color: pink;">,</span><br />
<span style="color: #000000;">&#91;</span>Parameter<span style="color: #000000;">&#40;</span>ParameterSetName<span style="color: pink;">=</span><span style="color: #800000;">&quot;TEXT&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #0000FF;">switch</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$Text</span><br />
<span style="color: #000000;">&#41;</span><br />
<br />
<span style="color: #008000;">#script internal version number used in output</span><br />
<span style="color: #000000;">&#91;</span><span style="color: #008080;">string</span><span style="color: #000000;">&#93;</span><span style="color: #800080;">$reportVersion</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;1.0.8&quot;</span><br />
<br />
<span style="color: #008000;">&lt;#<br />
define some HTML style<br />
here's a source for HTML color codes<br />
http://www.immigration-usa.com/html_colors.html<br />
<br />
the code must be left justified &nbsp;<br />
#&gt;</span> &nbsp; &nbsp; <br />
<span style="color: #800080;">$head</span> <span style="color: pink;">=</span> <span style="color: pink;">@</span><span style="color: #800000;">&quot;<br />
&lt;style&gt;<br />
body { background-color:#CCFFFF;<br />
&nbsp; &nbsp; &nbsp; &nbsp;font-family:Tahoma;<br />
&nbsp; &nbsp; &nbsp; &nbsp;font-size:12pt; }<br />
td, th { border:1px solid #000033; <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;border-collapse:collapse; }<br />
th { color:white;<br />
&nbsp; &nbsp; &nbsp;background-color:#000033; }<br />
table, tr, td, th { padding: 2px; margin: 0px }<br />
table { margin-left:50px; }<br />
&lt;/style&gt;<br />
&lt;Title&gt;$ReportTitle&lt;/Title&gt;<br />
&quot;</span><span style="color: pink;">@</span><br />
<br />
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$computername</span> <span style="color: #FF0000;">-eq</span> <span style="color: #800080;">$env</span>:computername<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp;<span style="color: #008000;">#local computer so no ping test is necessary</span><br />
&nbsp;<span style="color: #800080;">$OK</span><span style="color: pink;">=</span><span style="color: #800080;">$True</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #0000FF;">elseIf</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$computername</span> <span style="color: #FF0000;">-ne</span> <span style="color: #800080;">$env</span>:computername<span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-AND</span> <span style="color: #000000;">&#40;</span>Test<span style="color: pink;">-</span>Connection <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span> <span style="color: #008080; font-style: italic;">-quiet</span> <span style="color: #008080; font-style: italic;">-Count</span> <span style="color: #804000;">2</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp;<span style="color: #008000;">#not local computer and it can be pinged so proceed</span><br />
&nbsp;<span style="color: #800080;">$OK</span><span style="color: pink;">=</span><span style="color: #800080;">$True</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #0000FF;">If</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$OK</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; Try <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$os</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> Win32_operatingSystem <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span> <span style="color: #008080; font-style: italic;">-ErrorAction</span> Stop<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#set a variable to indicate WMI can be reached</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$wmi</span><span style="color: pink;">=</span><span style="color: #800080;">$True</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; Catch <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #800000;">&quot;WMI failed to connect to $($computername.ToUpper())&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$wmi</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;Preparing morning report for $($os.CSname)&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#OS Summary</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Operating System&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$osdata</span><span style="color: pink;">=</span><span style="color: #800080;">$os</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Computername&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.CSName<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;OS&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Caption<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;ServicePack&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.CSDVersion<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; free<span style="color: pink;">*</span>memory<span style="color: pink;">,</span>totalv<span style="color: pink;">*,</span>NumberOfProcesses<span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;LastBoot&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.ConvertToDateTime<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.LastBootupTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Uptime&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: #000000;">&#40;</span><span style="color: #000080;">$_</span>.ConvertToDateTime<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.LastBootupTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Computer system</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Computer System&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$cs</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_Computersystem <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$csdata</span><span style="color: pink;">=</span><span style="color: #800080;">$cs</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Status<span style="color: pink;">,</span>Manufacturer<span style="color: pink;">,</span>Model<span style="color: pink;">,</span>SystemType<span style="color: pink;">,</span>Number<span style="color: pink;">*</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#services</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Services&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#get services via WMI and group into a hash table</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$wmiservices</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-class</span> Win32_Service <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span> &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$services</span><span style="color: pink;">=</span><span style="color: #800080;">$wmiservices</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Group</span> State <span style="color: pink;">-</span>AsHashTable <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#get services set to auto start that are not running</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$failedAutoStart</span><span style="color: pink;">=</span><span style="color: #800080;">$wmiservices</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.startmode <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;Auto&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF0000;">-AND</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.state <span style="color: #FF0000;">-ne</span> <span style="color: #800000;">&quot;Running&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Disk Utilization</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Logical Disks&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$disks</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</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: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$diskData</span><span style="color: pink;">=</span><span style="color: #800080;">$disks</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> DeviceID<span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;SizeGB&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.size<span style="color: pink;">/</span>1GB <span style="color: #FF0000;">-as</span> <span style="color: #000000;">&#91;</span><span style="color: #008080;">int</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;FreeGB&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #800000;">&quot;{0:N2}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Freespace<span style="color: pink;">/</span>1GB<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;PercentFree&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #800000;">&quot;{0:P2}&quot;</span> &nbsp;<span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.Freespace<span style="color: pink;">/</span><span style="color: #000080;">$_</span>.Size<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#NetworkAdapters</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Network Adapters&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#get NICS that have a MAC address only</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$nics</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_NetworkAdapter <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #800000;">&quot;MACAddress Like '%'&quot;</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$Computername</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$nicdata</span><span style="color: pink;">=</span><span style="color: #800080;">$nics</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Foreach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$tempHash</span><span style="color: pink;">=@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #000080;">$_</span>.Name;DeviceID<span style="color: pink;">=</span><span style="color: #000080;">$_</span>.DeviceID;AdapterType<span style="color: pink;">=</span><span style="color: #000080;">$_</span>.AdapterType;MACAddress<span style="color: pink;">=</span><span style="color: #000080;">$_</span>.MACAddress<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#get related configuation information</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$config</span><span style="color: pink;">=</span><span style="color: #000080;">$_</span>.GetRelated<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.__CLASS <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;Win32_NetworkadapterConfiguration&quot;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#add to temporary hash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$tempHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;IPAddress&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$config</span>.IPAddress<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$tempHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;IPSubnet&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$config</span>.IPSubnet<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$tempHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DefaultGateway&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$config</span>.DefaultIPGateway<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$tempHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DHCP&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$config</span>.DHCPEnabled<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#convert lease information if found</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$config</span>.DHCPEnabled <span style="color: #FF0000;">-AND</span> <span style="color: #800080;">$config</span>.DHCPLeaseObtained<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$tempHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DHCPLeaseExpires&quot;</span><span style="color: pink;">,</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$config</span>.ConvertToDateTime<span style="color: #000000;">&#40;</span><span style="color: #800080;">$config</span>.DHCPLeaseExpires<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$tempHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DHCPLeaseObtained&quot;</span><span style="color: pink;">,</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$config</span>.ConvertToDateTime<span style="color: #000000;">&#40;</span><span style="color: #800080;">$config</span>.DHCPLeaseObtained<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$tempHash</span>.Add<span style="color: #000000;">&#40;</span><span style="color: #800000;">&quot;DHCPServer&quot;</span><span style="color: pink;">,</span><span style="color: #800080;">$config</span>.DHCPServer<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> PSObject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: #800080;">$tempHash</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Event log errors and warnings in the last $Hours hours</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$last</span><span style="color: pink;">=</span><span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span>.AddHours<span style="color: #000000;">&#40;</span><span style="color: pink;">-</span><span style="color: #800080;">$Hours</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#System Log</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...System Event Log Error/Warning since $last&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$syslog</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-LogName</span> System <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span> <span style="color: pink;">-</span>EntryType Error<span style="color: pink;">,</span>Warning <span style="color: pink;">-</span>After <span style="color: #800080;">$last</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$syslogdata</span><span style="color: pink;">=</span><span style="color: #800080;">$syslog</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> TimeGenerated<span style="color: pink;">,</span>EventID<span style="color: pink;">,</span>Source<span style="color: pink;">,</span>Message<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Application Log</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Application Event Log Error/Warning since $last&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$applog</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-EventLog</span> <span style="color: #008080; font-style: italic;">-LogName</span> Application <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span> <span style="color: pink;">-</span>EntryType Error<span style="color: pink;">,</span>Warning <span style="color: pink;">-</span>After <span style="color: #800080;">$last</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$applogdata</span><span style="color: pink;">=</span><span style="color: #800080;">$applog</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> TimeGenerated<span style="color: pink;">,</span>EventID<span style="color: pink;">,</span>Source<span style="color: pink;">,</span>Message<br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #008000;">#if wmi is ok</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #008000;">#write results depending on parameter set</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$footer</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Report v{3} run {0} by {1}\{2}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span><span style="color: #800080;">$env</span>:USERDOMAIN<span style="color: pink;">,</span><span style="color: #800080;">$env</span>:USERNAME<span style="color: pink;">,</span><span style="color: #800080;">$reportVersion</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0000FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$HTML</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#prepare HTML code</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">=@</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#insert a graphic header with one of the two following lines</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#$fragments+=&quot;&lt;center&gt;&lt;img src='http://jdhitsolutions.com/blog/wp-content/uploads/2011/03/jdhit-blog-header-2.png' /&gt;&lt;/Center&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800000;">&quot;&lt;Img src='http://www.lionking.org/imgarchive/Clip_Art/zazu03.gif' Alt='Zazu' style='float:left' width='120' height='100' hspace=10&gt;&lt;H1&gt; The Morning Report&lt;/H1&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#insert navigation bookmarks</span><br />
<span style="color: #800080;">$nav</span><span style="color: pink;">=@</span><span style="color: #800000;">&quot;<br />
&lt;a href='#Services'&gt;Services&lt;/a&gt;<br />
&lt;a href='#NoAutoStart'&gt;Failed Auto Start&lt;/a&gt;<br />
&lt;a href='#Disks'&gt;Disks&lt;/a&gt;<br />
&lt;a href='#Network'&gt;Network&lt;/a&gt;<br />
&lt;a href='#SysLog'&gt;System Log&lt;/a&gt;<br />
&lt;a href='#AppLog'&gt;Application Log&lt;/a&gt;<br />
&quot;</span><span style="color: pink;">@</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nav</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800000;">&quot;&lt;br clear='All'&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#add a link to the document top</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$nav</span><span style="color: pink;">+=</span><span style="color: #800000;">&quot;<span style="color: #008080; font-weight: bold;">`n</span>&lt;a href='#' target='_top'&gt;Top&lt;/a&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800000;">&quot;&lt;H2&gt;System Summary&lt;/H2&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$osdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-Html</span> <span style="color: #FF0000;">-as</span> List <span style="color: pink;">-</span>Fragment <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$csdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-Html</span> <span style="color: #FF0000;">-as</span> List <span style="color: pink;">-</span>Fragment <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #008080; font-weight: bold;">ConvertTo-Html</span> <span style="color: pink;">-</span>Fragment <span style="color: pink;">-</span>PreContent <span style="color: #800000;">&quot;&lt;H2&gt;&lt;a name='Services'&gt;Services&lt;/a&gt;&lt;/H2&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$services</span>.keys <span style="color: pink;">|</span> <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span> <span style="color: #008080; font-weight: bold;">ConvertTo-Html</span> <span style="color: pink;">-</span>Fragment <span style="color: pink;">-</span>PreContent <span style="color: #800000;">&quot;&lt;H3&gt;$_&lt;/H3&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$services</span>.<span style="color: #000080;">$_</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-HTML</span> <span style="color: pink;">-</span>Fragment<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008000;">#insert navigation link after each section</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nav</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$failedAutoStart</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">,</span>State <span style="color: pink;">|</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #008080; font-weight: bold;">ConvertTo-Html</span> <span style="color: pink;">-</span>Fragment <span style="color: pink;">-</span>PreContent <span style="color: #800000;">&quot;&lt;h3&gt;&lt;a name='NoAutoStart'&gt;Failed Auto Start&lt;/a&gt;&lt;/h3&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nav</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$diskdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-HTML</span> <span style="color: pink;">-</span>Fragment <span style="color: pink;">-</span>PreContent <span style="color: #800000;">&quot;&lt;H2&gt;&lt;a name='Disks'&gt;Disk Utilization&lt;/a&gt;&lt;/H2&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nav</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#convert nested object array properties to strings</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nicdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>DeviceID<span style="color: pink;">,</span>DHCP<span style="color: pink;">*,</span>AdapterType<span style="color: pink;">,</span>MACAddress<span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;IPAddress&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.IPAddress <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;IPSubnet&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.IPSubnet <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;IPGateway&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.DefaultGateway <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span> &nbsp;<span style="color: pink;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">ConvertTo-HTML</span> <span style="color: pink;">-</span>Fragment <span style="color: pink;">-</span>PreContent <span style="color: #800000;">&quot;&lt;H2&gt;&lt;a name='Network'&gt;Network Adapters&lt;/a&gt;&lt;/H2&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nav</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$syslogData</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-HTML</span> <span style="color: pink;">-</span>Fragment <span style="color: pink;">-</span>PreContent <span style="color: #800000;">&quot;&lt;H2&gt;&lt;a name='SysLog'&gt;System Event Log Summary&lt;/a&gt;&lt;/H2&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nav</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$applogData</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">ConvertTo-HTML</span> <span style="color: pink;">-</span>Fragment <span style="color: pink;">-</span>PreContent <span style="color: #800000;">&quot;&lt;H2&gt;&lt;a name='AppLog'&gt;Application Event Log Summary&lt;/a&gt;&lt;/H2&gt;&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$fragments</span><span style="color: pink;">+=</span><span style="color: #800080;">$nav</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800080;">$fragments</span> <span style="color: pink;">|</span> clip<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">ConvertTo-Html</span> <span style="color: #008080; font-style: italic;">-Head</span> <span style="color: #800080;">$head</span> <span style="color: #008080; font-style: italic;">-Title</span> <span style="color: #800080;">$ReportTitle</span> <span style="color: pink;">-</span>PreContent <span style="color: #000000;">&#40;</span><span style="color: #800080;">$fragments</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">out-String</span><span style="color: #000000;">&#41;</span> <span style="color: pink;">-</span>PostContent <span style="color: #800000;">&quot;&lt;br&gt;&lt;I&gt;$footer&lt;/I&gt;&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">elseif</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$TEXT</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#prepare formatted text</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$ReportTitle</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000;">&quot;-&quot;</span><span style="color: pink;">*</span><span style="color: #000000;">&#40;</span><span style="color: #800080;">$ReportTitle</span>.Length<span style="color: #000000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000;">&quot;System Summary&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$osdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$csdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">format-List</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800000;">&quot;Services&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$services</span>.keys <span style="color: pink;">|</span> <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #800080;">$services</span>.<span style="color: #000080;">$_</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">,</span>State<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800000;">&quot;Failed Autostart Services&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$failedAutoStart</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">,</span>State<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800000;">&quot;Disk Utilization&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$diskdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-table</span> <span style="color: #008080; font-style: italic;">-AutoSize</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800000;">&quot;Network Adapters&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$nicdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800000;">&quot;System Event Log Summary&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$syslogdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800000;">&quot;Application Event Log Summary&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$applogdata</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Format-List</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out-String</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write</span> <span style="color: #800080;">$Footer</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Write data to the pipeline as part of a custom object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> PSObject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OperatingSystem<span style="color: pink;">=</span><span style="color: #800080;">$osdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ComputerSystem<span style="color: pink;">=</span><span style="color: #800080;">$csdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Services<span style="color: pink;">=</span><span style="color: #800080;">$services</span>.keys <span style="color: pink;">|</span> <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$services</span>.<span style="color: #000080;">$_</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">,</span>State<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FailedAutoStart<span style="color: pink;">=</span><span style="color: #800080;">$failedAutoStart</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">,</span>State<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Disks<span style="color: pink;">=</span><span style="color: #800080;">$diskData</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Network<span style="color: pink;">=</span><span style="color: #800080;">$nicData</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SystemLog<span style="color: pink;">=</span><span style="color: #800080;">$syslogdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ApplicationLog<span style="color: pink;">=</span><span style="color: #800080;">$applogdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReportVersion<span style="color: pink;">=</span><span style="color: #800080;">$reportVersion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RunDate<span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Date</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RunBy<span style="color: pink;">=</span><span style="color: #800000;">&quot;$env:USERDOMAIN\$env:USERNAME&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #000000;">&#125;</span> <span style="color: #008000;">#if OK</span><br />
<br />
<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">#can't ping computer so fail</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Warning</span> <span style="color: #800000;">&quot;Failed to ping $computername&quot;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>As you can see, it is a lengthy script, but I&#8217;ve tried to include a fair amount of internal comments and documentation, so I won&#8217;t repeat it here, but I will touch on a few key points.</p>
<p>First, I&#8217;m embedding a style sheet directly in any HTML output so any files I create can stand alone. You could certainly modify the relevant sections and use the -CSSUri parameter with ConvertTo-HTML.  Next, I use a combination of Test-Connection and Try/Catch to handle computers that are offline or I can&#8217;t access. This speeds up the script and makes it nicer for the script user.  Assuming all is good, I create a number of variables that hold the WMI information I am interested in.</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">...<br />
<span style="color: #008000;">#OS Summary</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Operating System&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$osdata</span><span style="color: pink;">=</span><span style="color: #800080;">$os</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Computername&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.CSName<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;OS&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.Caption<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;ServicePack&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.CSDVersion<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; free<span style="color: pink;">*</span>memory<span style="color: pink;">,</span>totalv<span style="color: pink;">*,</span>NumberOfProcesses<span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;LastBoot&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.ConvertToDateTime<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.LastBootupTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><span style="color: pink;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Uptime&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: #000000;">&#40;</span><span style="color: #000080;">$_</span>.ConvertToDateTime<span style="color: #000000;">&#40;</span><span style="color: #000080;">$_</span>.LastBootupTime<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Computer system</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Write-Host</span> <span style="color: #800000;">&quot;...Computer System&quot;</span> <span style="color: #008080; font-style: italic;">-ForegroundColor</span> Cyan<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$cs</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-WmiObject</span> <span style="color: #008080; font-style: italic;">-Class</span> Win32_Computersystem <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computername</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800080;">$csdata</span><span style="color: pink;">=</span><span style="color: #800080;">$cs</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Status<span style="color: pink;">,</span>Manufacturer<span style="color: pink;">,</span>Model<span style="color: pink;">,</span>SystemType<span style="color: pink;">,</span>Number<span style="color: pink;">*</span><br />
...</div></div>
<p>After everything is collected, then I can write output using an If/ElseIf statement depending on what parameters were passed. If no parameters were specified then a custom object is assembled and written to the pipeline.</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;<span style="color: #0000FF;">else</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">#Write data to the pipeline as part of a custom object</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">New-Object</span> <span style="color: #008080; font-style: italic;">-TypeName</span> PSObject <span style="color: #008080; font-style: italic;">-Property</span> <span style="color: pink;">@</span><span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;OperatingSystem<span style="color: pink;">=</span><span style="color: #800080;">$osdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ComputerSystem<span style="color: pink;">=</span><span style="color: #800080;">$csdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Services<span style="color: pink;">=</span><span style="color: #800080;">$services</span>.keys <span style="color: pink;">|</span> <span style="color: #0000FF;">foreach</span> <span style="color: #000000;">&#123;</span><span style="color: #800080;">$services</span>.<span style="color: #000080;">$_</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">,</span>State<span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FailedAutoStart<span style="color: pink;">=</span><span style="color: #800080;">$failedAutoStart</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Select</span> Name<span style="color: pink;">,</span>Displayname<span style="color: pink;">,</span>StartMode<span style="color: pink;">,</span>State<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Disks<span style="color: pink;">=</span><span style="color: #800080;">$diskData</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Network<span style="color: pink;">=</span><span style="color: #800080;">$nicData</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SystemLog<span style="color: pink;">=</span><span style="color: #800080;">$syslogdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ApplicationLog<span style="color: pink;">=</span><span style="color: #800080;">$applogdata</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;ReportVersion<span style="color: pink;">=</span><span style="color: #800080;">$reportVersion</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RunDate<span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">Get-Date</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;RunBy<span style="color: pink;">=</span><span style="color: #800000;">&quot;$env:USERDOMAIN\$env:USERNAME&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span></div></div>
<p>But perhaps you&#8217;d like to see this in action. Here&#8217;s a sample HTML <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL1NhbXBsZVJlcG9ydC5odG1s" target='_blank'>SampleReport</a>. In this report, there are no recent errors or warnings in the Application event log. </p>
<p>Or if you have a few minutes, here&#8217;s a short clip of the script in action.</p>
<p><iframe width="560" height="315" src="http://www.youtube.com/embed/EuQXGNZ716g" frameborder="0" allowfullscreen></iframe></p>
<p>I hope you find this a useful jumping off point for your own script, although I think I&#8217;ve already worked out information you are most likely interested in. Download <a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL01vcm5pbmdSZXBvcnQudHh0">MorningReport.ps1</a> and try it out 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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVRoZStQb3dlclNoZWxsK01vcm5pbmcrUmVwb3J0K2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjAxJTJGdGhlLXBvd2Vyc2hlbGwtbW9ybmluZy1yZXBvcnQlMkY=" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3RoZS1wb3dlcnNoZWxsLW1vcm5pbmctcmVwb3J0LyZhbXA7aGVhZGxpbmU9VGhlK1Bvd2VyU2hlbGwrTW9ybmluZytSZXBvcnQ=" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdGhlLXBvd2Vyc2hlbGwtbW9ybmluZy1yZXBvcnQvJmFtcDt0aXRsZT1UaGUrUG93ZXJTaGVsbCtNb3JuaW5nK1JlcG9ydA==" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdGhlLXBvd2Vyc2hlbGwtbW9ybmluZy1yZXBvcnQvJmFtcDt0aXRsZT1UaGUrUG93ZXJTaGVsbCtNb3JuaW5nK1JlcG9ydA==" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdGhlLXBvd2Vyc2hlbGwtbW9ybmluZy1yZXBvcnQvJmFtcDt0PVRoZStQb3dlclNoZWxsK01vcm5pbmcrUmVwb3J0" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1UaGUrUG93ZXJTaGVsbCtNb3JuaW5nK1JlcG9ydCZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS90aGUtcG93ZXJzaGVsbC1tb3JuaW5nLXJlcG9ydC8=" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdGhlLXBvd2Vyc2hlbGwtbW9ybmluZy1yZXBvcnQvJmFtcDtpbWFnZXVybD0=" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1UaGUrUG93ZXJTaGVsbCtNb3JuaW5nK1JlcG9ydCZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS90aGUtcG93ZXJzaGVsbC1tb3JuaW5nLXJlcG9ydC8=" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS90aGUtcG93ZXJzaGVsbC1tb3JuaW5nLXJlcG9ydC8mYW1wO3RpdGxlPVRoZStQb3dlclNoZWxsK01vcm5pbmcrUmVwb3J0" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdGhlLXBvd2Vyc2hlbGwtbW9ybmluZy1yZXBvcnQvJmFtcDt0aXRsZT1UaGUrUG93ZXJTaGVsbCtNb3JuaW5nK1JlcG9ydA==" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3RoZS1wb3dlcnNoZWxsLW1vcm5pbmctcmVwb3J0LyZhbXA7dGl0bGU9VGhlK1Bvd2VyU2hlbGwrTW9ybmluZytSZXBvcnQ=" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS90aGUtcG93ZXJzaGVsbC1tb3JuaW5nLXJlcG9ydC8=" 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=1977" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/Z6ZL8ZguOCShgknFrzCX215whLU/0/da"><img src="http://feedads.g.doubleclick.net/~a/Z6ZL8ZguOCShgknFrzCX215whLU/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/Z6ZL8ZguOCShgknFrzCX215whLU/1/da"><img src="http://feedads.g.doubleclick.net/~a/Z6ZL8ZguOCShgknFrzCX215whLU/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/5h-K06-T1gc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/the-powershell-morning-report/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/the-powershell-morning-report/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=the-powershell-morning-report</feedburner:origLink></item>
		<item>
		<title>Friday Fun What’s My Variable</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/4F9Qt3Dbs5E/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/friday-fun-whats-my-variable/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 16:32:25 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[Friday Fun]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[FridayFun]]></category>
		<category><![CDATA[Get-variable]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[Type]]></category>
		<category><![CDATA[Variable]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=1962</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
I use scriptblocks quite a bit in my PowerShell work, often saved as variables. These are handy for commands you want to run again, but don&#8217;t necessarily need to turn into permanent functions. $freec=&#123;&#40;get-wmiobject win32_logicaldisk -filter &#34;deviceid='c:'&#34; -property Freespace&#41;.FreeSpace/1mb&#125; Now &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/friday-fun-whats-my-variable/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#leftcontainerBox {
	float:left;
	position: fixed;
	top: 60%;
	left: 70px;
}
#leftcontainerBox .buttons {
	float:left;
	clear:both;
	margin:4px 4px 4px 4px;
	padding-bottom:2px;
}
#bottomcontainerBox {
	width: 50%;
	padding-top: 1px;
}
#bottomcontainerBox .buttons {
	float: left;
	margin: 4px 4px 4px 4px;
}
</style>
<p>I use scriptblocks quite a bit in my PowerShell work, often saved as variables. These are handy for commands you want to run again, but don&#8217;t necessarily need to turn into permanent functions.</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;">$freec</span><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-wmiobject</span> win32_logicaldisk <span style="color: pink;">-</span><span style="color: #0000FF;">filter</span> <span style="color: #800000;">&quot;deviceid='c:'&quot;</span> <span style="color: #008080; font-style: italic;">-property</span> Freespace<span style="color: #000000;">&#41;</span>.FreeSpace<span style="color: pink;">/</span>1mb<span style="color: #000000;">&#125;</span></div></div>
<p>Now in PowerShell I can invoke the scriptblock.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; &amp;$freec<br />
94079.72265625</div></div>
<p>Ok then. I have a number of these defined. I decided I wanted an easy way to identify them when I run Get-Variable. For example, if I remembered all the variable names I could just do this:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; get-variable freec,dirt<br />
<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Value<br />
---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -----<br />
freec &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(gwmi win32_logicaldisk -filter &quot;deviceid='c:...<br />
dirt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Param([string]$Path=$env:temp) Get-ChildItem ...</div></div>
<p>But needless to say that&#8217;s asking too much. When I first looked at this problem I went down the path of trying to parse values I saw with Get-Variable to identify potential script blocks. Then I realized this was a rookie mistake. PowerShell is all about the objects. Now a variable is also an object with a value property. This value could be a string, and integer or a pscredential. So my task then was to identify each value <em>type</em>.</p>
<p>Every object in PowerShell has a built in method called GetType().</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $s=get-service spooler<br />
PS S:\&gt; $s.GetType()<br />
<br />
IsPublic IsSerial Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BaseType<br />
-------- -------- ---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --------<br />
True &nbsp; &nbsp; False &nbsp; &nbsp;ServiceController &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;System.ComponentM...</div></div>
<p>This is actually another object with a Name property.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; $s.GetType().name<br />
ServiceController</div></div>
<p>Aha! Let&#8217;s look at this with my variable.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS S:\&gt; (get-variable freec).value.GetType().Name<br />
ScriptBlock</div></div>
<p>This is a one-line shortcut that gets the Value property of the Freec variable and then runs the GetType() method followed by retrieving just the Name property. This is promising.  Here&#8217;s one way I can use 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-variable</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.value.GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;ScriptBlock&quot;</span><span style="color: #000000;">&#125;</span></div></div>
<p>As you can see there is still an issue with variables with no values.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2dldC12YXJpYWJsZXR5cGUtMS5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/get-variabletype-1-300x197.png" alt="" title="get-variabletype-1" width="300" height="197" class="aligncenter size-medium wp-image-1963" /></a></p>
<p>I&#8217;ll just add another condition to my Where 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-variable</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">Where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.value <span style="color: #FF0000;">-AND</span> <span style="color: #000080;">$_</span>.value.GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Name <span style="color: #FF0000;">-eq</span> <span style="color: #800000;">&quot;ScriptBlock&quot;</span><span style="color: #000000;">&#125;</span></div></div>
<p>Success!</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2dldC12YXJpYWJsZXR5cGUtMi5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/get-variabletype-2-300x116.png" alt="" title="get-variabletype-2" width="300" height="116" class="aligncenter size-medium wp-image-1964" /></a></p>
<p>These are in fact all of the scriptblocks in my current session. But now I can take this a step further and look at my other variables and their type.</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-variable</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Name<span style="color: pink;">,@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Type&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.value.GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Name<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span></div></div>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2dldC12YXJpYWJsZXR5cGUtMy5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/get-variabletype-3-300x185.png" alt="" title="get-variabletype-3" width="300" height="185" class="aligncenter size-medium wp-image-1965" /></a></p>
<p>Or I might try grouping.</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-variable</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">select</span> Name<span style="color: pink;">,@</span><span style="color: #000000;">&#123;</span>Name<span style="color: pink;">=</span><span style="color: #800000;">&quot;Type&quot;</span>;Expression<span style="color: pink;">=</span><span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.value.GetType<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.Name<span style="color: #000000;">&#125;</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #0000FF;">where</span> <span style="color: #000000;">&#123;</span><span style="color: #000080;">$_</span>.<span style="color: #008080; font-weight: bold;">type</span><span style="color: #000000;">&#125;</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Group</span> <span style="color: #008080; font-weight: bold;">Type</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Sort</span> Count <span style="color: #008080; font-style: italic;">-Descending</span></div></div>
<p>I wanted to filter out empty values so I&#8217;m only keeping objects that have a defined type in my grouped output.</p>
<p><a href="http://jdhitsolutions.com/blog/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDEyLzAxL2dldC12YXJpYWJsZXR5cGUtNC5wbmcjdXRtX3NvdXJjZT1mZWVkJmFtcDt1dG1fbWVkaXVtPWZlZWQmYW1wO3V0bV9jYW1wYWlnbj1mZWVk"><img src="http://jdhitsolutions.com/blog/wp-content/uploads/2012/01/get-variabletype-4-300x185.png" alt="" title="get-variabletype-4" width="300" height="185" class="aligncenter size-medium wp-image-1966" /></a></p>
<p>The bottom line is never forget about the object!</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PUZyaWRheStGdW4rV2hhdCVFMiU4MCU5OXMrTXkrVmFyaWFibGUraHR0cCUzQSUyRiUyRmpkaGl0c29sdXRpb25zLmNvbSUyRmJsb2clMkYyMDEyJTJGMDElMkZmcmlkYXktZnVuLXdoYXRzLW15LXZhcmlhYmxlJTJG" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4td2hhdHMtbXktdmFyaWFibGUvJmFtcDtoZWFkbGluZT1GcmlkYXkrRnVuK1doYXQlRTIlODAlOTlzK015K1ZhcmlhYmxl" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi13aGF0cy1teS12YXJpYWJsZS8mYW1wO3RpdGxlPUZyaWRheStGdW4rV2hhdCVFMiU4MCU5OXMrTXkrVmFyaWFibGU=" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi13aGF0cy1teS12YXJpYWJsZS8mYW1wO3RpdGxlPUZyaWRheStGdW4rV2hhdCVFMiU4MCU5OXMrTXkrVmFyaWFibGU=" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi13aGF0cy1teS12YXJpYWJsZS8mYW1wO3Q9RnJpZGF5K0Z1bitXaGF0JUUyJTgwJTk5cytNeStWYXJpYWJsZQ==" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1GcmlkYXkrRnVuK1doYXQlRTIlODAlOTlzK015K1ZhcmlhYmxlJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4td2hhdHMtbXktdmFyaWFibGUv" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi13aGF0cy1teS12YXJpYWJsZS8mYW1wO2ltYWdldXJsPQ==" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1GcmlkYXkrRnVuK1doYXQlRTIlODAlOTlzK015K1ZhcmlhYmxlJmFtcDtsaW5rPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4td2hhdHMtbXktdmFyaWFibGUv" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLXdoYXRzLW15LXZhcmlhYmxlLyZhbXA7dGl0bGU9RnJpZGF5K0Z1bitXaGF0JUUyJTgwJTk5cytNeStWYXJpYWJsZQ==" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvZnJpZGF5LWZ1bi13aGF0cy1teS12YXJpYWJsZS8mYW1wO3RpdGxlPUZyaWRheStGdW4rV2hhdCVFMiU4MCU5OXMrTXkrVmFyaWFibGU=" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL2ZyaWRheS1mdW4td2hhdHMtbXktdmFyaWFibGUvJmFtcDt0aXRsZT1GcmlkYXkrRnVuK1doYXQlRTIlODAlOTlzK015K1ZhcmlhYmxl" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS9mcmlkYXktZnVuLXdoYXRzLW15LXZhcmlhYmxlLw==" 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=1962" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/6HnsZ6RNZEdfVRcRlHFoeJLtmrA/0/da"><img src="http://feedads.g.doubleclick.net/~a/6HnsZ6RNZEdfVRcRlHFoeJLtmrA/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/6HnsZ6RNZEdfVRcRlHFoeJLtmrA/1/da"><img src="http://feedads.g.doubleclick.net/~a/6HnsZ6RNZEdfVRcRlHFoeJLtmrA/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/4F9Qt3Dbs5E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/friday-fun-whats-my-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/friday-fun-whats-my-variable/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=friday-fun-whats-my-variable</feedburner:origLink></item>
		<item>
		<title>Using Start-Job as a Scheduled Task</title>
		<link>http://feedproxy.google.com/~r/JeffsScriptingBlogAndMore/~3/yw0srQhgHlQ/</link>
		<comments>http://jdhitsolutions.com/blog/2012/01/using-start-job-as-a-scheduled-task/#comments</comments>
		<pubDate>Thu, 05 Jan 2012 15:54:41 +0000</pubDate>
		<dc:creator>Jeffery Hicks</dc:creator>
				<category><![CDATA[PowerShell v2.0]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Invoke-Command]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[remoting]]></category>
		<category><![CDATA[Start-Job]]></category>
		<category><![CDATA[Tasks]]></category>

		<guid isPermaLink="false">http://jdhitsolutions.com/blog/?p=1956</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 a technique you might want to use for ad hoc troubleshooting or reporting. Even though it is possible to set up scheduled tasks to run PowerShell commands or scripts, it is cumbersome and time consuming. PowerShell v3 offers a &#8230; <a href="http://jdhitsolutions.com/blog/2012/01/using-start-job-as-a-scheduled-task/">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 a technique you might want to use for ad hoc troubleshooting or reporting. Even though it is possible to set up scheduled tasks to run PowerShell commands or scripts, it is cumbersome and time consuming. PowerShell v3 offers a great alternative, but I&#8217;ll cover that another day. Suppose I want to do something every 15 minutes such as check the status of a service. Instead of going through the effort of creating a scheduled task, I&#8217;ll create a PowerShell job.</p>
<p>If I setup a job, it will run in my PowerShell session for as long as it needs to run or until I close my PowerShell session. Thus the trick is to keep the job running which easy to accomplish with a simple 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: #0000FF;">While</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #008000;">#do something</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>This will loop indefinitely because True is always True. In an interactive session, I can break out of this using Ctrl+C or insert code to break out if some condition is met.  If I use this loop in my Start-Job command, the command will run indefinitely until the job terminates. I can always kill the job with the Stop-Job cmdlet.  Although I suppose you should be careful with the code you put in the While loop as part of job because if you use Stop-Job, there&#8217;s no way of knowing what code might be executing at the time. But for my use of this technique I&#8217;m keeping it simple and quick.</p>
<p>The other part is the timing interval. This is easily accomplished using the Start-Sleep cmdlet and specifying a value in milliseconds, or more typically, seconds. Depending on your task you could also take advantage of eventing, but that too is a bit complicated to setup and tear down. So, now the main part of my While loop looks 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;">While</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; <span style="color: #008000;">#do something</span><br />
&nbsp;<span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-seconds</span> <span style="color: #804000;">900</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>My code will run every 900 seconds (15 minutes). Here&#8217;s a longer example that I put in a script.</p>
<div class="codecolorer-container powershell geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="powershell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #800080;">$file</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;c:\work\mylog.txt&quot;</span><br />
<span style="color: #008000;">#the number of seconds to pause between checks</span><br />
<span style="color: #800080;">$seconds</span><span style="color: pink;">=</span><span style="color: #804000;">600</span><br />
<span style="color: #008000;">#the service to check</span><br />
<span style="color: #800080;">$service</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;Spooler&quot;</span><br />
<span style="color: #008000;">#the computer to check</span><br />
<span style="color: #800080;">$computer</span><span style="color: pink;">=</span><span style="color: #800080;">$env</span>:computername<br />
<br />
<span style="color: #0000FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #800080;">$True</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$s</span><span style="color: pink;">=</span><span style="color: #008080; font-weight: bold;">get-service</span> <span style="color: #800080;">$service</span> <span style="color: #008080; font-style: italic;">-ComputerName</span> <span style="color: #800080;">$computer</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$t</span><span style="color: pink;">=</span><span style="color: #800000;">&quot;{0} Service {1} on {3} has a status of {2}&quot;</span> <span style="color: #FF0000;">-f</span> <span style="color: #000000;">&#40;</span><span style="color: #008080; font-weight: bold;">Get-Date</span><span style="color: #000000;">&#41;</span><span style="color: pink;">,</span> <span style="color: #800080;">$s</span>.name<span style="color: pink;">,</span><span style="color: #800080;">$s</span>.status<span style="color: pink;">,</span><span style="color: #800080;">$computer</span><br />
&nbsp; &nbsp; <span style="color: #800080;">$t</span> <span style="color: pink;">|</span> <span style="color: #008080; font-weight: bold;">Out<span style="color: #FF0000;">-File</span></span> <span style="color: #008080; font-style: italic;">-FilePath</span> <span style="color: #800080;">$file</span> <span style="color: #008080; font-style: italic;">-Append</span><br />
&nbsp; &nbsp; <span style="color: #008080; font-weight: bold;">Start-Sleep</span> <span style="color: #008080; font-style: italic;">-seconds</span> <span style="color: #800080;">$seconds</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>I could have put all of that into a script block and created the job, or I could use the script.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; start-job -FilePath C:\scripts\PollService.ps1</div></div>
<p>The job will write the service status information to a local text file every 10 minutes.  When I&#8217;m done I can simply my PowerShell session or run Stop-Job. Here&#8217;s where it can really get interesting: how about running this &#8220;scheduled task&#8221; ON a remote computer? There are two approaches. It depends on where you want the job to live.  I could keep the job on my computer:</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; invoke-command -FilePath C:\scripts\PollService.ps1 -ComputerName quark -asjob<br />
PS C:\&gt; get-job 3 | format-list<br />
<br />
<br />
HasMoreData &nbsp; : True<br />
StatusMessage :<br />
Location &nbsp; &nbsp; &nbsp;: quark<br />
Command &nbsp; &nbsp; &nbsp; : #requires -version 2.0<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $file=&quot;c:\work\mylog.txt&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #the number of seconds to pause between checks<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $seconds=600<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; #the service to check<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $service=&quot;Spooler&quot;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $computer=$env:computername<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while ($True) {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $s=get-service $service -ComputerName $computer<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $t=&quot;{0} Service {1} on {3} has a status of {2}&quot; -f (Get-Date),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $s.name,$s.status,$computer<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $t | Out-File -FilePath $file -Append<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Start-Sleep -seconds $seconds<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br />
JobStateInfo &nbsp;: Running<br />
Finished &nbsp; &nbsp; &nbsp;: System.Threading.ManualResetEvent<br />
InstanceId &nbsp; &nbsp;: 03a48cd0-f21a-4b7d-9a78-f148ec784ff8<br />
Id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: 3<br />
Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;: Job3<br />
ChildJobs &nbsp; &nbsp; : {Job4}<br />
Output &nbsp; &nbsp; &nbsp; &nbsp;: {}<br />
Error &nbsp; &nbsp; &nbsp; &nbsp; : {}<br />
Progress &nbsp; &nbsp; &nbsp;: {}<br />
Verbose &nbsp; &nbsp; &nbsp; : {}<br />
Debug &nbsp; &nbsp; &nbsp; &nbsp; : {}<br />
Warning &nbsp; &nbsp; &nbsp; : {}<br />
State &nbsp; &nbsp; &nbsp; &nbsp; : Running</div></div>
<p>The job object is on my (local) computer, even though the task is running on the remote computer. The other approach is to put the job ON the remote computer. This is a little trickier since I have to get the code I want to run ON the remote computer. I could copy the script over. Or I might try something like this:</p>
<p>First I want to convert my script into a scriptblock by stripping out the comments and inserting a semi colon at the end of each line. Then I can create a scriptblock from this text on the remote computer.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; $text=get-content C:\scripts\PollService.ps1 | where {$_ -notmatch &quot;^#&quot; -AND $_} | foreach {&quot;$_;&quot;}</div></div>
<p>I can pass this text as a parameter with invoke-command to setup a job on the remote computer. I recommend using a PSSession in case you want to go back later and stop the job.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; $quark=new-pssession -comp quark<br />
PS C:\&gt; invoke-command -scriptblock {param ($txt) $sb=$executioncontext.invokecommand.newscriptblock($txt) ; Start-job -scriptblock $sb } -session $quark -ArgumentList ($text | out-string)</div></div>
<p>The job is created on the remote session and runs indefinitely.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; invoke-command {get-job -State Running} -Session $quark<br />
<br />
WARNING: 2 columns do not fit into the display and were removed.<br />
<br />
Id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;State &nbsp; &nbsp; &nbsp;HasMoreData &nbsp; &nbsp; Location<br />
-- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;----- &nbsp; &nbsp; &nbsp;----------- &nbsp; &nbsp; --------<br />
17 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Job17 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Running &nbsp; &nbsp;True &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;localhost<br />
PS C:\&gt; invoke-command {get-content C:\work\mylog.txt} -Session $quark<br />
1/5/2012 9:37:41 AM Service Spooler on QUARK has a status of Running<br />
1/5/2012 9:38:46 AM Service Spooler on QUARK has a status of Running<br />
1/5/2012 10:44:54 AM Service Spooler on QUARK has a status of Running</div></div>
<p>As I mentioned there are probably several ways you could do this. When I am finished I can either terminate the PSSession or stop the remote job.</p>
<div class="codecolorer-container text geshi" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">PS C:\&gt; invoke-command {stop-job -State Running -PassThru} -Session $quark<br />
<br />
WARNING: 2 columns do not fit into the display and were removed.<br />
<br />
Id &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;State &nbsp; &nbsp; &nbsp;HasMoreData &nbsp; &nbsp; Location<br />
-- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;---- &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;----- &nbsp; &nbsp; &nbsp;----------- &nbsp; &nbsp; --------<br />
17 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Job17 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stopped &nbsp; &nbsp;False &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; localhost</div></div>
<p>So the next time you need some scheduled PowerShell, at least on a temporary basis, take a look at Start-Job.</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=aHR0cDovL3R3aXR0ZXIuY29tL2ludGVudC90d2VldD90ZXh0PVVzaW5nK1N0YXJ0LUpvYithcythK1NjaGVkdWxlZCtUYXNrK2h0dHAlM0ElMkYlMkZqZGhpdHNvbHV0aW9ucy5jb20lMkZibG9nJTJGMjAxMiUyRjAxJTJGdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2slMkY=" 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/dGFyZ2V0VXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3VzaW5nLXN0YXJ0LWpvYi1hcy1hLXNjaGVkdWxlZC10YXNrLyZhbXA7aGVhZGxpbmU9VXNpbmcrU3RhcnQtSm9iK2FzK2ErU2NoZWR1bGVkK1Rhc2s=" 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=aHR0cDovL2RlbGljaW91cy5jb20vcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2svJmFtcDt0aXRsZT1Vc2luZytTdGFydC1Kb2IrYXMrYStTY2hlZHVsZWQrVGFzaw==" 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=aHR0cDovL2RpZ2cuY29tL3N1Ym1pdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2svJmFtcDt0aXRsZT1Vc2luZytTdGFydC1Kb2IrYXMrYStTY2hlZHVsZWQrVGFzaw==" 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=aHR0cDovL3d3dy5mYWNlYm9vay5jb20vc2hhcmUucGhwP3U9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2svJmFtcDt0PVVzaW5nK1N0YXJ0LUpvYithcythK1NjaGVkdWxlZCtUYXNr" 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=aHR0cDovL3d3dy5mcmllbmRmZWVkLmNvbS9zaGFyZT90aXRsZT1Vc2luZytTdGFydC1Kb2IrYXMrYStTY2hlZHVsZWQrVGFzayZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy1zdGFydC1qb2ItYXMtYS1zY2hlZHVsZWQtdGFzay8=" 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=aHR0cDovL3d3dy5nb29nbGUuY29tL2J1enovcG9zdD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2svJmFtcDtpbWFnZXVybD0=" 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=aHR0cDovL3BpbmcuZm0vcmVmLz9tZXRob2Q9bWljcm9ibG9nJmFtcDt0aXRsZT1Vc2luZytTdGFydC1Kb2IrYXMrYStTY2hlZHVsZWQrVGFzayZhbXA7bGluaz1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy1zdGFydC1qb2ItYXMtYS1zY2hlZHVsZWQtdGFzay8=" 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=aHR0cDovL3JlZGRpdC5jb20vc3VibWl0P3VybD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy1zdGFydC1qb2ItYXMtYS1zY2hlZHVsZWQtdGFzay8mYW1wO3RpdGxlPVVzaW5nK1N0YXJ0LUpvYithcythK1NjaGVkdWxlZCtUYXNr" 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=aHR0cDovL3NsYXNoZG90Lm9yZy9ib29rbWFyay5wbD91cmw9aHR0cDovL2pkaGl0c29sdXRpb25zLmNvbS9ibG9nLzIwMTIvMDEvdXNpbmctc3RhcnQtam9iLWFzLWEtc2NoZWR1bGVkLXRhc2svJmFtcDt0aXRsZT1Vc2luZytTdGFydC1Kb2IrYXMrYStTY2hlZHVsZWQrVGFzaw==" 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/dXJsPWh0dHA6Ly9qZGhpdHNvbHV0aW9ucy5jb20vYmxvZy8yMDEyLzAxL3VzaW5nLXN0YXJ0LWpvYi1hcy1hLXNjaGVkdWxlZC10YXNrLyZhbXA7dGl0bGU9VXNpbmcrU3RhcnQtSm9iK2FzK2ErU2NoZWR1bGVkK1Rhc2s=" 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=aHR0cDovL3RlY2hub3JhdGkuY29tL2ZhdmVzP2FkZD1odHRwOi8vamRoaXRzb2x1dGlvbnMuY29tL2Jsb2cvMjAxMi8wMS91c2luZy1zdGFydC1qb2ItYXMtYS1zY2hlZHVsZWQtdGFzay8=" 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=1956" width="1" height="1" style="display: none;" />
<p><a href="http://feedads.g.doubleclick.net/~a/9JHaT4LytkQF9hk5P8360X6ZDHM/0/da"><img src="http://feedads.g.doubleclick.net/~a/9JHaT4LytkQF9hk5P8360X6ZDHM/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/9JHaT4LytkQF9hk5P8360X6ZDHM/1/da"><img src="http://feedads.g.doubleclick.net/~a/9JHaT4LytkQF9hk5P8360X6ZDHM/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/JeffsScriptingBlogAndMore/~4/yw0srQhgHlQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://jdhitsolutions.com/blog/2012/01/using-start-job-as-a-scheduled-task/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://jdhitsolutions.com/blog/2012/01/using-start-job-as-a-scheduled-task/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=using-start-job-as-a-scheduled-task</feedburner:origLink></item>
	</channel>
</rss><!-- Dynamic page generated in 8.546 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-01-31 11:23:53 -->

