Generate Computernames in MDT 2010 based on prefix and a sequencenumber

This procedure works like this: If they computername is in the database already (known), it will assign that name to the PC. If the computer is not in the database (unknown), it will generate a computername based on the prefix and the next sequencenumber.

Note: This post is for MDT 2010, for MDT 2012 or later versions, use this guide and sample code: Generate computer names in MDT 2012/2013 based on prefix and a sequence number. (the database tables have changed between MDT 2010 and future versions)

Step 1- Setting up the Database

Below you find a detailed step-by-step guide, and there also a video tutorial available on our YouTube channel: Part 18 of the MDT 2010 Lite Touch – Unleashed series.

  1. On the MDT Server (MDT01 in my example), install SQL Server 2008 Express SP1. After installation, enable Named Pipes and restart the service  
  2. Using the Deployment Workbench, in the advanced node, create a new Database (named MDT in my example)  
  3. Using SQL Management Studio (Server name is MDT01\SQLEXPRESS), create a Security Login for the domain user account that you use for your Lite Touch installations  
  4. For the previously created Security Login, add the following permissions to the MDT Database.
    1. db_datareader
    2. db_datawriter

Step 2 – Add needed Stored Procedure and Tables

Below you find a detailed step-by-step guide, and there also a video tutorial available on our YouTube channel: Part 19 of the MDT 2010 Lite Touch – Unleashed series.

  1. Download the files from here… 
    Generate Computer Names using the MDT Database  
  2. Using SQL Management Studio, open the InsertComputerNames.sql script and execute it (F5)  
  3. For the Security Login created in Step 1, grant execute permissions to the IdentifyComputer Stored Procedure (found under Programmability / Stored Procedures)  
  4. Open the MachineName.sql script and execute it (F5)  
  5. Edit the MachineNameSequence table, in the prefix field, type in PC, in the sequence field type in 0 (Zero)

Step 3 – Configure the Deployment Share rules

  1. Use the info in the sample customsettings.ini file to configure the rules on your deployment share to use the stored procedure.
[Settings]
Priority=IdentifyComputer, CSettings, Default

[Default]
OSInstall=Y

[CSettings]
SQLServer=MDT01
Instance=SQLEXPRESS
Database=MDT
Netlib=DBNMPNTW
SQLShare=Logs$
Table=ComputerSettings
Parameters=UUID, AssetTag, SerialNumber, MacAddress
ParameterCondition=OR

[IdentifyComputer]
SQLServer=MDT01
Instance=SQLEXPRESS
Database=MDT
Netlib=DBNMPNTW
SQLShare=Logs$
StoredProcedure=IdentifyComputer
Parameters=MacAddress

/ Johan

About the author

Johan Arwidmark

0 0 votes
Article Rating
Subscribe
Notify of
guest
36 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Admin
Admin
7 years ago

This post is for MDT 2010, in MDT 2012 Update 1 and MDT 2013 the database was updated. For MDT 2012/2013 use this example instead:

Generate computer names in MDT 2012/2013 based on prefix and a sequence number
https://deploymentresearch.com/Research/tabid/62/EntryId/103/Generate-computer-names-in-MDT-2012-2013-based-on-prefix-and-a-sequence-number.aspx

/ Johan

frankie_wu
frankie_wu
7 years ago

Hi Johan:
I had create a database by the Deployment Workbench,when i execute the InsertComputerNames.sql script ,a error "column name "OSDInstallSilent' is invalid". i use sql server 2012 , what wrong?
Thanks !

Admin
Admin
7 years ago

Hi Frankie,

This example works on SCCM 2012 R2 as well. If you want a step-by-step guide for implementing this on SCCM 2012 R2, buy this book 🙂

stealingwithpride.com/

/ Johan

frankie_wu
frankie_wu
7 years ago

Hi John:
I have a SCCM 2012 R2 environment, I need deploy some computers with Win7 Ent OS,I have a target ,the computer name is based on prefix and a sequencenumber,example PC01,PC02,PC03….,i don't know how to achieve the target after i have some failures, i hope i can get help from you !
Thanks a lot
Fankie

Admin
Admin
7 years ago

I don't have a ready-made sample for that, but you would have to send the additional parameters to the stored procedure, or take action on the result given by the stored procedure.

/ Johan

anilkoyya
anilkoyya
7 years ago

Hi Johan,

This really works great. Thanks for sharing with us. However there is a requirement from my customer regarding the Computer naming convention.
How do we modify this script to query default gateway, based on default gateway assign a prefix followed by Laptop or desktop.

Thanks in Advance

Cheers
Anil

Admin
Admin
9 years ago

The OSDComputerName is stored in a different table, you should the value when querying the computersettings view (which joins the two tables).

As far as description goes, you need to modify the stored procedure to set the description as well.

/ Johan

Admin
Admin
9 years ago

Yes, send me an email to get the updated stored procedure. My alias is my lastname and I'm using gmail.

/ Johan

marshal.anson
marshal.anson
9 years ago

