This is an update to the previous script "Query Dell Service Tag".
I couldn't leave well enough alone…
The LazyNetworkAdmin defined his script as,
"Because most of the computers I work on are Dell's,
a lot of times I need to look up the service tag for a specific machine.
Without the need of bulky software, you can easily use WMI to gather this information.
This article will show you how to remotely query your dell pc's for their service tags."
———-COPY EVERYTHING BELOW THIS LINE———-
On Error Resume Next
Const ForWriting = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objDictionary = CreateObject("Scripting.Dictionary")
strDomain = "YOUR_DOMAIN_HERE" ' Your Domain (e.g., monster.com)
strPCsFile = "Service_Tag.txt"
strPath = "C:\scripts\" ' Create this folder
strWorkstationID = "C:\scripts\Service_Tag.txt"
i = 0
'#########
Set objFSO3 = CreateObject("Scripting.FileSystemObject")
If objFSO3.FileExists(strPath & strPCsFile) Then
Set objFolder = objFSO3.GetFile(strPath & strPCsFile)
Else
Set objFSOf = CreateObject("Scripting.FileSystemObject")
If objFSOf.FolderExists(strPath) Then
Set objFolder = objFSOf.GetFolder(strPath)
Else
Set objFolder = objFSO3.CreateFolder(strPath)
End If
Set objFile1 = objFSO3.CreateTextFile(strPath & strPCsFile)
objFile1.Close
End If
'#########
Wscript.Echo "This program will return the Dell Service Tag on remote computer(s)"
strMbox = MsgBox("Would you like info for the entire domain: Matrixsvr ?",4,"Hostname")
If strMbox = 6 Then
'Set objPCTXTFile = objFSO.OpenTextFile(strPath & strPCsFile, ForWriting, True)
Set objDomain = GetObject("WinNT://" & strDomain) ' Note LDAP does not work
objDomain.Filter = Array("Computer")
For Each pcObject In objDomain
objDictionary.Add i, pcObject.Name
'Wscript.Echo objDictionary(i)
i = i + 1
Next
For each DomainPC in objDictionary
strComputer = objDictionary.Item(DomainPC)
GetWorkstationID()
Next
Set objFilesystem = Nothing
WScript.echo "Finished Scanning Network check : " & strPath
Else
strHost = InputBox("Enter the computer you wish to find the Dell Service Tag from","Hostname"," ")
GetWorkstationID2()
End If
Sub GetWorkstationID()
On Error Resume Next
Set objWMIservice = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
strWriteFile = strComputer &" Dell Service Tag: " & objitem.serialnumber
Next
'#############
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strPath & strPCsFile, ForWriting, True)
objOutputFile.WriteLine(strWriteFile)
objOutputFile.Close
'#############
End Sub
Sub GetWorkstationID2()
On Error Resume Next
Wscript.echo strComputer & ": " & objitem.serialnumber
Set objWMIservice = GetObject("winmgmts:\\" & strHost & "\root\cimv2")
set colitems = objWMIservice.ExecQuery("Select * from Win32_BIOS",,48)
For each objitem in colitems
Wscript.echo "Computer: " & strHost & " Dell Service Tag: " & objitem.serialnumber
strWriteFile = "Computer: " & strHost &" Dell Service Tag: " & objitem.serialnumber
Next
'%%%%%%%%%%
Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strPath & strPCsFile, ForWriting, True)
objOutputFile.WriteLine(strWriteFile)
objOutputFile.Close
'%%%%%%%%%%
End Sub
———-COPY EVERYTHING ABOVE THIS LINE———-
PLEASE MAKE SURE NO WORD WRAPPING IS HAPPENING IN YOUR SCRIPT!!!
To make this script work you will need two things!
1. You will need to have Admin privlidges on the target computers.
2. You will need the name of your domain (e.g., strDomain = "YOUR_DOMAIN_HERE" ' Your Domain (e.g., monster.com))
This information is provided "AS IS" with no warranties expressed or implied.