Powershell Get OS Version

Posted: 22nd February 2012 by Ben in For the Technical

Hi,

For those who don’t know I went on and joined the bandwagon after advice from a friend and joined Twitter today. You can “follow” me if that’s what it’s called @awes0meMachine . Hopefully I did that right, I’m still new at this crap.

Anyways- So say you have a crap ton of computers to run a script against, but first you need to know if it’s 2008 or 2003. Here is a nice simple script that will do that:

$computer = "."

$storedVariable = Get-WmiObject -Class Win32_OperatingSystem -computer $computer

foreach ($info in $storedVariable)
{
if ($info.Caption.Contains("2008"))
{Write-Host "It's 2008"}
else
{write-host "It's 2003"}
}

You can change the if statements to do whatever you want, write-host get more information- put files, run things: all that jazz. I’m going to add some twitter shit onto my site here in a little bit- but for now enjoy!

You must be logged in to post a comment.