Browsing Category

Information Technology Mastery

Information Technology Mastery,

PowerShell Tutorial: Programmatically Retrieving the Population of each US State

Data science is all the rage these days, but data science requires data. PowerShell may usually be thought of as a Sysadmin utility, but it can be used for an absolutely amazing number of process automation and business automation tasks, including gathering raw data for use by other applications.

In this example we will gather the population data for each state in the USA, using Census data. Here is some metadata on our source:

Source metadata

Now, let’s get to work, first by creating our function declaration, which we will call “statepop”, in this case.

Information Technology Mastery,

Tutorial: Getting the current price of Bitcoin using Powershell (USD, EUR, & GBP)

I began my Bitcoin journey in 2012, with CPU mining, back when that was still profitable. Some of you are just now joining the cryptocurrency wave, and that’s fine. Like all waves it will feel great while rising and will feel horrible while falling.

But, since we are working in the “Now”, let’s get some work done.

We want the price of bitcoin, in 3 currencies, from our PowerShell console window. Let’s get it.

Assign the now-familiar (if you have been following the series) $zurl variable

We begin, as we often do in these tutorials, with assigning the $zurl variable to identify our data source within PowerShell.

Make sure to enable TLS 1.2 within PowerShell
Information Technology Mastery,

Tutorial: Public IP Address Identification with PowerShell

A common task-within-a-task for Sysadmins is locating the Public-facing IP Address for a given Windows Server.

This may be done for the purposes of testing a new web app, or for the configuration of public DNS records.

Whatever the reason, here is an easy way to obtain that information without using a browser (especially since many sites which claim to be for public IP address identification are packed with ads, scripts, and other elements a wise System Administrator would avoid accessing from a server, especially while logged in with administrative credentials.

First, we assign a target URL to a variable called “$zurl”. The URL provided returns the data we need when called.

Assigning the $zurl variable

Now we have our URL stored as a string variable. You can always test the contents of a string variable by simply typing the variable name and pressing ENTER.

Information Technology Mastery,

Browsing NASA’s Image of The Day Archive using PowerShell

Welcome back to this series on Microsoft Windows PowerShell mastery, utilizing real-world examples you can make use of today.

Assign the URL to the $zurl variable

Next, you may need to tell PowerShell to respect TLS 1.2, as it does not by default, even though ALOT of websites use this as their SSL (Secure Sockets Layer) method. Your PC or server may already have TLS 1.2 enabled, so proceed on this item as needed. If you get an error that says an SSL connection could not be established, this is likely what is required to move past it.

Note: This change applies only to the current session, and must be reset each time – so include it in your script if you do not have TLS 1.2 enabled across the board.

Enable TLS 1.2
Information Technology Mastery,

Getting Latitude and Longitude for a given Zip Code with PowerShell

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.

Assigning 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.

Assigning the result to a variable

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

Information Technology Mastery,

Reading Reddit News via PowerShell

The “Meat” of the method

The provided image gives you the core of the method, but I will elaborate further for the “Uninitiated”.

Many websites publish their content, or a subset thereof, as RSS feeds. RSS means “Really Simple Syndication” and is a structured methodology for offering news and articles in a format which standardized for access and interpretation by multiple viewers and viewing platforms.

This is not to say that the full content of most news sites is available via this method, however. Far from it. In fact many news sources limit the number of characters, lines, or even which articles are contained within the Feed.

Many news sources made the above shift (to limited Feed content) as a result of “content theft” (as they saw it) but other websites who were, in many cases, accused of wholesale copying of content from source sites.

But, enough about that. Today we will cover how you can use PowerShell to read the headlines and content from Reddit’s World News Subreddit, starting with the “Invoke-Restmethod” commandlet.