I installed SQL 2012 with MDT 2012 Update 1. This no longer works. It will pull the computer name if it already exists, but it won't write to the computer name. It will create an entry in the DB with the MAC, ID, Type, and OSInstall columns, but not OSDComputerName or Description.

Any ideas?

discontinuity
discontinuity
10 years ago

I don't know what to say… You can't imagine how much you helped someone you don't know. Thank you very very much Johan, it worked. I've been trying to solve this for weeks. Couldn't find any answer anywhere but this site. And it seems to be working now. You rock! 😉 Thank you again and again…

Admin
Admin
10 years ago

No need to inject additional fields

In the customsettings.ini calling your stored procedure, update the [Settings] section to the following:

[Settings]
Priority=IdentifyComputer, Default
Properties=CustomOSDComputername

Update the IdentifyComputer Stored Procedure with the following:
/* Return the record as the result set */

SELECT OSDComputerName AS CustomOSDComputerName FROM ComputerSettings
WHERE MacAddress = @MacAddress

Then add a "Set Task Sequence Variable" action that sets OSDComputerName = %CustomOSDComputerName%. Add this action after the Gather that calls the stored procedure.

/ Johan

discontinuity
discontinuity
10 years ago

Update: I tried the above method (also created a TS variable like you suggested) but the OSDComputerName variable didn't get its new name from sql. But Sql generates the new name and inputs it in CustomOSDComputerName column. How can we make sql to return this value to the client? Should we alter the last 2 lines in sql stored procedure?
/* Return the record as the result set */

SELECT * FROM ComputerIdentity
WHERE MacAddress = @MacAddress

And how? I'm very sorry for bothering you and sending all these countless posts here 🙁

discontinuity
discontinuity
10 years ago

I altered the stored procedure so that it inputs the new name to a new column in "settings" table in MDT database. When executed it worked. But I don't know if sql returns that new column's value to the client? Do all the columns' values in "settings" table returned to the client when queried? If so I'm close to the end. Here are the last few line from my stored procedure if it helps. /* Insert the new record */ INSERT INTO ComputerIdentity (MacAddress) VALUES (@MacAddress) INSERT INTO Settings (Type, ID, CustomOSDComputerName, OSDInstallSilent, OSInstall) VALUES ('C',@@IDENTITY, @NewName, '1', 'Y') COMMIT… Read more »

discontinuity
discontinuity
10 years ago

