Get OS of the instance. Or, Gods forbid, SQL version…

I’ve thought about this long and hard. More ‘longer’ than ‘harder’, but still 🙂

The conclusion was that the blog won’t have much sense if I keep updating it once every few months. So I’ll minimize, or completely drop, the teaching tone from my posts.

Time taken to dissect every line of code isn’t worth it, really. If you’d like to go deeper into something that interests you, drop me a line and we can have a chat about it. Much better use of time than laying it all out initially… for nobody to read 🙂

So there you have it. This is about to become a soulless code dump place… But at least I’ve created a GitHub account! Yay! 🙂

First thing on the menu is my today’s puzzle. “How to find out which of my instances are running Windows and which run Linux?”

The easiest way would be to run Get-EC2Instance and get the Platform parameter. Conveniently, this is set to “Windows” for Windows OS, and not set at all for any other one.

Not helpful.

Let’s see if we can get something from the AMI instance was launched from.

Grab the instance information in the variable (or use the ImageId) and run:

Did you get the AMI information? Awesome! Use $Image.Name and $Image.Description to get all the juicy data from it. Is it Windows? Does it have SQL? Is it Linux? Which flavor/edition/version?

But what if I don’t get anything?!

If you can’t get any information from Get-EC2Image, let’s hope you followed best practices and have everything tagged nicely. Otherwise, you’ll need to query for the $Instance.Platform. Is it “Windows” or blank?

Let’s run Get-EC2Tag and see what you did:

Do you see only “Name” under “Key” column? Yep, you’re doing it wrong.

Or, do you see something like this?

Awesome! But, if not, you’re pretty much screwed. Unless you run SSM Agent everywhere and tell it to grab inventory for you to parse. That will definitely be less horrible than having no choice at all, but I won’t be covering it here.

Here’s the script. You can find it on GitHub now, too.

This is what you’ll get:

Leave a Comment