We help IT Professionals succeed at work.

Re: Remotely Obtain IBM machine Serial Numbers & Machine type For Multiple PCs

Manfredtoo
Manfredtoo asked
on
10,939 Views
Last Modified: 2013-01-10
hi experts
i am looking for a solution that is able to help me remotely obtain machine type and serial number from the IBM machines... thanks inadvance
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, try this little VBS snippet that will return the serial number.  This seems like it needs filtering, so if you could advise what needs changing, please let me know:
'=========
Set WMI = GetObject("WinMgmts:")
Set objs = WMI.InstancesOf("Win32_BaseBoard")
For Each obj In objs
  sAns = sAns & obj.SerialNumber
 If sAns < objs.Count Then sAns = sAns & ","
Next
MBSerialNumber = sAns
MsgBox MBSerialNumber
'=========

Regards,

Rob.

Author

Commented:
hi RobSampson
i manage to obtain the serial number by changing the "win32_BaseBoard" to "win32_Bios". well my objective is to obtain all the ibm serial number with the network. is there a script whereas it able to scan and showing the result containing machine hostname, ip address, machine serial and machine type?

cheers
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Yes, that can be done using a list of computers obtained from your AD.  I would set it up to Ping each computer to see if it's on, then get the data, and output to CSV.

Or, to avoid a scenario where the computer is not on, you could place the script in a Login script instead, and write the data to a network share, into a file name of each PC's serial number (or logon name).  This needs to be individual files to avoid multiple access problems.....

Which would you prefer?

Regards,

Rob.

Author

Commented:
well i prefer the 1st option u gave me by pinging to each computer to obtain information. i would like to check with u, can it be done if i reference the list PCs from a .txt file.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Yes, a text file is just as easy, plus you have more control over the PCs you check.  Also this way you can output non-contactable PCs to another text file for input later.  I'll work on this script.....

Regards,

Rob.

Author

Commented:
thanks robsampson
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Hi, try this VBS file.  Paste the text into Notepad, then "Save as" a file called Get_Details.vbs or something similar with a VBS extension.

Then, drag the text file with computer names in it onto the VBS file, and it will process it.

The output is a CSV file for the computers it could contact, and a plain text file with one computer name per line of computers it could not contact, for you to drag back onto the script later.

'===================
If WScript.Arguments.Count = 0 Then
      MsgBox "Please drag a text file that contains computer names onto this script file for processing."
      WScript.Quit
End If

strInputFile = WScript.Arguments.Item(0)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
strResultsFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "Results_" & Replace(TimeNow(Now), "-", "") & ".csv"
strNoContactFile = Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "NoContact_" & Replace(TimeNow(Now), "-", "") & ".txt"
Set objOutputFile = objFSO.CreateTextFile(strResultsFile, True)
objOutputFile.Write "Host Name,IP Address(es),Serial Number,Model"
Set objNoContactFile = objFSO.CreateTextFile(strNoContactFile, True)
While Not objInputFile.AtEndOfStream
      strComputer = objInputFile.ReadLine
      If Ping(strComputer) = True Then
            Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            
            ' hostname, ip address, machine serial and machine type
            
            ' GET THE IP ADDRESS(ES)
            Set colComputerIP = objWMIService.ExecQuery _
                      ("Select IPAddress from Win32_NetworkAdapterConfiguration")
                  
            strIPAddress = ""
            For Each IPConfig in colComputerIP
                  If Not IsNull(IPConfig.IPAddress) Then
                    For intIPCount = LBound(IPConfig.IPAddress) To UBound(IPConfig.IPAddress)
                              If strIPAddress = "" Then
                                    strIPAddress = IPConfig.IPAddress(intIPCount)
                              Else
                                    strIPAddress = strIPAddress & ";" & IPConfig.IPAddress(intIPCount)
                              End If
                        Next
                  End If
            Next
            
            ' GET THE SERIAL NUMBER
            Set colBIOS = objWMIService.ExecQuery _
                ("Select SerialNumber from Win32_BIOS")
            
            For Each objBIOS In colBIOS
                  strSN = strSN & objBIOS.SerialNumber
            Next
            
            ' GET THE COMPUTER MODEL AND HOSTNAME
            Set colComputer = objWMIService.ExecQuery _
                ("Select Model, Name from Win32_ComputerSystem")
            
            For Each objComp In colComputer
                  strModel = objComp.Model
                  strHostname = objComp.Name
            Next
            
            objOutputFile.Write VbCrLf & Trim(strHostname) & "," & Trim(strIPAddress) & "," & Trim(strSN) & "," & Trim(strModel)
      Else
            objNoContactFile.WriteLine Trim(strComputer)
      End If
Wend
objInputFile.Close
objOutputFile.Close
objNoContactFile.Close
Set objInputFile = Nothing
Set objOutputFile = Nothing
Set objNoContactFile = Nothing

MsgBox "Finished processing the input file." & VbCrLf & "Results are in: " & strResultsFile & VbCrLf & "PCs not found: " & strNoContactFile

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function

Function TimeNow(dDateTime)
      TimeNow =      Year(Now) & "-" &_
                        Right("00" & Month(Now), 2) & "-" &_
                        Right("00" & Day(Now), 2) & "-" &_
                        Right("00" & Hour(Now), 2) & "-" &_
                        Right("00" & Minute(Now), 2) & "-" &_
                        Right("00" & Second(Now), 2)
End Function
'===================

Regards,

Rob.

Author

Commented:
hi robsampon
thanks for the script,  its amazing. well i have couple of problems or should i say touch up =)
firstly it shows Line:19 char:13 error: permission denial 'Getobject' code:800A0046 source: microsoft vbscript runtime error while scanning half way thru guess for those pc does not allow to access cimv2. juz to update not all pc in my environment are ibm machines therefore is it possible to ignore and proceed it on the plotting of the data?
secondly, it would be the serial numbers all append together, as in the serial will not flush off, it takes the previous serial and append the current serial
cheers

Author

Commented:
hi rob
i managed to find the error for serial number issue, i mentioned earlier, it due to this statement strSN = strSN & objBIOS.SerialNumber with an extra  "strSN &" word. but as for the permission issue could you help me look into it? whereas i guess when it ping its gets reply from the pc but not able to access WMI.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
hi rob
thanks so much for adding the error checking for me. thanks you so much for your help. it works great.

Commented:
This is one excellent script Rob
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2014

Commented:
Thanks Sharath, it's good to just drag a text file onto the script....works pretty well.....

Rob.

Author

Commented:
rob indeed its a very cool script. =)

Commented:
Hi !
Nice script .. really like it.

I'm pushing an update to all my pc  and in my log file  it's creating a txt  with computername  username date time  but i would like to include model and serial number.  All IBM machine.

here's my log.bat

@echo off
for /f %%i in ('time /t') do set Heure=%%i
for /f "delims= tokens=1,2" %%i in ('date /t') do set Calendrier=%%i %%j
echo %computername%-%username% %Calendrier% %Heure% >> "J:\GENASDV2\Install Logs\sygate\log.txt"


How do I include the serial number and model type.

Commented:
You rock man. It is such a handy script. Its make my life easy.
I know this was a while ago but thanks, great!
Rob, just wanted to say thanks as well.  Great script!
I just joined Experts Exchange today and this was the first thing I ran across.  I must say "This script is Flippin amazing" Thanks Rob!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.