+ Post New Thread
Results 1 to 4 of 4
Scripts Thread, Script to find serial numbers of all computers on network in Coding and Web Development; Hi. I've found a script to do this for 1 computer at a time but does anyone know how to ...
  1. #1
    bandgeekmafia78's Avatar
    Join Date
    May 2007
    Location
    Salford
    Posts
    382
    Thank Post
    88
    Thanked 22 Times in 14 Posts
    Rep Power
    21

    Script to find serial numbers of all computers on network

    Hi.

    I've found a script to do this for 1 computer at a time but does anyone know how to change this to find ALL serial numbers in one go?

    ComputerName = InputBox("Enter the name of the computer you wish to query")

    winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""

    'WScript.Echo winmgmt1

    Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")

    for each SN in SNSet
    MsgBox "The serial number for the specified computer is: " & SN.SerialNumber
    Next

    Any help would be much appreciated!

    Alan.

  2. #2

    Steve21's Avatar
    Join Date
    Feb 2011
    Location
    Swindon
    Posts
    2,686
    Thank Post
    333
    Thanked 513 Times in 481 Posts
    Rep Power
    178
    Code:
    Dim myArray(3)
    myArray(0) = "BoB1"
    myArray(1) = "BoB2"
    myArray(2) = "BoB3"
    myArray(3) = "BoB4"
    
    
    For i = 0 To UBoundmyArray
    
    ComputerName = myArrayi
    
    winmgmt1 = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
    
    'WScript.Echo winmgmt1
    
    Set SNSet = GetObject( winmgmt1 ).InstancesOf ("Win32_BIOS")
    
    for each SN in SNSet
    MsgBox "The serial number for the specified computer is: " & SN.SerialNumber
    Next
    
    Next
    Is the basic code that should work, obviously need to populate the arrays etc.

    Steve

  3. Thanks to Steve21 from:

    bandgeekmafia78 (17th May 2011)

  4. #3

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,767
    Thank Post
    840
    Thanked 1,663 Times in 1,448 Posts
    Blog Entries
    11
    Rep Power
    442
    Not sure about yours but this will find all the serial numbers and dump them into a CSV file

    Inventory Your network

  5. Thanks to FN-GM from:

    bandgeekmafia78 (17th May 2011)

  6. #4

    Join Date
    May 2011
    Location
    Alexandria, VA
    Posts
    8
    Thank Post
    0
    Thanked 1 Time in 1 Post
    Rep Power
    0
    Code:
    $ErrorActionPreference = "SilentlyContinue"
    
    #Replace with your computer OU
    $OU = "OU=Computers,DC=domain,DC=local"
    $LdapFilter = "(&(objectCategory=computer))"
    
    $objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://"+$OU)
    $objADsearcher = New-Object System.DirectoryServices.DirectorySearcher
    $objADsearcher.SearchRoot = $objDomain
    $objADsearcher.filter = "$LdapFilter"
    
    $colProplist = "cn"
    foreach ($i in $colPropList){$objADsearcher.PropertiesToLoad.Add($i)}
    
    $objResults = $objADsearcher.findall()
    $AllComputers = @()
    $ComputerObj = @()
    
    $ComputerObj = New-Object psObject
    
    Foreach ($objresult in $objResults ) {
        $ComputerObj = @()
        $ComputerObj = New-Object psObject
    	$CN = ($objResult.GetDirectoryEntry().cn).ToString().TrimEnd()
    	$ComputerObj | Add-Member -MemberType NoteProperty -Name "CN" -Value $CN -Force
    	If ($result = test-connection -computername $CN -Quiet -Count 2 -TimeToLive 5){
    		$ComputerObj | Add-Member -MemberType NoteProperty -Name "Model" -Value ((Get-WmiObject -class win32_computersystem -computername $CN).model) -Force
    		$ComputerObj | Add-Member -MemberType NoteProperty -Name "Manufacturer" -Value ((Get-WmiObject -class win32_bios -computername $CN).manufacturer) -Force
    		$ComputerObj | Add-Member -MemberType NoteProperty -Name "Serial" -Value ((Get-WmiObject -class win32_bios -computername $CN).serialnumber) -Force
    	} Else { 
    		$ComputerObj | Add-Member -MemberType NoteProperty -Name "Model" -Value "Not Found" -Force
    		$ComputerObj | Add-Member -MemberType NoteProperty -Name "Manufacturer" -Value "Not Found" -Force
    		$ComputerObj | Add-Member -MemberType NoteProperty -Name "Serial" -Value "Not Found" -Force
    	}
    	$ComputerObj | ft
    	$AllComputers += $ComputerObj
    }
    
    $file = "ComputerInventory_" + (Get-Date -Format "yyyyMMdd") + ".csv"
    $AllComputers |Sort-Object "CN" | Export-Csv "$file" -NoTypeInformation
    Requires Powershell. I'm using 2.0 but I don't think there is anything in there that won't work in 1.0. Haven't tested for backwards compatibility.
    Finds computers in AD using designated OU as starting point.
    Sends ping to verify host is online before querying WMI.
    Exports results to CSV.

    Having an issue with a couple of PCs where access to WMI is being denied. In these cases the fields for Model, Serial, Manufacturer will be blank instead of "Not Found". I imagine it is an issue with WMI on those workstations and will have to investigate.

SHARE:
+ Post New Thread

Similar Threads

  1. How do I find my Promethean product serial number?
    By markrobinson in forum Promethean Direct Support
    Replies: 8
    Last Post: 2nd March 2011, 09:41 AM
  2. Find AD computers no longer in school
    By edutech4schools in forum Windows Server 2000/2003
    Replies: 10
    Last Post: 1st March 2011, 12:17 PM
  3. How could I find if a file exists on multiple computers?
    By reggiep in forum How do you do....it?
    Replies: 2
    Last Post: 13th September 2010, 11:12 AM
  4. Serial Numbers
    By HTCIT in forum Windows
    Replies: 6
    Last Post: 6th October 2009, 07:08 PM
  5. Useful contact numbers when contacting support numbers
    By ranj in forum Comments and Suggestions
    Replies: 10
    Last Post: 22nd December 2006, 08:21 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •