<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PowerShell Station</title>
	<atom:link href="http://powershellstation.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://powershellstation.com</link>
	<description>Mike&#039;s PowerShell Musings</description>
	<lastBuildDate>Thu, 05 Apr 2012 03:05:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>A Remoting Issue with PowerShell 3 Beta</title>
		<link>http://powershellstation.com/2012/04/05/a-remoting-issue-with-powershell-3-beta/</link>
		<comments>http://powershellstation.com/2012/04/05/a-remoting-issue-with-powershell-3-beta/#comments</comments>
		<pubDate>Thu, 05 Apr 2012 03:05:09 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[3.0 Beta]]></category>
		<category><![CDATA[PSRemoting]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=411</guid>
		<description><![CDATA[I&#8217;ve been doing some thinking about PowerShell Remoting for a project at work and realized that I hadn&#8217;t ever set up remoting on my &#8220;home&#8221; laptop. I&#8217;m not in a domain, so remoting configuration is a bit different. In any case, I would be using the same machine as source and target of the remoting [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing some thinking about PowerShell Remoting for a project at work and realized that I hadn&#8217;t ever set up remoting on my &#8220;home&#8221; laptop.  I&#8217;m not in a domain, so remoting configuration is a bit different.  In any case, I would be using the same machine as source and target of the remoting call, so how could it go wrong?</p>
<p>First of all, VMWare had set up some network adapters and placed them in a public profile.  Enable-PSRemoting doesn&#8217;t like that.  It was an easy google (bing?) to fix and Enable-PSRemoting succeeded.</p>
<p>I then issued this:</p>
<pre class="brush:powershell">
invoke-command -scriptblock { get-process | select-object -first 10  } -computer  localhost
</pre>
<p>Imagine my surprise when the result was this:</p>
<pre>
Could not find file 'C:\Windows\System32\WindowsPowerShell\v1.0\Event.Format.ps1xml'.
    + CategoryInfo          : OpenError: (:) [], RemoteException
    + FullyQualifiedErrorId : PSSessionStateBroken
</pre>
<p>I searched the internet for this, but only found one hit that was close, and that was <a href="http://nuget.codeplex.com/workitem/2016" title="a bug report">a bug report</a> for <a href="http://nuget.codeplex.com/" title="nuget">nuget</a>.</p>
<p>It seems like the powershell engine that is running the remote payload is looking for a formatting file that doesn&#8217;t exist.  To work around this, I simply copied an existing Format.ps1xml file (I chose Registry.format.ps1xml because it was the smallest), removed the signature from it, and changed the name of the view (so it wouldn&#8217;t change any output).</p>
<p>It&#8217;s not a big bug, and it&#8217;s a beta so I&#8217;m not worried.  Just thought I&#8217;d share my workaround.</p>
<p>-Mike</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2012%2F04%2F05%2Fa-remoting-issue-with-powershell-3-beta%2F&amp;title=A%20Remoting%20Issue%20with%20PowerShell%203%20Beta" id="wpa2a_2"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2012/04/05/a-remoting-issue-with-powershell-3-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Speeding up Powershell Webcast by Dr. Tobias Weltner</title>
		<link>http://powershellstation.com/2012/03/13/speeding-up-powershell-webcast-by-dr-tobias-weltner/</link>
		<comments>http://powershellstation.com/2012/03/13/speeding-up-powershell-webcast-by-dr-tobias-weltner/#comments</comments>
		<pubDate>Tue, 13 Mar 2012 04:06:50 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=399</guid>
		<description><![CDATA[If you&#8217;ve done much looking around, you know that there&#8217;s an awful lot of great information about PowerShell available on the web. The community that has formed around this product is one of its strengths. You&#8217;re probably familiar with the name Tobias Weltner. His Master-PowerShell e-book has long been a resource that I&#8217;ve turned to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve done much looking around, you know that there&#8217;s an awful lot of great information about PowerShell available on the web.  The community that has formed around this product is one of its strengths.  You&#8217;re probably familiar with the name Tobias Weltner.  His <a href="http://powershell.com/cs/blogs/ebook/" title="Master-PowerShell">Master-PowerShell</a> e-book has long been a resource that I&#8217;ve turned to for examples and explanations.  I recently watched a webcast that Dr. Weltner did as part of a series of webcasts at <a href="http://idera.com" title="Idera.com">idera.com</a>.  The title of the webcast is <a href="http://www.idera.com/Events/RegisterWC.aspx?EventID=297" title="Speeding up PowerShell: Multithreading">&#8220;Speeding up PowerShell: Multithreading&#8221;</a>.  When I got the announcement, I thought it was going to be about using the [System.Threading] namespace.  Boy, was I wrong.</p>
<p>The talk starts off with discussing times when it might make sense to avoid using the pipeline.  Once you see the material, it&#8217;s makes perfect sense.  He then moves to using PowerShell jobs to perform tasks, discussing the pros and cons of that approach.  Finally, he talks about using the Runspace class to run separate PowerShell instances.  It uses the classes, but still manages to be very readable, very approachable PowerShell.  He provides several examples in each section (including a function that executes a PowerShell scriptblock with a timeout, something I&#8217;ve never seen before).</p>
<p>All in all, this was easily the best webcast on PowerShell I&#8217;ve ever watched.  Unlike most Powershell videos I&#8217;ve seen, it wasn&#8217;t targeting a beginner, but someone who already knows the basics of scripting and wants to learn more.  The techniques he presents are, as I have said, very straightforward and explained very well.  I can already think of several examples of code that I&#8217;m probably going to be writing in the near future based on this presentation.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2012%2F03%2F13%2Fspeeding-up-powershell-webcast-by-dr-tobias-weltner%2F&amp;title=Speeding%20up%20Powershell%20Webcast%20by%20Dr.%20Tobias%20Weltner" id="wpa2a_4"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2012/03/13/speeding-up-powershell-webcast-by-dr-tobias-weltner/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Importing Modules using -AsCustomObject</title>
		<link>http://powershellstation.com/2012/02/08/importing-modules-using-ascustomobject/</link>
		<comments>http://powershellstation.com/2012/02/08/importing-modules-using-ascustomobject/#comments</comments>
		<pubDate>Wed, 08 Feb 2012 04:46:26 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=379</guid>
		<description><![CDATA[I recently got thinking about the -AsCustomObject switch for the Import-Module cmdlet. I have seen it several times in discussions of implementing &#8220;classes&#8221; in PowerShell. Here&#8217;s a typical (i.e. trivial) example: #module adder.psm1 function add-numbers($x,$y){ return $x+$y } With that module, we can do the standard module stuff: PS> import-module adder PS> add-numbers 1 2 [...]]]></description>
			<content:encoded><![CDATA[<p>I recently got thinking about the -AsCustomObject switch for the Import-Module cmdlet. I have seen it several times in discussions of implementing &#8220;classes&#8221; in PowerShell. Here&#8217;s a typical (i.e. trivial) example:</p>
<pre class="brush:powershell">
#module adder.psm1
function add-numbers($x,$y){
   return $x+$y
}
</pre>
<p>With that module, we can do the standard module stuff:</p>
<pre class="brush:powershell">
PS> import-module adder
PS> add-numbers 1 2
3
</pre>
<p>Ok, that was way too basic. Here&#8217;s something a lot closer to the topic at hand:</p>
<pre class="brush:powershell">
PS> $adder=import-module adder -ascustomobject
PS> $adder | gm

   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
add-numbers ScriptMethod System.Object add-numbers(); 

PS> $adder.add-numbers(1,2)
Unexpected token '-numbers' in expression or statement.
At line:1 char:11
PS>  $adder."add-numbers"( 1, 2)
3
</pre>
<p>There are a several interesting things to notice about this example. First of all, note that the add-numbers function has become a scriptmethod on the $adder object. As the help topic for import-module states, the members of the custom object are the (exported) members of the module. When we try to call the add-numbers method, we find that our decision to use the <em>noun-verb</em> naming convention has bitten us. To use the method, we need to enclose the offending method name in quotes (both single and double work fine). Note that since this is a method we need to use commas to separate the arguments to the function.</p>
<p>A second thing to note is since this is a method, not a function, we can&#8217;t skip arguments.</p>
<pre class="brush:powershell">PS> $adder.add-numbers(,2)</pre>
<p>Note that we could definitely do</p>
<pre class="brush:powershell">add-numbers -y 2</pre>
<p>if we had used a normal import-module. Granted that in this case there would be no need to.</p>
<p>What if we try to fix the quotation issue by including an alias (say, AddNumbers) to the module and exporting it?</p>
<pre class="brush:powershell">
function add-numbers($x,$y){
   return $x+$y
}
new-alias addNumbers add-numbers
export-modulemember -Function * -Variable * -alias *
</pre>
<p>Here&#8217;s what we find:</p>
<pre class="brush:powershell">
PS> $adder=import-module adder -ascustomobject -force
PS> $adder | gm

   TypeName: System.Management.Automation.PSCustomObject

Name        MemberType   Definition
----        ----------   ----------
Equals      Method       bool Equals(System.Object obj)
GetHashCode Method       int GetHashCode()
GetType     Method       type GetType()
ToString    Method       string ToString()
add-numbers ScriptMethod System.Object add-numbers(); 

PS> get-alias AddNumbers

Capability      Name                             ModuleName
----------      ----                             ----------
Script          addNumbers -> add-numbers        adder
</pre>
<p>Hey! Our alias is missing. Unfortunately, it got imported into the global scope (possibly hiding another function).  Note that I used the -force switch to make sure that we re-import it if it was already loaded.</p>
<p>When I first read about the -asCustomObject switch, I could see myself using this to import modules that had conflicting function names, and using the custom objects to call the methods in question.  However, consider a function with a large number of switches or parameters.  With an &#8220;-ascustomobject&#8221; object, you would need to specify all of the switches or parameters. Again, what about a function which used parametersets? As it turns out, scriptmethods don&#8217;t seem to use parametersets.  Here&#8217;s function to demonstrate:</p>
<pre class="brush:powershell">
function test-psets{
param([Parameter(ParameterSetName="Set1")]$x,
      [Parameter(ParameterSetName="Set2")]$y)
      switch ($PsCmdlet.ParameterSetName){
         "Set1" {write-host "we're using Set1"}
         "Set2"  {write-host "we're using Set2"}
         default {write-host "don't know what parameter set we're in"}
      }
      Write-host "we had better be using $($PsCmdlet.ParameterSetName)"
}
</pre>
<p>Calling that function on a custom object looks like this:</p>
<pre class="brush:powershell">
PS> $adder=import-module adder -ascustomobject -force
PS> $adder."test-psets"(1)   #should use pset 1, since we're only using the first parameter
don't know what parameter set we're in
we had better be using
PS> $adder."test-psets"(1,2)  #shouldn't be valid, since they're different parametersets
don't know what parameter set we're in
we had better be using
PS> #Sanity check to make sure the function works
PS> import-module adder
PS> test-psets -x 1
we're using Set1
we had better be using Set1

PS> test-psets -y 1
we're using Set2
we had better be using Set2

PS> test-psets -x 1 -y 2
test-psets : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:1
+ test-psets -x 1 -y 2
+ ~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [test-psets], ParameterBindingException
    + FullyQualifiedErrorId : AmbiguousParameterSet,test-psets
</pre>
<p>So it seems that functions that utilize parametersets are going to be a lot less useful with -AsCustomObject imports.</p>
<p>As I mentioned, there are several examples floating around concerning creating new objects (or classes, depending on your perspective) using modules and this option.  Given the drawbacks I&#8217;ve noted in this article, I think I&#8217;m going to stay away from that particular use case.</p>
<p>What do you think?  Did I miss something important?  Please let me know what your opinion is.</p>
<p>-Mike</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2012%2F02%2F08%2Fimporting-modules-using-ascustomobject%2F&amp;title=Importing%20Modules%20using%20-AsCustomObject" id="wpa2a_6"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2012/02/08/importing-modules-using-ascustomobject/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Aggregation In PowerShell (and another pointless function)</title>
		<link>http://powershellstation.com/2011/12/14/aggregation-in-powershell-and-another-pointless-function/</link>
		<comments>http://powershellstation.com/2011/12/14/aggregation-in-powershell-and-another-pointless-function/#comments</comments>
		<pubDate>Wed, 14 Dec 2011 04:37:42 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Discussion]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=371</guid>
		<description><![CDATA[I&#8217;ve been doing a lot of thinking about &#8220;idiomatic PowerShell&#8221; since my last post and my thinking led me to an idea that I haven&#8217;t actually used, but seems like the kind of thing that people would do in PowerShell. If I were writing a script that needed to get a &#8220;bunch of things&#8221; from [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing a lot of thinking about &#8220;idiomatic PowerShell&#8221; since my <a title="PowerShell’s Problem with Return" href="http://powershellstation.com/2011/08/26/powershell%e2%80%99s-problem-with-return/">last post</a> and my thinking led me to an idea that I haven&#8217;t actually used, but seems like the kind of thing that people would do in PowerShell.</p>
<p>If I were writing a script that needed to get a &#8220;bunch of things&#8221; from somewhere (perhaps several different sources) and return all of them, I might be tempted to do something like this. Please forgive my PowerShell pseudocode:</p>
<pre class="brush: powershell">function get-stuff{
param($parm1 )
    $results=@()
    foreach ($source in $sources){
        $results += ($source | where { $_ -and "Some condition exists"  })
    }
    foreach ($source in $someothersources){
        $results += ($source | where { $_ -and "Some condition exists"  })
    }
 return $results
}</pre>
<p>I&#8217;ve used several permutations of that kind of code using arrays of some sort to collect the results as I go along and eventually return the collection from the function. I&#8217;m not sure that there&#8217;s anything wrong with doing it this way. That is, I&#8217;m not sure that you&#8217;re likely to have issues with doing it this way.</p>
<p>On the other hand, it&#8217;s more idiomatic (i.e more in the style of the PowerShell language) to do something like this (again, pardon the pseudocode):</p>
<pre class="brush: powershell">function get-stuff{
param($parm1 )
    foreach ($source in $sources){
        $source | where { $_ -and "Some condition exists"  }
    }
    foreach ($source in $someothersources){
        $source | where { $_ -and "Some condition exists"  }
    }

}</pre>
<p>All I&#8217;m doing here is sending the output of the inner statements (which are pipelines) to the output stream of the function. Note that there isn&#8217;t any need for anything to accumulate the results into.  Using the output stream makes this function work more like the built-in cmdlets in PowerShell as it won&#8217;t be blocking the pipeline.</p>
<p>The only thing that I have against this code is that it goes against rule #2 that I wrote last time about writing values to the output stream.  I said there that if you were going to write to the output stream, you should explicitly use <strong>write-output</strong>.  We could modify the code above to use <strong>write-output</strong>, but that would involve using parentheses (around the pipelines), messing up the flow of the code, and even blocking the pipeline while the expressions in the parentheses were collected (as an argument to write-output).  </p>
<p>That brings me to what I was saying about &#8220;another pointless function&#8221;.  About a year ago I wrote a <a href="http://powershellstation.com/2010/08/01/the-identity-function/" title="The Identity Function">post</a> about the identity function, which doesn&#8217;t really do anything except return the input.  It is a really useful function for creating lists and such, allowing you to skip on providing a bunch of punctuation.  It&#8217;s not a pointless function, but it&#8217;s not one that is getting much press, either.  I was thinking about how to make the &#8220;pipeline&#8221; version of the code work nicely and not make it ugly and thought of the following function.</p>
<pre class="brush: powershell">
function out-output{
    process{ $_ }
}
</pre>
<p>Like the identity function (or ql, as I&#8217;ve seen it referred to), out-output doesn&#8217;t do anything but emit values that are provided.  Out-output, however, gets its values from the pipeline rather than the argument list.  This function allows us to be explicit about our intent to use the output stream.</p>
<pre class="brush: powershell">function get-stuff{
param($parm1 )
    foreach ($source in $sources){
        $source | where { $_ -and "Some condition exists"  } | out-output
    }
    foreach ($source in $someothersources){
        $source | where { $_ -and "Some condition exists"  } | out-output
    }
}
</pre>
<p>I&#8217;m not sure if this is a good idea, and I know that it&#8217;s just adding a tiny bit of processing to the script.  My thought is that making the operation of the script explicit is worth it in the long run.</p>
<p>What do you think?</p>
<p>-mike</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2011%2F12%2F14%2Faggregation-in-powershell-and-another-pointless-function%2F&amp;title=Aggregation%20In%20PowerShell%20%28and%20another%20pointless%20function%29" id="wpa2a_8"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2011/12/14/aggregation-in-powershell-and-another-pointless-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell Station issues</title>
		<link>http://powershellstation.com/2011/10/11/powershell-station-issues/</link>
		<comments>http://powershellstation.com/2011/10/11/powershell-station-issues/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 02:53:54 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=343</guid>
		<description><![CDATA[I&#8217;m officially an idiot.  I am in good company, though.  The funny (not really funny) thing, is that I read Jeff&#8217;s post 2 years ago and did absolutely nothing about it.  So when my hosting provider had some issues and rebuilt the server this site is on, I was completely unprepared (i.e. I had no [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m officially an idiot.  I am in <a title="good company" href="http://www.codinghorror.com/blog/2009/12/international-backup-awareness-day.html">good company</a>, though.  The funny (not really funny) thing, is that I read Jeff&#8217;s post 2 years ago and did absolutely nothing about it.  So when my hosting provider had some issues and rebuilt the server this site is on, I was completely unprepared (i.e. I had no recent backups).</p>
<p>Let me say that I&#8217;m very pleased with <a title="nosupportlinuxhosting" href="http://nosupportlinuxhosting.com">nosupportlinuxhosting</a> and especially how they handled this outage.  I was informed promptly about the issue, the solution they were pursuing, and was notified when they server was back online.  For a &#8220;no support&#8221; company, I can definitely say that I&#8217;ve had better responses from them than the previous company that was handling the site.</p>
<p>I hope to have (most of) the posts back online in the next day or 2.  Fortunately I did have a backup from january (ouch), but that was just posts, pages, and comments.  If you receive some posts in your feed reader over the next few days, that&#8217;s probably me adding posts from the last 9 months or so.  I doubt I&#8217;ll be able to reconstruct the comments, so I apologize for that lack.</p>
<p>The easy &#8220;take away&#8221; from this is:  <strong>Make sure you have offsite backups for all of your systems.</strong></p>
<p>The not so easy &#8220;take away&#8221; from this is: <strong>No, really, make sure you have offsite backups for all of your systems.</strong></p>
<p>Maybe I&#8217;ll learn my lesson this time.</p>
<p>Mike</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2011%2F10%2F11%2Fpowershell-station-issues%2F&amp;title=PowerShell%20Station%20issues" id="wpa2a_10"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2011/10/11/powershell-station-issues/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell’s Problem with Return</title>
		<link>http://powershellstation.com/2011/08/26/powershell%e2%80%99s-problem-with-return/</link>
		<comments>http://powershellstation.com/2011/08/26/powershell%e2%80%99s-problem-with-return/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 22:29:36 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Discussion]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://powershellstation.com/wordpress/?p=331</guid>
		<description><![CDATA[I think that PowerShell is a fairly readable language, once you’re used to its unique features. Naming functions (cmdlets) with an embedded hyphen, using -eq instead of the equals sign (and similarly for other operators) and not using commas to delimit parameters in a function call (but using them in a method call) are all [...]]]></description>
			<content:encoded><![CDATA[<p>I think that PowerShell is a fairly readable language, once you’re used to its unique features. Naming functions (cmdlets) with an embedded hyphen, using -eq instead of the equals sign (and similarly for other operators) and not using commas to delimit parameters in a function call (but using them in a method call) are all things that you get used to pretty quickly. There is one feature of PowerShell, however, that I don’t think will ever come naturally to me, and that’s how it handles return values from functions.</p>
<p>In most languages, if you see “return 1″ as the only return in a function, you can know that the function is going to the value 1 to the caller. In fact, I’m not sure I’ve ever seen a language that didn’t work that way. That is, until I found PowerShell. Generally speaking, the return statement works just as expected. In the absence of any statements writing to the output stream (with write-output) or “dropping” their values, “return 1″ will cause the caller to receive the value “1″. Using write-output is pretty obvious, and I’d recommend using it explicitly if you intend to add objects to the output stream (thereby including them in the eventual function value). Expressions that don’t capture their return values, however, are not quite so easy to spot.</p>
<p>For example, examine this code to add a parameter to an ADO.NET command object looks fine:</p>
<pre class="brush:powershell">$cmd.Parameters.AddWithValue('@demographics','$demoXML)</pre>
<p>This is a straightforward translation of one of the lines of code in the example code <a href="http://here/">here</a>.  The problem with the code is that AddWithValue not only adds a parameter, it also returns the parameter.  Since we didn’t assign it to a variable, cast it to [void] or pipe it to out-null, the output of this function (AddWithValue) gets added to the output of the function it’s in.</p>
<p>Several “add” functions in the .net framework follow this pattern, either returning the object that was added or the index of that object in the collection.  The DBConnection.Open method (inherited by SQLConnection, among others) returns the opened connection.  I’m sure that with time I could find more examples than I’d feel like sharing.</p>
<p>Another way that I’ve seen the output stream getting messed up is when a function uses strings to output information without using write-host.  For example, this function outputs “progress” information as it goes:</p>
<pre class="brush:powershell">
function get-filelength{
param($filename)
	"reading file"
	$len=0
	$file=get-content $filename
	foreach($line in $file){
	   "adding a line"
	   $len+=$line.length
	}
	return $len
}
</pre>
<p>I realize that this is not the best way to find the length of a file, but it works for the purpose of illustration. If you simply call the function (without assigning it to a variable), you’ll see a bunch of text, followed by the “value” of the function. The “returned value” of the function is clearly intended to be $len, but instead all of the text is included. The type of the function output is Object[], rather than a number.</p>
<p>There are some good reasons to use the output stream in a function (the next post will examine one such use), but it’s very easy to accidentally put something in the stream without intending to. When this happens, it often leads to unexpected results and long debugging sessions.</p>
<p>Here are my recommendations for avoiding this kind of error:</p>
<ol start="1">
<li>Use one of the “write” functions to provide text messages to the user (write-host, write-debug, write-verbose)</li>
<li>Use write-output if your intent is to add something to the output stream</li>
<li>Check msdn to see if the methods you use have output. If you’re looking at the C# version, methods that return void do not need to be “handled”. In the VB.NET version, they’ll be declared as Sub, rather than Function.</li>
<li>Be consistent with how you “handle” methods or functions whose values you want to discard. Options are to cast the result as [void] or pipe it to out-null</li>
<li>If you’re using write-output to put objects in the output stream, use return with no value (i.e., don’t return $val). Seeing a value returned explicitly implies that that is the only value returned.</li>
<li>If all else fails, use write-host to output the type of variables when debugging (or look at their values in the watch window if you’re using an IDE with a debugger).</li>
</ol>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2011%2F08%2F26%2Fpowershell%25e2%2580%2599s-problem-with-return%2F&amp;title=PowerShell%E2%80%99s%20Problem%20with%20Return" id="wpa2a_12"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2011/08/26/powershell%e2%80%99s-problem-with-return/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PowerShell Tools and Books That I Use (Revisited)</title>
		<link>http://powershellstation.com/2011/05/19/powershell-tools-and-books-that-i-use-revisited/</link>
		<comments>http://powershellstation.com/2011/05/19/powershell-tools-and-books-that-i-use-revisited/#comments</comments>
		<pubDate>Thu, 19 May 2011 17:38:18 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=354</guid>
		<description><![CDATA[A friend of mine found this blog yesterday and commented on “PowerShellToolsandBooksThatIUse“. I thought that it would be good to update the list since it’s almost 2 years old.  The changes are mostly incremental: version changes, a few new items, a few I don’t use much anymore. Without further ado, here we go (now with [...]]]></description>
			<content:encoded><![CDATA[<p>A friend of mine found this blog yesterday and commented on “<a href="../2009/09/10/powershell-tools-and-books-that-i-use/">PowerShell</a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/">Tools</a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/">and</a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/">Books</a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/">That</a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/">I</a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/">Use</a>“. I thought that it would be good to update the list since it’s almost 2 years old.  The changes are mostly incremental: version changes, a few new items, a few I don’t use much anymore.</p>
<p>Without further ado, here we go (now with linky-goodness!):</p>
<p>Tools I Use (note…these are all free!):</p>
<ul>
<li>PowerShell ISE (I know it’s part of the install, but I use it a lot!)</li>
<li><a href="http://powergui.org/index.jspa">PowerGUI</a><a href="http://powergui.org/index.jspa">Script</a><a href="http://powergui.org/index.jspa">Editor</a> (I still haven’t gotten the hang of PowerGUI itself)</li>
<li><a href="http://pscx.codeplex.com/">Powershell</a><a href="http://pscx.codeplex.com/">Community</a><a href="http://pscx.codeplex.com/">Extensions</a><a href="http://pscx.codeplex.com/"> 2.0</a> (PSCX)</li>
<li><a href="http://sqlpsx.codeplex.com/">SQL</a><a href="http://sqlpsx.codeplex.com/">PowerShell</a><a href="http://sqlpsx.codeplex.com/">Extensions</a><a href="http://sqlpsx.codeplex.com/"> 2.3</a> (SQLPSX)</li>
<li><a href="http://www.sapien.com/downloads">PrimalForms</a><a href="http://www.sapien.com/downloads">Community</a><a href="http://www.sapien.com/downloads">Edition</a> (free registration required) Download under “Free Tools/32-bit”</li>
</ul>
<p>Books:</p>
<ul>
<li><a href="http://www.manning.com/payette2/">PowerShell</a><a href="http://www.manning.com/payette2/">In</a><a href="http://www.manning.com/payette2/">Action</a><a href="http://www.manning.com/payette2/">,2</a><a href="http://www.manning.com/payette2/">nd</a><a href="http://www.manning.com/payette2/">Edition</a> by Bruce Payette (just released yesterday, 5/18!)</li>
<li><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">Professional</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">Windows</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">PowerShell</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">Programming</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">: </a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">Snapins</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">, </a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">Cmdlets</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">, </a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">Hosts</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">and</a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939">Providers</a> by Arul Kumaravel et. al. (PowerShell 1.0, but still has good info about building hosts)</li>
<li><a href="http://powershell.com/cs/blogs/ebook/">Mastering</a><a href="http://powershell.com/cs/blogs/ebook/">PowerShell</a> by Dr. Tobias Weltner</li>
<li><a href="http://www.manning.com/siddaway/">PowerShell</a><a href="http://www.manning.com/siddaway/">in</a><a href="http://www.manning.com/siddaway/">Practice</a>, by Richard Siddaway</li>
</ul>
<p>In addition to these, there are any number of blogs (I really need to update <a href="../blogs/">my</a><a href="../blogs/">list</a>) that I subscribe to in google reader. Also, there’s a very active community on <a href="http://stackoverflow.com/questions/tagged/powershell">StackOverflow</a> that will usually be able to provide direction if you’re not sure what’s going on.</p>
<p>As I said the last time, there are lots of other tools and books, but these are the ones I keep coming back to.</p>
<p>Let me know if you think I missed something super-important.</p>
<p>Mike</p>
<p><!--[if gte mso 9]><xml><br />
 <o:OfficeDocumentSettings><br />
  <o:TargetScreenSize>800&#215;600</o:TargetScreenSize><br />
 </o:OfficeDocumentSettings><br />
</xml><![endif]--><!--[if gte mso 9]><xml><br />
 <w:WordDocument><br />
  <w:View>Normal</w:View><br />
  <w:Zoom>0</w:Zoom><br />
  <w:TrackMoves/><br />
  <w:TrackFormatting/><br />
  <w:PunctuationKerning/><br />
  <w:ValidateAgainstSchemas/><br />
  <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid><br />
  <w:IgnoreMixedContent>false</w:IgnoreMixedContent><br />
  <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText><br />
  <w:DoNotPromoteQF/><br />
  <w:LidThemeOther>EN-US</w:LidThemeOther><br />
  <w:LidThemeAsian>X-NONE</w:LidThemeAsian><br />
  <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript><br />
  <w:Compatibility><br />
   <w:BreakWrappedTables/><br />
   <w:SnapToGridInCell/><br />
   <w:WrapTextWithPunct/><br />
   <w:UseAsianBreakRules/><br />
   <w:DontGrowAutofit/><br />
   <w:SplitPgBreakAndParaMark/><br />
   <w:EnableOpenTypeKerning/><br />
   <w:DontFlipMirrorIndents/><br />
   <w:OverrideTableStyleHps/><br />
  </w:Compatibility><br />
  <w:DoNotOptimizeForBrowser/><br />
  <m:mathPr><br />
   <m:mathFont m:val="Cambria Math"/><br />
   <m:brkBin m:val="before"/><br />
   <m:brkBinSub m:val="&#45;-"/><br />
   <m:smallFrac m:val="off"/><br />
   <m:dispDef/><br />
   <m:lMargin m:val="0"/><br />
   <m:rMargin m:val="0"/><br />
   <m:defJc m:val="centerGroup"/><br />
   <m:wrapIndent m:val="1440"/><br />
   <m:intLim m:val="subSup"/><br />
   <m:naryLim m:val="undOvr"/><br />
  </m:mathPr></w:WordDocument><br />
</xml><![endif]--><!--[if gte mso 9]><xml><br />
 <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true"<br />
  DefSemiHidden="true" DefQFormat="false" DefPriority="99"<br />
  LatentStyleCount="267"><br />
  <w:LsdException Locked="false" Priority="0" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Normal"/><br />
  <w:LsdException Locked="false" Priority="9" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="heading 1"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/><br />
  <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 1"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 2"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 3"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 4"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 5"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 6"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 7"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 8"/><br />
  <w:LsdException Locked="false" Priority="39" Name="toc 9"/><br />
  <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/><br />
  <w:LsdException Locked="false" Priority="10" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Title"/><br />
  <w:LsdException Locked="false" Priority="0" Name="Default Paragraph Font"/><br />
  <w:LsdException Locked="false" Priority="11" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/><br />
  <w:LsdException Locked="false" Priority="22" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Strong"/><br />
  <w:LsdException Locked="false" Priority="20" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/><br />
  <w:LsdException Locked="false" Priority="59" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Table Grid"/><br />
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/><br />
  <w:LsdException Locked="false" Priority="1" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/><br />
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Shading"/><br />
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light List"/><br />
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Grid"/><br />
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 1"/><br />
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 2"/><br />
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 1"/><br />
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 2"/><br />
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 1"/><br />
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 2"/><br />
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 3"/><br />
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Dark List"/><br />
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Shading"/><br />
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful List"/><br />
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Grid"/><br />
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Shading Accent 1"/><br />
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light List Accent 1"/><br />
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Grid Accent 1"/><br />
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/><br />
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/><br />
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/><br />
  <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/><br />
  <w:LsdException Locked="false" Priority="34" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/><br />
  <w:LsdException Locked="false" Priority="29" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Quote"/><br />
  <w:LsdException Locked="false" Priority="30" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/><br />
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/><br />
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/><br />
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/><br />
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/><br />
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Dark List Accent 1"/><br />
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/><br />
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful List Accent 1"/><br />
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/><br />
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Shading Accent 2"/><br />
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light List Accent 2"/><br />
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Grid Accent 2"/><br />
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/><br />
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/><br />
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/><br />
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/><br />
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/><br />
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/><br />
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/><br />
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Dark List Accent 2"/><br />
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/><br />
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful List Accent 2"/><br />
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/><br />
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Shading Accent 3"/><br />
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light List Accent 3"/><br />
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Grid Accent 3"/><br />
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/><br />
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/><br />
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/><br />
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/><br />
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/><br />
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/><br />
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/><br />
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Dark List Accent 3"/><br />
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/><br />
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful List Accent 3"/><br />
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/><br />
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Shading Accent 4"/><br />
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light List Accent 4"/><br />
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Grid Accent 4"/><br />
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/><br />
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/><br />
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/><br />
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/><br />
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/><br />
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/><br />
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/><br />
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Dark List Accent 4"/><br />
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/><br />
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful List Accent 4"/><br />
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/><br />
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Shading Accent 5"/><br />
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light List Accent 5"/><br />
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Grid Accent 5"/><br />
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/><br />
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/><br />
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/><br />
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/><br />
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/><br />
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/><br />
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/><br />
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Dark List Accent 5"/><br />
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/><br />
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful List Accent 5"/><br />
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/><br />
  <w:LsdException Locked="false" Priority="60" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Shading Accent 6"/><br />
  <w:LsdException Locked="false" Priority="61" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light List Accent 6"/><br />
  <w:LsdException Locked="false" Priority="62" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Light Grid Accent 6"/><br />
  <w:LsdException Locked="false" Priority="63" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/><br />
  <w:LsdException Locked="false" Priority="64" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/><br />
  <w:LsdException Locked="false" Priority="65" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/><br />
  <w:LsdException Locked="false" Priority="66" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/><br />
  <w:LsdException Locked="false" Priority="67" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/><br />
  <w:LsdException Locked="false" Priority="68" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/><br />
  <w:LsdException Locked="false" Priority="69" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/><br />
  <w:LsdException Locked="false" Priority="70" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Dark List Accent 6"/><br />
  <w:LsdException Locked="false" Priority="71" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/><br />
  <w:LsdException Locked="false" Priority="72" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful List Accent 6"/><br />
  <w:LsdException Locked="false" Priority="73" SemiHidden="false"<br />
   UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/><br />
  <w:LsdException Locked="false" Priority="19" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/><br />
  <w:LsdException Locked="false" Priority="21" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/><br />
  <w:LsdException Locked="false" Priority="31" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/><br />
  <w:LsdException Locked="false" Priority="32" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/><br />
  <w:LsdException Locked="false" Priority="33" SemiHidden="false"<br />
   UnhideWhenUsed="false" QFormat="true" Name="Book Title"/><br />
  <w:LsdException Locked="false" Priority="37" Name="Bibliography"/><br />
  <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/><br />
 </w:LatentStyles><br />
</xml><![endif]--><!--[if gte mso 10]></p>
<style>
 /* Style Definitions */
 table.MsoNormalTable
	{mso-style-name:"Table Normal";
	mso-tstyle-rowband-size:0;
	mso-tstyle-colband-size:0;
	mso-style-noshow:yes;
	mso-style-priority:99;
	mso-style-parent:"";
	mso-padding-alt:0in 5.4pt 0in 5.4pt;
	mso-para-margin:0in;
	mso-para-margin-bottom:.0001pt;
	mso-pagination:widow-orphan;
	font-size:10.0pt;
	font-family:"Times New Roman","serif";}
</style>
<p><![endif]--></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">A friend of mine found this blog yesterday and commented on “</span><a href="../2009/09/10/powershell-tools-and-books-that-i-use/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PowerShell</span></a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Tools</span></a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">and</span></a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Books</span></a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">That</span></a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">I</span></a><a href="../2009/09/10/powershell-tools-and-books-that-i-use/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Use</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">“. I thought that it would be good to update the list since it’s almost 2 years old.  The changes are mostly incremental: version changes, a few new items, a few I don’t use much anymore.</span></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">Without further ado, here we go (now with linky-goodness!):</span></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">Tools I Use (note…these are all free!):</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">PowerShell ISE (I know it’s part of the install, but I use it a lot!)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://powergui.org/index.jspa"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PowerGUI</span></a><a href="http://powergui.org/index.jspa"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Script</span></a><a href="http://powergui.org/index.jspa"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Editor</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> (I still haven’t gotten the hang of PowerGUI itself)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://pscx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Powershell</span></a><a href="http://pscx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Community</span></a><a href="http://pscx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Extensions</span></a><a href="http://pscx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;"> 2.0</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> (PSCX)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://sqlpsx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">SQL</span></a><a href="http://sqlpsx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PowerShell</span></a><a href="http://sqlpsx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Extensions</span></a><a href="http://sqlpsx.codeplex.com/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;"> 2.3</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> (SQLPSX)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://www.sapien.com/downloads"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PrimalForms</span></a><a href="http://www.sapien.com/downloads"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Community</span></a><a href="http://www.sapien.com/downloads"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Edition</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> (free registration required) Download under “Free Tools/32-bit”</span></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">Books:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://www.manning.com/payette2/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PowerShell</span></a><a href="http://www.manning.com/payette2/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">In</span></a><a href="http://www.manning.com/payette2/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Action</span></a><a href="http://www.manning.com/payette2/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">,2</span></a><a href="http://www.manning.com/payette2/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">nd</span></a><a href="http://www.manning.com/payette2/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Edition</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> by Bruce Payette (just released yesterday, 5/18!)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Professional</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Windows</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PowerShell</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Programming</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">: </span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Snapins</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">, </span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Cmdlets</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">, </span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Hosts</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">and</span></a><a href="http://www.amazon.com/Professional-Windows-PowerShell-Programming-Providers/dp/0470173939"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Providers</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> by Arul Kumaravel et. al. (PowerShell 1.0, but still has good info about building hosts)</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://powershell.com/cs/blogs/ebook/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Mastering</span></a><a href="http://powershell.com/cs/blogs/ebook/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PowerShell</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> by Dr. Tobias Weltner</span></p>
<p class="MsoNormal" style="margin: 0in 0in 0.0001pt 0.5in; text-indent: -0.25in; line-height: normal;"><span style="font-size: 10pt; font-family: 'Verdana','sans-serif';"><span>●<span style="font: 7pt 'Times New Roman';">      </span></span></span><a href="http://www.manning.com/siddaway/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">PowerShell</span></a><a href="http://www.manning.com/siddaway/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">in</span></a><a href="http://www.manning.com/siddaway/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">Practice</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">, by Richard Siddaway</span></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">In addition to these, there are any number of blogs (I really need to update </span><a href="../blogs/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">my</span></a><a href="../blogs/"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">list</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">) that I subscribe to in google reader. Also, there’s a very active community on </span><a href="http://stackoverflow.com/questions/tagged/powershell"><span style="font-size: 12pt; font-family: 'Times New Roman','serif'; color: blue;">StackOverflow</span></a><span style="font-size: 12pt; font-family: 'Times New Roman','serif';"> that will usually be able to provide direction if you’re not sure what’s going on.</span></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">As I said the last time, there are lots of other tools and books, but these are the ones I keep coming back to.</span></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">Let me know if you think I missed something super-important.</span></p>
<p class="MsoNormal" style="margin: 5pt 0in; line-height: normal;"><span style="font-size: 12pt; font-family: 'Times New Roman','serif';">Mike</span></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2011%2F05%2F19%2Fpowershell-tools-and-books-that-i-use-revisited%2F&amp;title=PowerShell%20Tools%20and%20Books%20That%20I%20Use%20%28Revisited%29" id="wpa2a_14"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2011/05/19/powershell-tools-and-books-that-i-use-revisited/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A few functions for working with SQL Agent Job data</title>
		<link>http://powershellstation.com/2011/05/09/a-few-functions-for-working-with-sql-agent-job-data/</link>
		<comments>http://powershellstation.com/2011/05/09/a-few-functions-for-working-with-sql-agent-job-data/#comments</comments>
		<pubDate>Tue, 10 May 2011 02:04:39 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://powershellstation.com/wordpress/?p=338</guid>
		<description><![CDATA[If you’ve ever looked at sysjobhistory, you know that the way SQL Server stores datetimes and durations in this table are not very friendly. Well, that’s not quite true. They are human-readable if they are small, but if you’ve got a job that runs for hours (days?), it becomes more and more difficult. For example, [...]]]></description>
			<content:encoded><![CDATA[<p>If you’ve ever looked at sysjobhistory, you know that the way SQL Server stores datetimes and durations in this table are not very friendly. Well, that’s not quite true. They are human-readable if they are small, but if you’ve got a job that runs for hours (days?), it becomes more and more difficult.<br />
For example, a job which started at 9:05AM today (5/9/2011) would have a run_time of 905 and a run_date of 20110905. Both of those are recognizable, but since they are integers, it’s complicated to get them into a datetime variable in PowerShell in order to manipulate them. I have seen several posts on how to create a UDF (user-defined function) to convert these values to a datetime, and that’s usually a good solution. Unfortunately, it’s not always possible (politically) to create a UDF on a SQL instance. For example, if you are simply monitoring a box to make sure that backups are run, and don’t have much control over the box besides that function, you might not be allowed to create the necessary UDFs. Similarly, a SQL solution involving a select statement that kneads the data into the value you want is not a great solution because it’s not reusable, except in the cut-paste sense.<br />
For that reason, I have written 4 different functions to assist with managing job data.</p>
<pre class="brush:powershell">
function convertfrom-SqlAgentDuration{
param($sql_duration)
    return New-TimeSpan -seconds ($sql_duration % 100) -minutes (($sql_duration / 100) % 100) -hours ($sql_duration /10000)
}

function convertfrom-SQLAgentDateTime{
param($sql_startdate,$sql_starttime)
    return (get-date -year ($sql_startdate/10000) -month ($sql_startdate/100 % 100) -day ($sql_startdate %100) -hour ($sql_starttime/10000 % 100) -minute ($sql_starttime/100 % 100) -sec ($sql_starttime % 100))
}

function convertto-SQLAgentDuration{
param([System.TimeSpan]$duration)
    return $duration.seconds+100*$duration.minutes+10000*($duration.hours+24*$duration.days)
}

function convertto-SQLAgentDateTime{
param([datetime]$date)
    return (new-object PSObject -property @{date=[int](get-date $date -uformat "%Y%m%d");time=[int](get-date $date -uformat "%H%M%S")})
}
</pre>
<p>Obviously, these are not high-performance functions, but given the volume of data you would be getting out of the SQL Agent, that shouldn’t pose any kind of problem. Here are some example usages:</p>
<pre>
PS>get-date

Monday, May 09, 2011 9:01:58 PM
_________________________________________________________________________________
PS>convertto-sqlagentdatetime (get-date) | ft -auto

    date   time
    ----   ----
20110509 210648
_________________________________________________________________________________
PS>convertfrom-sqlagentdatetime 20110509 210648

Monday, May 09, 2011 9:06:48 PM
_________________________________________________________________________________
PS>convertfrom-SqlAgentDuration 12345

Days              : 0
Hours             : 1
Minutes           : 23
Seconds           : 45
Milliseconds      : 0
Ticks             : 50250000000
TotalDays         : 0.0581597222222222
TotalHours        : 1.39583333333333
TotalMinutes      : 83.75
TotalSeconds      : 5025
TotalMilliseconds : 5025000
</pre>
<p>I hope these functions are useful to you. Let me know what you think.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2011%2F05%2F09%2Fa-few-functions-for-working-with-sql-agent-job-data%2F&amp;title=A%20few%20functions%20for%20working%20with%20SQL%20Agent%20Job%20data" id="wpa2a_16"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2011/05/09/a-few-functions-for-working-with-sql-agent-job-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Powershellstation.com has moved</title>
		<link>http://powershellstation.com/2011/01/30/powershellstation-com-has-moved/</link>
		<comments>http://powershellstation.com/2011/01/30/powershellstation-com-has-moved/#comments</comments>
		<pubDate>Sun, 30 Jan 2011 21:58:20 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=350</guid>
		<description><![CDATA[I mentioned a while back that I was thinking about moving my site to NoSupportLinuxHosting.com.  They offer $1 per month basic shared hosting with the caveat that they don’t provide tech support.  Since I’m not doing anything fancy on this site (i.e. hosting wordpress only), and I’m not to the point where I need to [...]]]></description>
			<content:encoded><![CDATA[<p>I mentioned a while back that I was thinking about moving my site to NoSupportLinuxHosting.com.  They offer $1 per month basic shared hosting with the caveat that they don’t provide tech support.  Since I’m not doing anything fancy on this site (i.e. hosting wordpress only), and I’m not to the point where I need to be concerned about storage or bandwidth, it seemed like a good fit.  I’ve not had any real issues with my previous host (godaddy.com…yes, I know), but figured I could be saving a bit of money.</p>
<p>If you’re reading this, the transformation went well.  It only took 30-ish minutes to accomplish.</p>
<p>Let me know if you find something missing or not working.</p>
<p>Mike</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2011%2F01%2F30%2Fpowershellstation-com-has-moved%2F&amp;title=Powershellstation.com%20has%20moved" id="wpa2a_18"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2011/01/30/powershellstation-com-has-moved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Verifying Automation</title>
		<link>http://powershellstation.com/2011/01/06/verifying-automation/</link>
		<comments>http://powershellstation.com/2011/01/06/verifying-automation/#comments</comments>
		<pubDate>Fri, 07 Jan 2011 00:59:16 +0000</pubDate>
		<dc:creator>mike</dc:creator>
				<category><![CDATA[Discussion]]></category>
		<category><![CDATA[Scheduled Tasks]]></category>
		<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://powershellstation.com/?p=317</guid>
		<description><![CDATA[If you&#8217;re anything like me, you&#8217;ve been bitten by the PowerShell bug and are using it among other automation sources to make you life in IT much more enjoyable. If this is not the case&#8230;you need to get started!&#160; There&#8217;s no time like the present, and a PowerShell New Year&#8217;s resolution should be something to [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re anything like me, you&#8217;ve been bitten by the PowerShell bug and are using it among other automation sources to make you life in IT much more enjoyable.  If this is not the case&#8230;you need to get started!&nbsp; There&#8217;s no time like the present, and a PowerShell New Year&#8217;s resolution should be something to consider.</p>
<p>For those of you that are with me in the PowerShell camp, I have something that I&#8217;d like to discuss.&nbsp; You probably have hundreds (dozens?) of scripts scheduled on multiple servers, possibly in multiple domains or geographical locations to perform things like these:</p>
<ul>
<li>Gather information about servers</li>
<li>Generate reports about application usage</li>
<li>Copy information from one place to another</li>
<li>Validate security setup</li>
<li>Start and Stop processes</li>
<li>Scan log files for error conditions</li>
<li>Lots of other things (you get the point)</li>
</ul>
<p>How do you know that the scripts that you have written carefully and scheduled are actually running successfully?&nbsp; At first, this seems like a silly question.&nbsp; When you deployed the script, surely you ran it once to make sure it worked.&nbsp; What could have gone wrong?</p>
<p>Here are some examples that come to mind:</p>
<ul>
<li>A policy was pushed which set the execution policy to Restricted</li>
<li>The credentials you scheduled the script with have been revoked</li>
<li>A file share that the scripts depend on is unavailable</li>
<li>Firewall rules change and now WMI queries aren&#8217;t working</li>
<li>The Task Scheduler service is stopped</li>
</ul>
<p>You can probably think of a lot more examples of things that would keep scripts from working, but you get the idea.&nbsp; I&#8217;ve given some thought to how to do this, but haven&#8217;t come to any real conclusions.&nbsp; Obviously, having your scripts log results is helpful, but only if you monitor the logs for success/failure.&nbsp; Also, if you have a script which is supposed to run every 10 minutes, it doesn&#8217;t help if you don&#8217;t get alerted when it only runs once in a day, even if&nbsp; it runs successfully.&nbsp; Also, if there is more than one person writing scripts, how do you make sure that everyone is using the same techniques to log progress?</p>
<p>Here are some of my thoughts:</p>
<ul>
<li>Use a &#8220;launcher&#8221; to run scripts (see below)</li>
<li>Keep a database of processes with an expected # of runs per day</li>
<li>Monitor matching start/end of scripts</li>
<li>Log all output streams (<a title="example" href="http://www.nivot.org/2009/08/19/PowerShell20AConfigurableAndFlexibleScriptLoggerModule.aspx">example</a>)</li>
</ul>
<p>The first item in the list (the launcher) has been something I&#8217;ve been considering because it&#8217;s not trivial to run a PowerShell script in a scheduled task.&nbsp; Even with the -file parameter which was added in PowerShell 2.0, it can involve a fairly long command-line.&nbsp; With the added difficulty of trying to capture output streams (most of which are not exposed to the command shell) it becomes a process that is almost hard to get right every time.&nbsp; Some features I&#8217;m planning for the launcher are:</p>
<ul>
<li>Load appropriate profiles</li>
<li>Log all output streams (with timestamps) to file or database</li>
<li>Log application start/end times</li>
<li>Email owner of script if there are unhandled exceptions</li>
</ul>
<p>I know this topic is not specific to PowerShell, but as Windows administrators get more used to scripting solutions to their automation problems with PowerShell (which I am confident that they are doing), it&#8217;s something that every organization will need to consider.&nbsp; I&#8217;ll try to follow up with some posts that have some actual code to address some of these points.</p>
<p>Mike</p>
<p>P.S.  I&#8217;m specifically not discussing &#8220;enterprise job scheduling&#8221; solutions like JAMS because of the high cost involved.  I&#8217;d like to see the community come up with something a little more budget-friendly.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fpowershellstation.com%2F2011%2F01%2F06%2Fverifying-automation%2F&amp;title=Verifying%20Automation" id="wpa2a_20"><img src="http://powershellstation.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://powershellstation.com/2011/01/06/verifying-automation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  powershellstation.com/feed/ ) in 0.28871 seconds, on May 19th, 2012 at 3:55 pm UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on May 20th, 2012 at 3:55 pm UTC -->
<!-- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- Quick Cache Is Fully Functional :-) ... A Quick Cache file was just served for (  powershellstation.com/feed/ ) in 0.00085 seconds, on May 20th, 2012 at 12:09 am UTC. -->
