The company uses the Microsoft MDT to deploy the system, and the default MDT automatically generates a random name every time the system is deployed, because the company is a domain environment and has a set of asset management system record serial number, computer name, model, asset number and asset owner information, each time manually to query very inconvenient, Think of a way to automatically recognize a computer name by script
The general idea is as follows
Periodically generate CSV files from the asset system's SQL database and save them in the MDT path
Read the CSV file through VBS and query the serial number of the deployed machine via WMI
Using VBS to compare to the native serial number, query the CSV library, return the corresponding computer name and assign a value
With the idea, we start to implement.
When the MDT system uses the Deploywiz_computername.vbs file to process the computer name, make the following changes to the file
Z:\Tools-Scripts\assets.csv is the path to the CSV file, and Z: The network for the MDT server-side directory hangs on the drive letter.
Option Explicit
Dim Serialnum,os_pc_name,objwmiservice,colitems,objitem
Dim FSO, Radfile, MyFile, SearchString, Mypos,tempdata,fileobj ', username, SearchChar
Os_pc_name= ""
Set objWMIService = GetObject ("winmgmts://./root/cimv2")
Set colitems = objWMIService.ExecQuery ("SELECT * from Win32_BIOS", 48)
For each objitem in colitems
Serialnum = Objitem.serialnumber
Next
Set fso = CreateObject ("Scripting.FileSystemObject")
If (FSO. FileExists ("Z:\Tools-Scripts\assets.csv")) Then
Radfile= "Z:\Tools-Scripts\assets.csv"
End If
If (FSO. FileExists ("Z:\mdt\Tools-Scripts\assets.csv")) Then
Radfile= "Z:\mdt\Tools-Scripts\assets.csv"
End If
' Set myfile= FSO. OpenTextFile (Radfile, 1, TRUE)
If (FSO. FileExists (radfile)) Then
Set fileobj = fso. GetFile (Radfile)
Set myfile= fileobj. OpenAsTextStream (1,-2)
Do While Myfile.atendofline <> True
Searchstring=myfile.readline
MyPos = Instr (searchstring, Serialnum)
If MyPos > 0 Then
Tempdata=split (SearchString, ",")
Os_pc_name=trim (tempdata (0))
Oenvironment.item ("osdcomputername") = Os_pc_name ' added to set ComputerName *******************
End If
Loop
Myfile.close
End If
This article from "Laughing Proud of the Wind" blog, declined reprint!
MDT automatically gets and generates computer names