MDT automatically gets and generates computer names

Source: Internet
Author: User

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

    1. Periodically generate CSV files from the asset system's SQL database and save them in the MDT path

    2. Read the CSV file through VBS and query the serial number of the deployed machine via WMI

    3. 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


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


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



End If

This article from "Laughing Proud of the Wind" blog, declined reprint!

MDT automatically gets and generates computer names

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.