Retrieve Server OS and platform using Powershell

Post date: Nov 30, 2010 1:6:6 PM

I was looking for a way to get an overview of all servers in the domain regarding to Operating System and platform.

This is the first script in here using get-WMIOBJECT

Use WMI Explorer to find the properties you are looking for.

Again, if i can be of any help, just let me know.

Here's the script, it gives an idea how to use the get-wmiobject command in PS:

cls

$strPath="c:\xml\computers.xls"

$a = new-object -comobject excel.application

$a.Visible = $true

if (Test-Path $strPath)

{

# Open the document

$b = $a.WorkBooks.Open($strPath)

$c = $b.Worksheets.Item(1)

} else {

# Create It

$b = $a.Workbooks.Add()

$c = $b.Worksheets.Item(1)

#$c.Cells.Item(1,1) = "_Computername"

#$c.cells.item(1,2) = "_Operating System"

#$c.cells.item(1,3) = "_Harware model"

$d = $c.UsedRange

$d.Interior.ColorIndex = 19

$d.Font.ColorIndex = 11

$d.Font.Bold = $True

}

$introw = $c.UsedRange.Rows.Count + 1

$computers = Get-QADComputer -OSName 'Windows*Server*'

foreach ($computer in $computers){

$name = $computer.name

$OS = $computer.operatingSystem

$uuu = $OS.Substring(0,14)

$ServerOS = Get-WmiObject Win32_OperatingSystem -ComputerName $computer.name

$Platform = Get-WmiObject Win32_ComputerSystem -ComputerName $computer.name

$SOS = $ServerOS.caption

$hw = $Platform.Model

if ($uuu -eq 'Windows Server') {

$introw = $introw + 1

$c.cells.item($introw, 1) = $name

$c.cells.item($introw, 2) = $SOS

$c.cells.item($introw, 3) = $hw

}}

$objRange = $c.UsedRange

$objRange2 = $a.Range("A1")

[void] $objRange.Sort($objRange2)

$objRange.NumberFormat = "0#########"

$objRange.EntireColumn.AutoFit() |out-null