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.
- On the MDT Server (MDT01 in my example), install SQL Server 2008 Express SP1. After installation, enable Named Pipes and restart the service
- Using the Deployment Workbench, in the advanced node, create a new Database (named MDT in my example)
- 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
- For the previously created Security Login, add the following permissions to the MDT Database.
- db_datareader
- 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.
- Download the files from here…
Generate Computer Names using the MDT Database - Using SQL Management Studio, open the InsertComputerNames.sql script and execute it (F5)
- For the Security Login created in Step 1, grant execute permissions to the IdentifyComputer Stored Procedure (found under Programmability / Stored Procedures)
- Open the MachineName.sql script and execute it (F5)
- 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
- 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
Hi this was very usefull for me. my mdt is running smoothly and the autonaming is going good as well but i have a challenge. in the company we use 3 types of computernames. so, what i did was create 3 storedprocedures, insertcomputername, insertcomputername1 and insertcomputername2 and also 3 tables : MachinenameSequence, MachinenameSequence1 and MachinenameSequence2 when running the procedure in the sql itself, it updates the correct table and stores the data in the table ComputerIdentity now, i want to go a step further. I want to do the following. When deploying a new computer, i need to have the… Read more »
You can customize the MDT deployment wizard to prompt for that. Either by adding a custom wizard pane, or modifying an existing one. Another option is to have a userexit script, or the TS itself prompt for a selection of a naming template.
Thanxs for the reply.I will try to get this done, but i am not that good of a wiz in this, since it is my first time setting up a MDT.
i have already found some things on the net about this now, but it does not seem to be an easy thing to do. will keep you posted if i can get this done
Well, through our company Mirolus and the ViaMonstra Online Academy we do offer consulting services if your company should need assistance with this. Won't take more than a few hours to configure. Here is a link: https://academy.viamonstra.com/courses/one-on-one-consulting-single-session
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
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 !
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
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
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
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
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
Yes, send me an email to get the updated stored procedure. My alias is my lastname and I'm using gmail.
/ Johan
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?
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…
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
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 🙁
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 »
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 »
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
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 🙂
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 »
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 »
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 »
It means you have a previous rule thats sets the computername. Please upload your cs.ini and ztigather.log, and post the link.
/ Johan
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.
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.
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.
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
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 ?
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 ?
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
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 ?
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=
______________________________________
Whatever account you log on with will be used, and that account needs to have execute permissions on the stored procedure itself.
/ Johan
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=
______________________________________
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=
______________________________________
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
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 »
Yes, you can
/ Johan
Hi Johan,
Thank you for this one.
Can i use this same procedure for both ZTI & LTI?
Cheers