{"id":8501,"date":"2007-02-23T19:32:00","date_gmt":"2007-02-23T19:32:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/02\/23\/time-till-we-land\/"},"modified":"2019-02-18T13:20:43","modified_gmt":"2019-02-18T20:20:43","slug":"time-till-we-land","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/time-till-we-land\/","title":{"rendered":"Time till we land &#8230;"},"content":{"rendered":"<h2><span>&lt;Today we have a guest blog entry from Ed Wilson \u2013 Author of the upcoming MSPRESS book, Microsoft Windows PowerShell Step By Step&gt; <\/span><\/h2>\n<h2><span>&lt;2\/16 fixed a bug pointed out by Richard Siddaway [use TotalMinutes instead of Minutes for the out-gauge].&nbsp; Thanks Richard! -jps&gt; <\/span><\/h2>\n<p>I was on my way to Ottawa this week, and working on a few scripts, when I realized that perhaps I might need to keep track of time. My poor old combination laptop\/coffee warmer is struggling to keep up the pace, and as a result I need a good five minute warning to shut the silly thing down prior to landing. The flight attendants do not usually give me sufficient warning to put the beast to bed. Alas, what&#8217;s a consultant to do\u2026? <\/p>\n<p>I decided to use the New-TimeSpan cmdlet to calculate the difference between the current time (obtained by get-date) and the time the plane would land at 12:55 pm. So I came up with this &#8220;one-liner&#8221;\u2026 <\/p>\n<p>New-TimeSpan -Start (Get-Date) -End (Get-Date -Hour 12 -Minute 55) <\/p>\n<p>After running the command, I was able to immediately see how long I had until the plane landed as shown here\u2026 <\/p>\n<p>Days : 0 <\/p>\n<p>Hours : 0 <\/p>\n<p>Minutes : 56 <\/p>\n<p>Seconds : 0 <\/p>\n<p>Milliseconds : 15 <\/p>\n<p>Ticks : 33600156250 <\/p>\n<p>TotalDays : 0.0388890697337963 <\/p>\n<p>TotalHours : 0.933337673611111 <\/p>\n<p>TotalMinutes : 56.0002604166667 <\/p>\n<p>TotalSeconds : 3360.015625 <\/p>\n<p>TotalMilliseconds : 3360015.625 <\/p>\n<p>The problem, is this is way too reading. So I pipelined the output to the Format-List cmdlet. The revised code is seen here. <\/p>\n<p>New-TimeSpan -Start (Get-Date) -End (Get-Date -Hour 12 -Minute 55) | Format-List TotalMinutes <\/p>\n<p>Now the output is simple: TotalMinutes : 54 <\/p>\n<p>All I have to do now, is up-arrow, and press enter, and I have a clear idea of when the plane will land. But wait, there&#8217;s more. I really did not want to have to remember to up arrow, all the time\u2026 dude, if I was going to remember that, I could probably remember to look at the clock on my coffee warmer and see that\u2026. So I added in the PowerGadgets snap-in as shown here (See Jeffrey&#8217;s <a href=\"https:\/\/blogs.msdn.com\/powershell\/archive\/2007\/01\/26\/executive-demo.aspx\">earlier blog on PowerGadgets<\/a>\u2026 they rock!) <\/p>\n<p>Add-PSSnapin PowerGadgets<strong> <\/strong><\/p>\n<p>Up arrow \u2026 remove the Format-List cmdlet, replace with Out-gage. Specify the value is minutes, and I would like it to float and refresh every 30 seconds. Set the max scale for 60 minutes and voila \u2026 <\/p>\n<p>New-TimeSpan -Start (Get-Date) -End (Get-Date -Hour 22 -Minute 00) | <\/p>\n<p>Out-Gauge -Value TotalMinutes -Floating -Refresh 0:0:30 -MainScale_max 60 <\/p>\n<p>Now I get a floating gage that I can move around as needed. It is measured for 60 minutes, and will automatically refresh every 30 seconds. And it only took one line of code\u2026 cool. <\/p>\n<p>Ed Wilson [MSFT] <\/p>\n<p>US Enterprise Services, Consulting for IT Operations <\/p>\n<p>Microsoft Windows PowerShell Step By Step, Microsoft Press (Forthcoming) <\/p>\n<p><a href=\"http:\/\/www.microsoft.com\/MSPress\/books\/10329.aspx\">http:\/\/www.microsoft.com\/MSPress\/books\/10329.aspx<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>&lt;Today we have a guest blog entry from Ed Wilson \u2013 Author of the upcoming MSPRESS book, Microsoft Windows PowerShell Step By Step&gt; &lt;2\/16 fixed a bug pointed out by Richard Siddaway [use TotalMinutes instead of Minutes for the out-gauge].&nbsp; Thanks Richard! -jps&gt; I was on my way to Ottawa this week, and working on [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8501","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>&lt;Today we have a guest blog entry from Ed Wilson \u2013 Author of the upcoming MSPRESS book, Microsoft Windows PowerShell Step By Step&gt; &lt;2\/16 fixed a bug pointed out by Richard Siddaway [use TotalMinutes instead of Minutes for the out-gauge].&nbsp; Thanks Richard! -jps&gt; I was on my way to Ottawa this week, and working on [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8501","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=8501"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8501\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=8501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=8501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=8501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}