Thank you very much for the reply. Yes computer has its name assigned (either it's an old computer or a new computer added via computer association in SCCM) before the sql query but I still don't get why it doesn't get overwritten with the new name from sql. Your suggestion is smart, but I don't know how to implement it. If I create a new column in Settings table in MDT database, will that new column's variable be assigned if I create a new TS variable? In that case I should edit the Stored Procedure to update the new column… Read more »

Admin
Admin
10 years ago

Well, the computername is already set when the second cs.ini is run, therefor it will not be reset. A workaround is to have the database return another property, say CustomOSDComputerName. Then you can add a "Set Task Sequence Variable" action where you set OSDCOmputerName=%CustomOSDComputerName% which will overwrite whatever that is set.

/ Johan

discontinuity
discontinuity
10 years ago

Hmm, doing a refresh to see if a new reply has been sent after posting, my browser reposts again!! I'm sorry for the double posts 🙁

Have you been able to check the logs? I'm still clueless what's going on? If I can't resolve this issue I'll have to find another job 🙂

discontinuity
discontinuity
10 years ago

http://skydrive.live.com/#cid=D418489FED312C0C&id=D418489FED312C0C%212137 The first gather step in TS is used to get MAC address and IP address of the machine and to display it in my custom hta where end user selects the appropriate department.The second gather step is used to get the new computer name. After that another hta displays the new assigned computer name for 10 seconds and the TS continues. But the old name is always assigned though the computer's mac is not in the mdt database. (but the computer that is being installed has computer account in AD and SCCM database. The computer is in the OSD… Read more »

discontinuity
discontinuity
10 years ago

http://skydrive.live.com/#cid=D418489FED312C0C&id=D418489FED312C0C%212137 The first gather step in TS is used to get MAC address and IP address of the machine and to display it in my custom hta where end user selects the appropriate department.The second gather step is used to get the new computer name. After that another hta displays the new assigned computer name for 10 seconds and the TS continues. But the old name is always assigned though the computer's mac is not in the mdt database. (but the computer that is being installed has computer account in AD and SCCM database. The computer is in the OSD… Read more »

discontinuity
discontinuity
10 years ago

http://skydrive.live.com/#cid=D418489FED312C0C&id=D418489FED312C0C%212137 The first gather step in TS is used to get MAC address and IP address of the machine and to display it in my custom hta where end user selects the appropriate department.The second gather step is used to get the new computer name. After that another hta displays the new assigned computer name for 10 seconds and the TS continues. But the old name is always assigned though the computer's mac is not in the mdt database. (but the computer that is being installed has computer account in AD and SCCM database. The computer is in the OSD… Read more »

Admin
Admin
10 years ago

It means you have a previous rule thats sets the computername. Please upload your cs.ini and ztigather.log, and post the link.

/ Johan

discontinuity
discontinuity
10 years ago

Hi Johan, I've been onto this subject for a few weeks and I managed to run the stored procedure successfully. It generates the computer names in the database but the new computer name does not return to the machine being installed. In smstslog it says:
"Successfully queried the database.
Records returned from SQL=1
Value for OSDCOMPUTERNAME is already set to GGN0004 so database value of GGN0016 will be ignored."
What could be wrong here? MDT database didn't have any record about this machine before.

discontinuity
discontinuity
10 years ago

Hi Johan, I've been onto this subject for a few weeks and I managed to run the stored procedure successfully. It generates the computer names in the database but the new computer name does not return to the machine being installed. In smstslog it says:
"Successfully queried the database.
Records returned from SQL=1
Value for OSDCOMPUTERNAME is already set to GGN0004 so database value of GGN0016 will be ignored."
What could be wrong here? MDT database didn't have any record about this machine before.

discontinuity
discontinuity
10 years ago

Hi Johan, I've been onto this subject for a few weeks and I managed to run the stored procedure successfully. It generates the computer names in the database but the new computer name does not return to the machine being installed. In smstslog it says:
"Successfully queried the database.
Records returned from SQL=1
Value for OSDCOMPUTERNAME is already set to GGN0004 so database value of GGN0016 will be ignored."
What could be wrong here? MDT database didn't have any record about this machine before.

Admin
Admin
10 years ago

The stored procedure is called by the IdentifyComputer section in the customsettings.ini file and the computername is retreived by the CSettings section. The C The ZTIGather.log will show you what settings that where.

/ Johan

marcomontesanto
marcomontesanto
10 years ago

I fix a problem with the stored procedure and now it completes without errors as well as the whole deployment process.
Unfortunately the PC name won't be assigned as I expect and it remains in the format MININT-XXXXX.

When will the stored procedure be invoked ? Should I add a custom task in TS to make it work ?

marcomontesanto
marcomontesanto
10 years ago

I fix a problem with the stored procedure and now it completes without errors as well as the whole deployment process.
Unfortunately the PC name won't be assigned as I expect and it remains in the format MININT-XXXXX.

When will the stored procedure be invoked ? Should I add a custom task in TS to make it work ?

Admin
Admin
10 years ago

There is no need to pass it via bootstrap.ini, and the gather action is excuted in the very beginning.

Try run the stored procedure manually in SQL Management Studio, because that fails, the error is SQL related, and not MDT related.

/ Johan

marcomontesanto
marcomontesanto
10 years ago

I'm using an administrative account who have "EXECUTE" permission over stored procedure. However I do not pass it using "bootstrap.ini", could be that the account is used only for join to domain (creating MINIT-XXXXXX) and then lost during the next phases ?

marcomontesanto
marcomontesanto
10 years ago

This is the bootstrap.ini I use; I do not have buildaccount as I've preferred to insert credentials without storing the password in "clear"; could it be the problem ?
________________________________
[Settings]
Priority=Default

[Default]
DeployRoot=SERVERNAMEDeploymentShare$

SkipBDDWelcome=YES

UserDomain=MYDOMAIN
UserID=
UserPassword=
______________________________________

Admin
Admin
10 years ago

Whatever account you log on with will be used, and that account needs to have execute permissions on the stored procedure itself.

/ Johan

marcomontesanto
marcomontesanto
10 years ago

This is the bootstrap.ini I use; I do not have buildaccount as I've preferred to insert credentials without storing the password in "clear"; could it be the problem ?
________________________________
[Settings]
Priority=Default

[Default]
DeployRoot=SERVERNAMEDeploymentShare$

SkipBDDWelcome=YES

UserDomain=MYDOMAIN
UserID=
UserPassword=
______________________________________

marcomontesanto
marcomontesanto
10 years ago

This is the bootstrap.ini I use; I do not have buildaccount as I've preferred to insert credentials without storing the password in "clear"; could it be the problem ?
________________________________
[Settings]
Priority=Default

[Default]
DeployRoot=SERVERNAMEDeploymentShare$

SkipBDDWelcome=YES

UserDomain=MYDOMAIN
UserID=
UserPassword=
______________________________________

Admin
Admin
10 years ago

Make sure you have granted the buildaccount execute permissions on the stored procedure itself. read/write to the database is not enough to execute the stored procedure. Also verify that you did add the prefix and a starting sequence number to the machinenamesequence table.

/ Johan

marcomontesanto
marcomontesanto
10 years ago

I've setup a full deployment environment following the book guidelines "Deployment Fundamentals – Volume 1" (Arwidmark-Nystrom). I made only the following change: the bootstrap.ini include only domain name (so username and password are needed to continue). I was able to deploy without problems the images to our test PC. We would like to start the deploy in production environment but I need to generate automaticallyu the name of each PC. For this reason I setup the stored procedure found here but as far as now I was unable to make it work and I even found the reason ! But… Read more »

Admin
Admin
11 years ago

Yes, you can

/ Johan

mdiawara
mdiawara
11 years ago

Hi Johan,

Thank you for this one.
Can i use this same procedure for both ZTI & LTI?

Cheers


>