Announcement

Collapse
No announcement yet.

Script to get Serial Number from a list of computer.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script to get Serial Number from a list of computer.

    Hello to all,
    I am in the need to write a script to obtain the serial number and model from a list of computer, I have the script below which work fine when it's only one computer but I don't know how to make it work to pick up a list of computer from a text file. Any ideas are welcome,
    Thanks in advance,

    Code:
    On Error Resume Next 
    
    Dim strComputer
    strComputer = InputBox("Enter the name of the computer:") 
    
    Set objWMIService = GetObject("winmgmts:" _
       & "{impersonationLevel=impersonate}!\\"  _
       & strComputer & "\root\cimv2") 
    
    Set colSMBIOS = objWMIService.ExecQuery _
       ("Select * from Win32_SystemEnclosure") 
    For Each objSMBIOS in colSMBIOS
       MsgBox strComputer & ": " & objSMBIOS.SerialNumber
    Next
    
    Set colItems = objWMIService.ExecQuery _
       ("Select * from Win32_ComputerSystem")
    For Each objItem in colItems
       Wscript.Echo "System Name: " & objItem.Name
       Wscript.Echo "Manufacturer: " & objItem.Manufacturer
       Wscript.Echo "Model: " & objItem.Model
    Next
    
    Call retrieve_Space
    
    Public sub retrieve_Space
       Const HARD_DISK = 3
    
       Set objWMIService = GetObject("winmgmts:" _
         & "{impersonationLevel=impersonate}!\\" _
         & strComputer & "\root\cimv2")
    
       Set colDisks = objWMIService.ExecQuery _
         ("Select * from Win32_LogicalDisk Where DriveType = " _
         & HARD_DISK & "")
       For Each objDisk in colDisks
         msgbox "DeviceID: " & objDisk.DeviceID
         msgbox "Free Disk Space: " &  objDisk.FreeSpace
       Next
    End Sub
    Last edited by Rems; 28th September 2009, 21:56. Reason: replaced quote-tags with code-tags

  • #2
    Re: Script to get Serial Number from a list of computer.

    Code:
    Const ForReading = 1
    strReadFile = "C:\computers.txt"
    
    ' start reading computer names from the text file
    With CreateObject("Scripting.FileSystemObject")
       Set objTextFile = .OpenTextFile _
          (strReadFile, ForReading)
       intSize = 0
       Do Until objTextFile.AtEndOfStream
          strComputer = trim(objTextFile.ReadLine)
          If strComputer <> Empty then
            ReDim Preserve arrComputers(intSize)
            arrComputers(intSize) = strComputer
            intSize = intSize + 1
          End If
       Loop
       objTextFile.Close: Set objTextFile = Nothing
    End With
    If not IsArray(arrComputers) _
       Then wscript.echo "No Computers!": wscript.quit(0)
    
    Dim strComputer
    For Each strComputer in arrComputers
    
       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
       ' your script comes here, but without!!! the folowing 2 lines,
       '     Dim strComputer
       '     strComputer = InputBox("Enter the name of the computer:")
       '
       ' btw... You create the objWMIService 2x in your 
       ' script, while the first only would be sufficient.
       ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    
    Next
    wscript.quit 0
    Similar Thread
    http://forums.petri.com/showthread.php?t=35894

    \Rems

    This posting is provided "AS IS" with no warranties, and confers no rights.

    __________________

    ** Remember to give credit where credit's due **
    and leave Reputation Points for meaningful posts

    Comment


    • #3
      Re: Script to get Serial Number from a list of computer.

      Rems
      Thanks for taking your time to reply to my post and suggesting that similar threat, which by the way has some scripts that are more sophisticated, I liked the option of dumping the results into a spreadsheet. I am closing this post since is a repeated issue.
      Thanks again for your help,
      Alex

      Comment

      Working...
      X