Quantcast
Channel: PowerShell General
Viewing all articles
Browse latest Browse all 10624

Computer inventory script

$
0
0

Greetings everyone,

I've hacked together a script to get some basic computer info using wmi. The below script works, the problem I have is getting the IP address info. I don't get any error just don't get any result for the IP address. Any ideas what I'm doing wrong?

 

Thanks in advance

$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) = "Server Name"
$c.Cells.Item(1,2) = "Operating System"
$c.Cells.Item(1,3) = "System Type"
$c.Cells.Item(1,4) = "Manufacturer"
$c.Cells.Item(1,5) = "Model"
$c.Cells.Item(1,6) = "Service Tag"
$c.Cells.Item(1,7) = "Last Reboot Time"
$c.Cells.Item(1,8) = "IP Address"

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

$intRow = 2

$colComputers = get-content C:\scripts\computers.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
$Network = Get-WmiObject Win32_NetworkAdapterConfiguration -computerName $strComputer

$c.Cells.Item($intRow,1) = $strComputer.Toupper()
$c.Cells.Item($intRow,2) = $OS.Caption
$c.Cells.Item($intRow,3) = $Computer.SystemType
$c.Cells.Item($intRow,4) = $Computer.Manufacturer
$c.Cells.Item($intRow,5) = $Computer.Model
$c.Cells.Item($intRow,6) = $Bios.serialnumber
$c.Cells.Item($intRow,7) = [System.Management.ManagementDateTimeconverter]::ToDateTime($OS.LastBootUpTime)
$c.Cells.Item($intRow,8) = $Network.IpAddress[0]
$intRow = $intRow + 1
}
$d.EntireColumn.AutoFit()
cls


Viewing all articles
Browse latest Browse all 10624

Trending Articles