Wednesday, September 10, 2014

How to check the model for a list of Dell PC with service tag

I have a need to check the model of list of PC. The only information I have is their service tag.

It may take desktop engineers a long time to check one by one if they do not have this record correctly.

I have written an auto-it script which basically do the following.

1. Load the list of the service tag from "c:\temp\tag.lst" into an array

2. For each service tag, do the following

a. Open up the Dell Service tag website (<your service tag>/diagnose?s=BSD) 

b. Download the file and search for the string "supportproductselected"

c. Extract the string in between "supportproductselect" and "/>"

3. Export the results into c:\temp\tagresult.txt

You need to install Auto-it before you can run this script and you need to put all your service tag into a text file "tag.lst" which has one service tag per line.

Here's the detail script for your reference.


#include <String.au3>
#include <array.au3>
#include <IE.au3>
#include <file.au3>

Local Const $sFilePath = "c:\temp\Tagresult.txt"

    ; Create a temporary file to read data from.
    If Not _FileCreate($sFilePath) Then Return MsgBox($MB_SYSTEMMODAL, "", "An error occurred whilst writing the result file.")

   $fresult = FileOpen($sFilePath, $FO_APPEND)
      If $fresult = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when reading the result file.")
        Return False

$list = FileReadToArray("c:\temp\tag.lst")

 If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "There was an error reading the file. @error: " & @error) ; An error occurred reading the current script file.
        For $i = 0 To UBound($list) - 1 ; Loop through the array.
            FileWriteLine($fresult, $list[$i] & "," & tag($list[$i]))


func tag($word)

   $oIE = Inetget("" & $word & "/diagnose?s=BSD", "c:\temp\tag.txt")

   $f = fileopen("c:\temp\tag.txt",0)

   $con = fileread($f)

$s = stringinstr($con, "supportproductselected")
$t = stringInstr($con, "content=", 0,1, stringinstr($con, "supportproductselected"))

$product = stringmid($con, $t+8, stringinstr($con, "/>", 0,1, $t)-$t-8)

consolewrite (chr(34) & $word & chr(34) & ", " & $product &@CRLF)

   return $product


No comments:

Post a Comment