Wednesday, January 7, 2015

(PowerShell) WindowsOS Version (Linux Style)

I decided to do this blog to prove that I can learn something that is worth writing down (and using again at a later time) everyday. It might boring on some days but hopefully I will have some useful info here. So off we go...

==================================================

I wanted a way to to list the Windows OS Version similar to how I can
in Ubuntu.

lsb_release -d







So I tried

Get-WmiObject -Class Win32_OperatingSystem

Which by default returns (Not really what I was looking for)








After digging through the properties a little What I ended up using was

(Get-WmiObject -Class Win32_OperatingSystem).caption

This returns (Exactly what I was looking for)



I added this as an alias so I do not have to type this in every time.
I had to make the function first and then alias that, using the command
itself did not work (It was trying to assign the alias to the caption
string object).

Note: There may be an easier way to do this, I will update if I find it.

function fget_os {(Get-WmiObject -Class Win32_OperatingSystem).caption}

Set-Alias getos fget_os


Done :)