{"id":2550,"date":"2018-07-31T19:02:02","date_gmt":"2018-07-31T19:02:02","guid":{"rendered":"http:\/\/microsoftgeek.com\/?p=2550"},"modified":"2018-07-31T19:12:37","modified_gmt":"2018-07-31T19:12:37","slug":"how-to-get-weather-forecast-in-powershell","status":"publish","type":"post","link":"https:\/\/microsoftgeek.com\/?p=2550","title":{"rendered":"How to Get Weather Forecast In PowerShell"},"content":{"rendered":"<p>We will use an open source web service wttr.in to fetch the weather forecast. Wttr.in can be used not only to check the weather, but also for some other purposes. For example, you can see the current Moon phase.\u00a0In PowerShell, there is a special alias &#8220;curl&#8221; for the built-in cmdlet\u00a0<strong><em>Invoke-RestMethod<\/em><\/strong>, which can retrieve the URL contents from the PowerShell console.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>To get the weather forecast in PowerShell<\/strong>, you can use the following commands.<\/p>\n<p>To get the current weather in PowerShell, type or copy-paste the following command:<\/p>\n<pre><span style=\"color: #ff00ff;\">(curl http:\/\/wttr.in\/?Q0 -UserAgent \"curl\" ).Content<\/span>\r\n\r\n<a href=\"http:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-localweather.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2551\" src=\"http:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-localweather.png\" alt=\"\" width=\"673\" height=\"219\" srcset=\"https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-localweather.png 673w, https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-localweather-300x98.png 300w\" sizes=\"auto, (max-width: 673px) 100vw, 673px\" \/><\/a>\r\n\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>You can specify the desired location as follows:<\/p>\n<pre><span style=\"color: #ff00ff;\">(curl http:\/\/wttr.in\/NewYork -UserAgent \"curl\" ).Content<\/span><\/pre>\n<p>The output will be as follows:<\/p>\n<p><a href=\"http:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-NYC.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2552\" src=\"http:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-NYC.png\" alt=\"\" width=\"1018\" height=\"636\" srcset=\"https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-NYC.png 1018w, https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-NYC-300x187.png 300w, https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-NYC-768x480.png 768w\" sizes=\"auto, (max-width: 1018px) 100vw, 1018px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>You can specify the country where you live when required. The syntax is as follows:<\/p>\n<pre><span style=\"color: #ff00ff;\">(curl http:\/\/wttr.in\/\"Madrid,Spain\" -UserAgent \"curl\" ).Content<\/span><\/pre>\n<p>Double quotes are important to ensure that the location will be passed to the service, otherwise you will get an error in PowerShell.<\/p>\n<p><a href=\"http:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-spain.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2555\" src=\"http:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-spain.png\" alt=\"\" width=\"1018\" height=\"636\" srcset=\"https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-spain.png 1018w, https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-spain-300x187.png 300w, https:\/\/microsoftgeek.com\/wp-content\/uploads\/2018\/07\/PS-spain-768x480.png 768w\" sizes=\"auto, (max-width: 1018px) 100vw, 1018px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>The service supports a number of options.<\/p>\n<p>Alternatively, you can use this command in your terminal:<\/p>\n<pre><span style=\"color: #ff00ff;\">(curl http:\/\/wttr.in\/:help -UserAgent \"curl\" ).Content<\/span><\/pre>\n<p>Here are some useful options.<\/p>\n<pre><span style=\"color: #ff00ff;\">(curl wttr.in\/New-York?n  -UserAgent \"curl\" ).Content<\/span><\/pre>\n<p>This will display the short version of the forecast which includes only Noon and Night.<\/p>\n<pre><span style=\"color: #ff00ff;\">(curl wttr.in\/New-York?0 -UserAgent \"curl\" ).Content<\/span><\/pre>\n<p>This will show only the current weather in the specified location.<\/p>\n<p>&nbsp;<\/p>\n<p>It is worth mentioning that the <strong>wttr.in<\/strong> service can show the forecast right in your web browser. Point your browser to the same location you use in PowerShell.<\/p>\n<p>If you add &#8220;.png&#8221; to the location, the service will return a PNG image. You can embed it in your web page.<br \/>\nFor example, open this link:\u00a0<span style=\"color: #ff00ff;\"><a style=\"color: #ff00ff;\" href=\"http:\/\/wttr.in\/New-York.png\" rel=\"norefferer nofollow\">http:\/\/wttr.in\/New-York.png<\/a><\/span><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We will use an open source web service wttr.in to fetch the weather forecast. Wttr.in can be used not only to check the weather, but also for some other purposes. For example, you can see the current Moon phase.\u00a0In PowerShell, there is a special alias &#8220;curl&#8221; for the built-in cmdlet\u00a0Invoke-RestMethod, which can retrieve the URL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[],"class_list":["post-2550","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2550","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2550"}],"version-history":[{"count":14,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2550\/revisions"}],"predecessor-version":[{"id":2567,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=\/wp\/v2\/posts\/2550\/revisions\/2567"}],"wp:attachment":[{"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2550"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2550"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/microsoftgeek.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2550"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}