Getting the Computer name, serial number and model from all connected PC..

Hi,
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,
Charles

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 (https://powershell.org/ebooks/).

Chris

Hello,

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
}

you should take a look at Don Jones freebook

https://www.penflip.com/powershellorg/creating-html-reports-in-powershell

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

Win32_ComputerSystem will usually have Manufacturer and Model, also.

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

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    

P.S
Cyril I download the book and I’m reading it shortly

Try this :slight_smile:

$IP = “10.131.199.”
$Subnet = 50
$Address = $IP+$subnet

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

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.

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