Author Posts

October 23, 2015 at 11:57 am

I'm looking to obtain the computer name, serial number and model from a range of IP addresses(50-254). So far I managed to get the computer names but I'm stuck with the other two. Also there is any way to know when I got an error (like access denied) from which IP it was. Right now when I got that error the script continue to run but I have no clue which PC fail.

Thank you,

October 23, 2015 at 12:04 pm

I would take a look at the Win32_BIOS and Win32_Baseboard classes (Get-WMIObject). Both have a serial number field but I have had better luck with Win32_BIOS. Win32_Baseboard will often continue manufacturer and model number.

As far as determining which system an error came from you can try utilizing a try catch block. If you aren't familiar with error handling, there is a free ebook on this very site (


October 23, 2015 at 12:07 pm


you could try something like

$list = get-content .\IP_list.txt

foreach($svr in $list)
(get-WmiObject -ComputerName $svr win32_computersystem).name
(get-WmiObject -ComputerName $svr win32_computersystem).model
(Get-WmiObject -Computername $svr win32_bios).serialnumber

October 23, 2015 at 12:07 pm

you should take a look at Don Jones freebook

he provides a bunch of examples with wmi that can help you

October 23, 2015 at 12:07 pm

Win32_ComputerSystem will usually have Manufacturer and Model, also.

October 23, 2015 at 12:08 pm

And if you're interested "Learn PowerShell Toolmaking in a Month of Lunches" uses pretty much what you're after as its running example.

October 23, 2015 at 12:34 pm

This is where I'm right now..
$oct4 = 50..254
foreach ($oct_a in $octet4) {

if (Test-Connection "10.131.199.$oct_a" -Count 1 -Quiet) {

$Computers=Get-WmiObject Win32_ComputerSystem -ComputerName "10.131.199.$octb" -ErrorAction ignore | Select-Object -ExpandProperty name
$Computers | Export-Csv -Path computers.csv

} #end if

} #End foreach

Cyril I download the book and I'm reading it shortly

October 24, 2015 at 7:59 am

Try this 🙂

$IP = "10.131.199."
$Subnet = 50
$Address = $IP+$subnet

Test-Connection $Address -Count 1
Get-WmiObject Win32_ComputerSystem -ComputerName $Address | select name,model
Get-WmiObject Win32_BIOS -ComputerName $Address | select serialnumber
$Address = $IP+$subnet
}While($Subnet -le 254)

October 24, 2015 at 11:24 am

Was that a typo? You're putting your range in $oct4 but iterating over $octet4. Your iterator is $oct_a, but then you're using $octb (undefined) as the last octet in the address.

October 26, 2015 at 5:22 am

Thank you Mike, it works like a charm.
Bob, Yes, it was a typo.. Thank you though..