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

Welcome Forums General PowerShell Q&A Getting the Computer name, serial number and model from all connected PC..

This topic contains 9 replies, has 7 voices, and was last updated by

 
Participant
3 years, 3 months ago.

  • Author
    Posts
  • #31264

    Participant
    Points: 0
    Rank: Member

    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

  • #31266

    Participant
    Points: 0
    Rank: Member

    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

  • #31267

    Participant
    Points: 0
    Rank: Member

    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
    }

  • #31268

    Participant
    Points: 0
    Rank: Member

    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

  • #31269

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Win32_ComputerSystem will usually have Manufacturer and Model, also.

  • #31270

    Keymaster
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

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

  • #31273

    Participant
    Points: 0
    Rank: Member

    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

  • #31297

    Participant
    Points: 0
    Rank: Member

    Try this 🙂

    $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)

  • #31298

    Participant
    Points: 0
    Rank: Member

    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.

  • #31314

    Participant
    Points: 0
    Rank: Member

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

The topic ‘Getting the Computer name, serial number and model from all connected PC..’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort