Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

VBS: a script to retrieve the wmi infos from computer : Manufacturer & Model

Publié le par damcuvelier

 

 

This script is in vbs and if you run it into under cmd you will just have to copy/past info to use it.

I am going to write an add-on to automatic model detection, with this script in beggining:

 

On Error Resume Next

Dim oWMIService, cObj, oObj, ObjFile
Dim PathListModeleFile, line, here
Dim listmodel,listManufacturer
Dim RefDriverPackage

here=left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1)

CheckModelComputer()


'This fonction give Manufacturer & Model of a computer by WMI QUERY
sub CheckModelComputer()
Set ObjFile = CreateObject("Scripting.FileSystemObject")
Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set cObj= oWMIService.ExecQuery ("select * from Win32_ComputerSystem")
For Each oObj In cObj
    wscript.echo "Manufacturer = " & chr(34) & oObj.Manufacturer & chr(34)
    wscript.echo "Model = " & chr(34) & oObj.Model & chr(34)
Next

End sub

 

Now we want to update an ini file for sccm automatic driver deploiement.

Use this:

 

'//
'// Usage: Create a list of pc models
'// Name: model.vbs
'// command: cscript model.vbs "modelvariablename"
'//
'// Damien Cuvelier
'//

On Error Resume Next

Dim oWMIService, cObj, oObj, ObjFile
Dim PathListModeleFile, line, here
Dim fso,f1,modelname
Dim listmodel,listManufacturer
Dim RefDriverPackage
Const ForReading = 1, ForWriting = 2, ForAppending = 8
here=left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1)
PathListModeleFile = here &"\ListModelesDrivers.ini"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.OpenTextFile(PathListModeleFile, ForAppending,true)


'Retrieve command line arguments:
Dim oArgs
Set oArgs=WScript.Arguments
modelname = oArgs(0)

 

CheckModelComputer()

'This fonction give Manufacturer & Model of a computer by WMI QUERY
sub CheckModelComputer()
Set ObjFile = CreateObject("Scripting.FileSystemObject")
Set oWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set cObj= oWMIService.ExecQuery ("select * from Win32_ComputerSystem")
For Each oObj In cObj
    f1.WriteLine( oObj.Manufacturer & ";" & oObj.Model & ";" & modelname )
Next
End sub

 

 

Run this script on all the computer you want and it will create a file named

ListModelesDrivers.ini on the same folder (if it does not exist) and append into this file the reference of the computer.

The nomenclature is manufacturer;model;argument

where argument is the argument you give in running the script in cdm like this:

cscript model.vbs “argument”

 

it is used by the script follow for sccm variable, that you assign to the drivers package to insall computer drivers:

'//
'// Usage: Create a list of pc models
'// Name: model.vbs
'// command: cscript modele.vbs (by sccm in a package in Task Sequence)
'// Damien Cuvelier
'//

On Error Resume Next
Dim oWMIService, cObj, oObj, ObjFile
Dim PathListModeleFile, line, gethomepath
Dim listmodel,listManufacturer,sModel,sManufacturer
Dim RefDriverPackage

Set ObjFile = CreateObject("Scripting.FileSystemObject")
gethomepath=left(WScript.ScriptFullName,len(WScript.ScriptFullName)-len(WScript.ScriptName)-1)
Set oOsdV4 = CreateObject("Microsoft.SMS.TSEnvironment")
CheckModelComputer()
oOsdV4("RefDriverPackage") = RefDriverPackage

 


'Cette fonction vérifie que le matériel est compatible avec la liste associé à ce média de déploiement
sub CheckModelComputer()
    PathListModeleFile = gethomepath &"\ListModelesDrivers.ini"
    'Recherche modele et constructeur
    Set oWMIService = GetObject("winmgmts:"  & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
    Set cObj= oWMIService.ExecQuery ("select * from Win32_ComputerSystem")
    For Each oObj In cObj
    sManufacturer = oObj.Manufacturer
    sModel = oObj.Model
    msgbox sManufacturer
    msgbox sModel
                WScript.StdOut.WriteLine "Your Model:"&chr(34)&sModel&chr(34)&" is unknow, please contact your support"
        If ObjFile.FileExists(PathListModeleFile) = True Then
        'Chargement de la liste des modeles
        RefDriverPackage = ""
            For Each Line In Split(ObjFile.OpenTextFile(PathListModeleFile,1).ReadAll(),vbCrLf)
            listmodel = split(Line,":")(1)
            listManufacturer = split(line,":")(0)
            Next
                If instr(lcase(sManufacturer),lcase(listManufacturer)) > 0 _
                And instr(lcase(smodel),lcase(listmodel)) > 0 Then
                RefDriverPackage = split(line,":")(2)
                Else
                WScript.StdOut.WriteLine "Your Model:"&chr(34)&sModel&chr(34)&" is unknow, please contact your support"
                Msgbox "Your Model:"&chr(34)&sModel&chr(34)&" is unknow, please contact your support"
                End If
        End If
    Next
End sub

 

 

when you have update your file ListModelesDrivers.ini update it into the package of modele.vbs.

 

your model reference is up to date

now you have to create the driver package for your new computer and add the variable define for this computer in condition of running the package in sccm

 

enjoy (5min)

Commenter cet article

Y
Are your facing issue during Upgraded Yahoo mail 2018, 2019, 7 to 11, 11.5, login, password etc. call Yahoo Help Number Australia +61-028091-6999<br /> Get more information visit here: http://yahoo.contactsupportnumberaustralia.com.au/
Répondre
X
Xero Online Australia Support Number +61-028091-6999,we fix all Xero Issue like Xero Accounting Software, Payroll, Invoice, vat, Cloud etc<br /> Get more information visit here: http://xero.contactsupportnumberaustralia.com.au/
Répondre
T
Need any Help or Support for Telstra Mail like login, password etc then just call BigPond Technical Support Contact Number Australia +61-028091-6999<br /> Get More Information visit here: http://bigpondaccount.contactsupportnumberaustralia.com.au/
Répondre
Q
Dial QuickBooks Online Contact Support Australia Number +61-028091-6999. We Fix Intuit QuickBooks Issues Bookkeeping, Payroll, Invoice, Enterprise, Vat, Bank error, Reconciliation etc<br /> <br /> Get More Information visit here http://quickbooks.contactsupportnumberaustralia.com.au/
Répondre
Y
Yahoo Mail Customer Support Australia +61-028091-6999 Help Number for Fix All Yahoo issues like Yahoo Sign in, Password, Login, Sent, Received mail, 11.5,7, 11 etc<br /> Get More Information visit http://yahoo.contactsupportnumberaustralia.com.au/
Répondre