Creating a PowerShell Weather Command Part 6
Get-OMLocation
I hope you have been enjoying this series and are learning. As with much of my content, the goal isn’t the end product. It is how I got there. You should be able to apply the techniques and concepts I’m using to your own PowerShell work. In the case of this series, you should be learning how to build a tool around a web API. You should be learning how to write basic Pester tests for your scripts. Hopefully, you are also picking up a scripting trick or two. While the destination may be fun and interesting, it is the journey that matters.
If you’ve been following along at home, we have a working function to get current weather conditions using the free Open-Meteo API. We also have a Pester test to validate the code. The value of the Pester test is that not only does it validate that your code works, but it will always work. We started with a simple fixture, wrote tests, and then code to pass the test. With each iteration of the function, re-running the Pester test validates that nothing was broken with the latest change.
My suggestion is to write your Pester tests as you write your code. My current test is over 240 lines of code. It would be daunting to think about writing it all at once. But I didn’t. The size of the file grew organically as I developed my function. If you wait to write the test until your function is complete, odds are, you won’t.
The last major part of my function is being able to get latitude and longitude for the API. If I want to get current weather conditions for Omaha, Nebraska, how can I make this as easy as possible for the user? I found my answer on the weather API page. In the navigation panel, there is a link for Geocoding.