Ying Li at myITforum.com

PowerShell & System Center

PowerShell script to collect server inventory

$erroractionpreference = "SilentlyContinue"

$a = New-Object -comobject Excel.Application
$a.visible = $True

$b = $a.Workbooks.Add()
$c = $b.Worksheets.Item(1)

$c.Cells.Item(1,1)  = "Organization"
$c.Cells.Item(1,2)  = "Server Name"
$c.Cells.Item(1,3)  = "Operating System"
#$c.Cells.Item(1,4)  = "IP Address"
$c.Cells.Item(1,4)  = "Service Packs"
$c.Cells.Item(1,5)  = "System Type"
$c.Cells.Item(1,6)  = "Install Date"
$c.Cells.Item(1,7)  = "Manufacturer"
$c.Cells.Item(1,8)  = "Model"
$c.Cells.Item(1,9)  = "Service Tag"
$c.Cells.Item(1,10)  = "Serial Number"
$c.Cells.Item(1,11) = "Number of Processors"
$c.Cells.Item(1,12) = "Total Phsyical Memory (GB)"
$c.Cells.Item(1,13) = "Last Reboot Time"
$c.Cells.Item(1,14) = "Report Time Stamp"

$d = $c.UsedRange
$d.Interior.ColorIndex = 19
$d.Font.ColorIndex = 11
$d.Font.Bold = $True

$intRow = 2

$colComputers = get-content C:\MachineList.txt
foreach ($strComputer in $colComputers)
{
$OS = get-wmiobject Win32_OperatingSystem -computername $strComputer
$Computer = get-wmiobject Win32_computerSystem -computername $strComputer
$Bios =get-wmiobject win32_bios -computername $strComputer

$c.Cells.Item($intRow,1)  = $OS.Organization
$c.Cells.Item($intRow,2)  = $strComputer.Toupper()
$c.Cells.Item($intRow,3)  = $OS.Caption
#$c.Cells.Item($intRow,4)  = $IP.IPaddress[0]
$c.Cells.Item($intRow,4)  = $OS.CSDVersion
$c.Cells.Item($intRow,5)  = $Computer.SystemType
$c.Cells.Item($intRow,6)  = [System.Management.ManagementDateTimeconverter]::ToDateTime($OS.InstallDate)
$c.Cells.Item($intRow,7)  = $Computer.Manufacturer
$c.Cells.Item($intRow,8)  = $Computer.Model
$c.Cells.Item($intRow,9)  = $Bios.serialnumber
$c.Cells.Item($intRow,10)  = $OS.SerialNumber
$c.Cells.Item($intRow,11) = $Computer.NumberOfProcessors
$c.Cells.Item($intRow,12) = "{0:N0}" -f ($computer.TotalPhysicalMemory/1GB)
$c.Cells.Item($intRow,13) = [System.Management.ManagementDateTimeconverter]::ToDateTime($OS.LastBootUpTime)

 

$c.Cells.Item($intRow,14) = Get-date
 
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls

 

Posted: May 27 2008, 02:10 PM by yli628 | with 4 comment(s)
Filed under:

Comments

jratzo said:

I think I'm doing something wrong, but how exactly should the MachineList.txt be populated? Just list the names of the server and thats it? This script is creating an excel sheet with Organization, servername, etc. Any help would be appreciated.

This script seems like it would be awesome!

Thanks!

# March 16, 2009 8:03 PM

yli628 said:

Yes, the machinelist.txt looks like this:

server1

server2

server3

...

Let me know if you have further questions?

# March 17, 2009 8:50 AM

jratzo said:

Sorry about that I had it right, I was just copying and pasted the script instead of saving it as a .ps1 and running it.

Thanks

# March 17, 2009 9:06 AM

yli628 said:

That helps! :)

# March 17, 2009 10:37 AM