Little do many know that PowerShell can be used for all kinds of behind-the-scenes data gathering operations. Any DevOps professional who is overlooking PowerShell as a built-into-Windows data gathering tool should take a second look.
In this example we are going to take a Zip code (I chose 28213 for the example), “feed” it to PowerShell, then return coordinates which could be useful in any number of subsequent operations, including mapping.
First, let’s assign the target ZIP code to a variable.

Next we will grab some data from a convenient API (Application Programming Interface). There are ALOT of open API’s which provide this kind of functionality. Even Google provides this, but using Google’s API is a bit more complex, especially once authentication becomes a factor.

We now have some data stored within the $z variable, but what we actually want is “buried” within the object. Let’s extract that.

Don’t worry about the formats shown. You do not need to learn XML for this tutorial. We are going deeper to the actual metadata.

This gives us more context regarding the data and its source, but it’s still not there data points we want. Let’s go deeper.

We are getting closer. Now we can see the “location” element, which is what we actually want to access. Let’s go in.

Great. We now have arrived at the “point” parameter, within which we will find the data we are looking for. It is worthy of note that our query to this API can include multiple zip codes and a range of the same, but that’s beyond the scope of today’s tutorial.

And now we arrive at actual numerical data for Longitude and Latitude, with regard to our target Zip Code (28213, in this case).
Let’s assign those values to variables we can use later.

Now, we could simply stop here and then we could reference $latlon.latitude and $latlon.longitude when we want to use these coordinates, but I prefer to keep things separate when optimal.

There. Now we have totally separate variables for our latitude and longitude values for the target zip code. From here you could push that data to any number of subsequent scripts, functions, or applications.
You now know how to pull coordinates for a given ZIP code using PowerShell. Please use this newfound power for Good instead of Evil.
-Z
Note: If you find this tutorial valuable, buy me coffee – https://cash.app/$Zeaun
