Wednesday, March 18, 2009

Serial Number Retriever

Yet another serial number generator. Ported from a vbscript found online.
Just feed a machine name to the script to get an output with a serial number into a csv file.
You can also feed a file with all computer names on separate lines. If executed with no options, the current computer info is returned.
If there is no input, the local machine will be used.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=SerialNumber.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs
    Just feed a machine name to the script to get an output with a serial number into a csv file.
    You can also feed a file with all computer names on separate lines. If executed with no options, the current computer info is returned.
    If there is no input, the local machine will be used.
    
    Alex Belenkiy
    09/24/08
 
 
#ce
#include <array.au3>
#include <file.au3>
 
dim $strComputer, $ComputersArray
 
$OutputFile = FileOpen("ServiceTag " & @MON & "-" & @MDAY & "-" & @YEAR & ".csv", 10)
FileWriteLine($OutputFile, "Machine Name, Manufacturer, Model Number, Serial Number, Part Number, SMBIOSAssetTag, OtherIdentifyingInfo")
If $CmdLine[0] = 0 Then 
    $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & @ComputerName & "\root\cimv2")
    $colSMBIOS = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")    
    For $objSMBIOS in $colSMBIOS
        FileWriteLine($OutputFile, @ComputerName & "," & $objSMBIOS.Manufacturer & "," & $objSMBIOS.Model & "," & $objSMBIOS.SerialNumber & "," & $objSMBIOS.PartNumber & $objSMBIOS.SMBIOSAssetTag & $objSMBIOS.OtherIdentifyingInfo)
    Next
Else
    if not FileExists($CmdLine[1]) Then
        $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $CmdLine[1] & "\root\cimv2")
        if not @error Then
            $colSMBIOS = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")    
            For $objSMBIOS in $colSMBIOS
                FileWriteLine($OutputFile, $CmdLine[1] & "," & $objSMBIOS.Manufacturer & "," & $objSMBIOS.Model & "," & $objSMBIOS.SerialNumber & "," & $objSMBIOS.PartNumber & $objSMBIOS.SMBIOSAssetTag & $objSMBIOS.OtherIdentifyingInfo)
            Next
        EndIf
    Else
        _FileReadToArray($CmdLine[1],$ComputersArray)
        For $a = 1 to $ComputersArray[0]
            $objWMIService = ObjGet("winmgmts:" & "{impersonationLevel=impersonate}!\\" & $ComputersArray[$a] & "\root\cimv2")
            if not @error Then
                $colSMBIOS = $objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")    
                For $objSMBIOS in $colSMBIOS
                    FileWriteLine($OutputFile, $ComputersArray[$a] & "," & $objSMBIOS.Manufacturer & "," & $objSMBIOS.Model & "," & $objSMBIOS.SerialNumber & "," & $objSMBIOS.PartNumber & $objSMBIOS.SMBIOSAssetTag & $objSMBIOS.OtherIdentifyingInfo)
                Next
            EndIf
        Next
    EndIf
EndIf
    
        
FileClose($OutputFile)

No comments: