{"id":92,"date":"2007-03-21T12:30:39","date_gmt":"2007-03-21T20:30:39","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/03\/21\/powershell-temperature\/"},"modified":"2007-03-21T12:30:39","modified_gmt":"2007-03-21T20:30:39","slug":"powershell-temperature","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/03\/21\/powershell-temperature\/","title":{"rendered":"PowerShell Temperature"},"content":{"rendered":"<p>I thought this was going to be a fast and furious example, but it took a whole lot longer than I expected. The good news is that I&#8217;ve done all the work for you.&nbsp; You&#8217;re most welcome. <\/p>\n<p>I love weather and living in central New York we get all kinds. So I decided I needed a thermometer on my desktop. Using <a href=\"http:\/\/www.powergadgets.com\/\" target=\"_blank\">PowerGadget&#8217;s<\/a> Out-Gauge cmdlet this is pretty easy to do.<\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">#Get-Temperature.ps1 <br \/>$url=&#8221;http:\/\/xml.weather.yahoo.com\/forecastrss?p=ZIPCODE&#8221;<br \/>$webClient = New-Object System.Net.WebClient<br \/>[xml]$data=$webClient.DownloadString($Url) <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">#create new object to hold values<br \/>$obj = New-Object System.Object<br \/>Add-Member -inputobject $obj -membertype NoteProperty -Name Temperature -value $data.rss.channel.item.condition.temp<br \/>Add-Member -inputobject $obj -membertype NoteProperty -Name Conditions -value $data.rss.channel.item.condition.text <\/font><\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">Write-Output $obj<br \/><\/font><\/p>\n<p><span class=\"full-image-float-left\"><img decoding=\"async\" style=\"width: 50px; height: 150px\" alt=\"thermometer.png\" src=\"\/storage\/thermometer.png\" \/><\/span>The script downloads an XML file with weather information. You need to substitute your zip code in the URL. I&#8217;ve &#8220;objectified&#8221; the function by defining some properties. There&#8217;s a lot more information in the XML file you can play with as well. I picked two properties that I wanted to use in my gauge. Because the configuration for the gauge is more than I care to type more than once, I put this code in a separate script so all I have to do is run it:<\/p>\n<p><font style=\"color: #0000ff\" face=\"Lucida Console\" color=\"#0000ff\" size=\"2\">s:\\posh\\Get-Temperature.ps1 | out-gauge -style 4 -MainIndicator_Style Filler07 -value Temperature -type vertical -floating -tooltip {$_.Conditions} -tooltipenabled True -scales_0_max 120 -scales_0_min -20 -size 50,150 -refresh 0:30:0<\/font><\/p>\n<p>&nbsp;Be sure to specify the complete path to the script file. As written, the temperature is updated every 30 minutes. If I hover my mouse over the gauge I&#8217;ll also get current conditions. Hover over the &#8220;mercury&#8221; and I&#8217;ll get the current temperature. <\/p>\n<p>I had hoped to add the code as a function to my profile, but PowerGadgets doesn&#8217;t necessarily load the functions from your profile so the refresh didn&#8217;t work. They&#8217;re looking into this issue for a future release. I also could have created an actual gadget file with PowerGadget Creator.<\/p>\n<p>[Note 3\/22\/2003]<\/p>\n<p>I just edited the second block of code.&nbsp; I had posted code that won&#8217;t work. You&#8217;ll get a message about Condition not recognized as a cmdlet, etc. For the ToolTip I have to explicitly say, use the Conditions property from the current object, ie, the one in the pipeline.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:746ea10d-06f8-4214-8de0-19777c39310a\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\"><span class=\"sizeLess20\">Technorati tags: <\/span><a href=\"http:\/\/technorati.com\/tags\/PowerShell\" rel=\"tag\"><span class=\"sizeLess20\">PowerShell<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/XML\" rel=\"tag\"><span class=\"sizeLess20\">XML<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/PowerGadgets\" rel=\"tag\"><span class=\"sizeLess20\">PowerGadgets<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/technorati.com\/tags\/Scripting\" rel=\"tag\"><span class=\"sizeLess20\">Scripting<\/span><\/a><\/div>\n<p><\/p>\n<div class=\"wlWriterSmartContent\" id=\"0767317B-992E-4b12-91E0-4F059A8CECA8:44a0aa66-7030-4e43-a6b5-716e0e8f3a20\" style=\"padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px\"><span class=\"sizeLess20\">del.icio.us tags: <\/span><a href=\"http:\/\/del.icio.us\/popular\/PowerShell\" rel=\"tag\"><span class=\"sizeLess20\">PowerShell<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/del.icio.us\/popular\/XML\" rel=\"tag\"><span class=\"sizeLess20\">XML<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/del.icio.us\/popular\/PowerGadgets\" rel=\"tag\"><span class=\"sizeLess20\">PowerGadgets<\/span><\/a><span class=\"sizeLess20\">, <\/span><a href=\"http:\/\/del.icio.us\/popular\/Scripting\" rel=\"tag\"><span class=\"sizeLess20\">Scripting<\/span><\/a><\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I thought this was going to be a fast and furious example, but it took a whole lot longer than I expected. The good news is that I&#8217;ve done all the work for you.  You&#8217;re most welcome.<\/p>\n<p>I love weather and living in central New York we get all kinds. So I decided I needed a thermometer on my desktop. Using PowerGadget&#8217;s Out-Gauge cmdlet this is pretty easy to do.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[25],"tags":[],"class_list":["post-92","post","type-post","status-publish","format-standard","hentry","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=92"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/92\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}