Get PC name from Dell Service Tag

Home Forums Scripting Windows Script Host Get PC name from Dell Service Tag

This topic contains 7 replies, has 5 voices, and was last updated by Avatar reddurex 6 years, 5 months ago.

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • Avatar
    GTTDi
    Member
    #161522

    Hi,

    I am wondering if it is possible to do the following with a VBScript:

    To get the PC name from just the DELL Service Tag?

    Any help would be greatly appreciated.

    EDIT:
    Startup script is not an option :( am not allowed use it

    Rems
    Rems
    Moderator
    #228294

    Re: Get PC name from Dell Service Tag

    What is your goal exactly?

    You could write a script that tries to connect to every client computer in AD. Or use a startup script that will run on every client. If the tag number is a match then the script logs the name of that computer to somewhere.

    /Rems

    Avatar
    zainulpatel
    Member
    #387643

    Re: Get PC name from Dell Service Tag

    My goal is, i have some PCs that i only have a record of there Service Tag and need to find the PC name associated with the specific service tags.

    Rems
    Rems
    Moderator
    #228295

    Re: Get PC name from Dell Service Tag

    GTTDi;272600 wrote:
    My goal is, i have some PCs that i only have a record of there Service Tag and need to find the PC name associated with the specific service tags.

    EDIT:
    Startup script is not an option :( am not allowed use it

    OK, how cAn we run the script, by visiting every computer with a pen drive in your hand maybe? Or can you run a script remotely against a group of computers (what’s the OS)?

    /Rems

    Avatar
    roshihan
    Member
    #387534

    Re: Get PC name from Dell Service Tag

    First, get a list of all machines in your domain and put them in a text file called pcs.txt, for example. One hostname per line.

    Take the following VBScript snippet and save it to a file called GetSerial.vbs (or whatever you like):

    On Error Resume Next

    strComputer = WScript.Arguments(0)

    UserName = “”
    Password = “”

    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,UserName,Password)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    For Each objItem in colItems
    WScript.Echo strComputer & vbTab & objItem.Manufacturer & vbTab & objItem.SerialNumber
    Next
    Else
    WScript.Echo strComputer & vbTab & “WMI Error” & vbTab & Err.Description
    End If[/CODE]

    Now run the script against every PC in the list to get the serial numbers back for identification. From a CMD prompt run:

    [CODE]for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]

    It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script ([B]not [/B]recommended).[CODE]On Error Resume Next

    strComputer = WScript.Arguments(0)

    UserName = “”
    Password = “”

    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,UserName,Password)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    For Each objItem in colItems
    WScript.Echo strComputer & vbTab & objItem.Manufacturer & vbTab & objItem.SerialNumber
    Next
    Else
    WScript.Echo strComputer & vbTab & “WMI Error” & vbTab & Err.Description
    End If[/CODE]

    Now run the script against every PC in the list to get the serial numbers back for identification. From a CMD prompt run:

    for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]

    It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script ([B]not [/B]recommended).[CODE]for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]

    It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script (not recommended).

    Avatar
    reddurex
    Member
    #388044

    Re: Get PC name from Dell Service Tag

    noxigen;272829 wrote:
    First, get a list of all machines in your domain and put them in a text file called pcs.txt, for example. One hostname per line.

    Take the following VBScript snippet and save it to a file called GetSerial.vbs (or whatever you like):

    On Error Resume Next

    strComputer = WScript.Arguments(0)

    UserName = “”
    Password = “”

    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,UserName,Password)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    For Each objItem in colItems
    WScript.Echo strComputer & vbTab & objItem.Manufacturer & vbTab & objItem.SerialNumber
    Next
    Else
    WScript.Echo strComputer & vbTab & “WMI Error” & vbTab & Err.Description
    End If[/CODE]Now run the script against every PC in the list to get the serial numbers back for identification. From a CMD prompt run:

    [CODE]for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script ([B]not [/B]recommended).[/QUOTE]

    Instead of using batch, why not put all of that functionality into the VBS script? :idea:[CODE]On Error Resume Next

    strComputer = WScript.Arguments(0)

    UserName = “”
    Password = “”

    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,UserName,Password)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    For Each objItem in colItems
    WScript.Echo strComputer & vbTab & objItem.Manufacturer & vbTab & objItem.SerialNumber
    Next
    Else
    WScript.Echo strComputer & vbTab & “WMI Error” & vbTab & Err.Description
    End If[/CODE]Now run the script against every PC in the list to get the serial numbers back for identification. From a CMD prompt run:

    for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script ([B]not [/B]recommended).[/QUOTE]

    Instead of using batch, why not put all of that functionality into the VBS script? :idea:[CODE]for /f %a in (pcs.txt) do cscript /nologo GetSerial.vbs %a >>serials.log[/CODE]It will attempt a remote WMI connection to each PC and query the serial number. All results will be logged to the serials.log file. Make sure to run the script while logged in as a user with admin rights on all PCs. You can also hard code the credentials in the script (not recommended).

    Instead of using batch, why not put all of that functionality into the VBS script? :idea:

    Avatar
    roshihan
    Member
    #387539

    Re: Get PC name from Dell Service Tag

    Out of habit. I usually create scripts that target a single machine so that I can execute them against multiple machines in parallel or import them into System Frontier. :cool:

    Avatar
    reddurex
    Member
    #388045

    Re: Get PC name from Dell Service Tag

    noxigen;272967 wrote:
    Out of habit. I usually create scripts that target a single machine so that I can execute them against multiple machines in parallel or import them into System Frontier. :cool:

    You could still make this dynamic in that way. :smile:

    Code:
    On Error Resume Next

    ‘ Input File Example:
    ‘ 127.0.0.1
    ‘ 127.0.0.1, UserName, Password’

    Dim fileStream, fileSystemObj
    Const ForReading = 1
    Dim strArr

    localUserName = “”
    localPass = “”

    If WScript.Arguments.Length = 0 Then
    Call GetInfo(“127.0.0.1”, localUserName, localPass, False)
    Else
    filePath = WScript.Arguments(0)
    Set fileSystemObj = CreateObject(“Scripting.FileSystemObject”)
    If fileSystemObj.FileExists(filePath) Then
    Set fileStream = fileSystemObj.OpenTextFile(filePath, ForReading, 0)
    Do Until fileStream.AtEndOfStream
    strLn = fileStream.ReadLine()
    If Trim(strLn) “” Then
    arg1 = “”
    arg2 = “”
    strArr = Split(strLn, “,”)
    If UBound(strArr) = 2 Then
    arg1 = Trim(strArr(1))
    arg2 = Trim(strArr(2))
    End If
    Call GetInfo(Trim(strArr(0)), user, pass, True)
    End If
    Loop
    Else
    MsgBox “File does not exist: ” & filePath, 48, “Error”
    End If
    End If

    Sub GetInfo(strComputer, userName, pass, abortOption)
    Set SWBemlocator = CreateObject(“WbemScripting.SWbemLocator”)
    Set objWMIService = SWBemlocator.ConnectServer(strComputer,”rootCIMV2″,userName,pass)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_BIOS”,,48)

    If Err.Number = 0 And IsObject(colItems) Then
    Style = 64
    If abortOption Then Style = 67
    For Each objItem in colItems
    Result = MsgBox(“Computer: ” & strComputer & vbNewLine & _
    “Manufacturer: ” & objItem.Manufacturer & vbNewLine & _
    “SerialNumber: ” & objItem.SerialNumber, Style, “WMI Results”)
    If abortOption And Result = 7 Then WScript.Quit(0)
    Next
    Else
    MsgBox “(” & strComputer & “) – ” & _
    Err.Description, 48, “WMI Error”
    End If
    End Sub

    You can specify a file that contains a list of computer names and optional username and password delimited by a “,” (comma). So for instance the file may look like this:

    Code:
    127.0.0.1
    127.0.0.1, UserName, Password

    Where the username and password are optional for each line. Otherwise just invoking the script without any arguments assumes “127.0.0.1”.

    Note: You could edit the script to output all of the information at the end once all queries are completed, or add a messagebox that has 2 buttons, and check for whether the user wants to continue checking the next one, otherwise exit the script.

    edit: I edited the script with the most up to date version I have right now.

    VBscript isn’t really my thing, I know VB.net and C#, but I mainly deal with C/C++.

    Cheers,
    Ace

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.