How to Get Weather Forecast In PowerShell

We will use an open source web service to fetch the weather forecast. can be used not only to check the weather, but also for some other purposes. For example, you can see the current Moon phase. In PowerShell, there is a special alias “curl” for the built-in cmdlet Invoke-RestMethod, which can retrieve the URL contents from the PowerShell console.


To get the weather forecast in PowerShell, you can use the following commands.

To get the current weather in PowerShell, type or copy-paste the following command:

(curl -UserAgent "curl" ).Content



You can specify the desired location as follows:

(curl -UserAgent "curl" ).Content

The output will be as follows:



You can specify the country where you live when required. The syntax is as follows:

(curl"Madrid,Spain" -UserAgent "curl" ).Content

Double quotes are important to ensure that the location will be passed to the service, otherwise you will get an error in PowerShell.




The service supports a number of options.

Alternatively, you can use this command in your terminal:

(curl -UserAgent "curl" ).Content

Here are some useful options.

(curl  -UserAgent "curl" ).Content

This will display the short version of the forecast which includes only Noon and Night.

(curl -UserAgent "curl" ).Content

This will show only the current weather in the specified location.


It is worth mentioning that the service can show the forecast right in your web browser. Point your browser to the same location you use in PowerShell.

If you add “.png” to the location, the service will return a PNG image. You can embed it in your web page.
For example, open this link: