Generate computer names in MDT 2012/2013 based on prefix and a sequence number

Here is a stored procedure you can use to generate computer names in MDT 2012/2013, with or without ConfigMgr 2012.

Download the sample files

The stored procedure assumes that you have installed the MDT 2012/2013 database, and works like this: If they computer name 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 computer name based on the prefix and the next sequence number. The configuration is done in three simple steps:

  1. Setting up the MDT database
  2. Add the Stored Procedure and a Table to keep track of the sequence numbers
  3. Configure the Deployment Share rules (CustomSettings.ini)

Step 1- Setting up the MDT Database

In this example I have a deployment server named MDT01, a deployment share named MDT Production, and I have installed SQL Server 2012 SP1 Express (named pipes enabled). I have also created a Logs$ share to which MDT connects and establishes a trusted connection. To drive my deployments I use an account named VIAMONSTRAMDT_BA (domain user account).

  1. On MDT01, using Deployment Workbench, expand the MDT Production deployment share, expand Advanced Configuration, right-click Database, and select New Database.
  2. In the New DB Wizard, on the SQL Server Details page, enter the following settings and click Next:
    1. SQL Server Name: MDT01
    2. Instance: SQLEXPRESS
    3. Port:
    4. Network Library: Named Pipes
  3. On the Database page, select Create a new database; in the Database field, type MDT and click Next.
  4. On the SQL Share page, in the SQL Share field, type Logs$ and click Next. Click Next again and then click Finish.
  5. On MDT01, start SQL Server Management Studio.
  6. In the Connect to Server dialog box, in the Server name list, select MDT01\SQLEXPRESS and click Connect.
  7. In the Object Explorer pane, expand the Security node, right-click Logins, and select New Login.
  8. On the Login – New page, in the Login name field, type VIAMONSTRAMDT_BA. Then in the left pane, select User Mapping. Select the MDT database, and assign the following roles:
    1. db_datareader
    2. db_datawriter
    3. public (default)
  9. Click OK, and close SQL Server Management Studio.

Step 2 – Add and configure a Stored Procedure and Table

  1. Download the sample files.
  2. On MDT01, using SQL Server Management Studio, open the InsertComputerNames.sql script and execute it by pressing F5.
  3. In the left pane (Object Explorer), expand Databases, expand MDT, expand Programmability, and expand Stored Procedures.
  4. Right-click the dbo. InsertComputerName stored procedure and select Properties.
  5. In the Stored Procedure Properties – InsertComputerName window, in the left pane, select Permissions. In the right pane, click Search, click Browse, select VIAMONSTRA\MDT_BA, and click OK twice.
  6. In the right pane, select the Execute check box in the Grant column, and click OK.
    Permissions
  7. Using SQL Server Management Studio, open the MachineName.sql script and execute it (press F5).
  8. In the left pane (Object Explorer), in the MDT database, expand Tables.
  9. Right-click the dbo.MachineNameSequence table and select Edit Top 200 Rows.
  10. In the Prefix field, type PC, and in the Sequence field, type 80. Then press Enter to insert the record into the database. The number 80 is your starting point, so the first computer will have the name of 80, the next computer will then have a number of 81, and so forth.

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=YES

[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=InsertComputerName
Parameters=MacAddress

/ Johan

About the author

Johan Arwidmark

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

There is no need to develop a script for that, the latop/desktop detection feature is built-in already. Add the following settings to your CustomSettings.ini in your settings package in SCCM 2012.

[Settings]
Priority=Default, ByLaptopType, ByDesktopType

[Default]

[ByLaptopType]
Subsection=Laptop-%IsLaptop%

[ByDesktopType]
Subsection=Desktop-%IsDesktop%

[Laptop-True]
OSDComputerName=LW#Left("%SerialNumber%",13)#

[Desktop-True]
OSDComputerName=DW#Left("%SerialNumber%",13)#

/ Johan

Ayoo
Ayoo
6 years ago

Hi Johan, Im try to develop a powershell script to generate Hostnames based on a set Prefix for Lw%serialnumber% for laptop and DW%serialnumber% not more that 13 character for sccm 2012.R2. I have attempted the script below but it doesnt work can you help or point out where i have gone wrong $ComputerModel = (Get-WmiObject -Class Win32_ComputerSystem | Select-Object Model).Model$SerialNumber = (Get-WmiObject -Class Win32_BIOS | Select-Object SerialNumber).SerialNumber # Workstationsif (($ComputerModel -match "Precision") -OR ($ComputerModel -match "Optiplex")) { $OSDComputerName = $SerialNumber + "-" + "WS" $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment $TSEnv.Value("OSDComputerName") = "$OSDComputerName"} # Laptopsif ($ComputerModel -match "Latitude") { $OSDComputerName =… Read more »

Montanus
Montanus
7 years ago

I am using MDT 2013, Windows Server 2012, SQL 2012

Admin
Admin
7 years ago

Hi Pål,

The ComputerSettings table is not a table, it's a view 🙂

As for your other question, contact me offline and I can help, you find email info in the About section

/ Johan

Montanus
Montanus
7 years ago

I am using MDT 2013, Windows Server 2012, SQL 2012

Montanus
Montanus
7 years ago

Hi I have set up the database etc as described above. The script works great and the computer name is created right in the database. Everything looks good. I'm a little unsure about a setting in Customsettings.ini, in Csettings. It's Table = ComputerSettings. I can not see the table in the database. I have one called ComputerIdentity. This table has fields like parameter in customsettings ini. So I refer to that table. My unattended installation works fine but is installed with the wrong computer name. It should have been tryggdepc001 but become instead something completely different, Trygde-QFDRTOFG I suspect it… Read more »

Admin
Admin
7 years ago

You can either send the isLaptop/isDesktop value and have the store procedure create a prefix, or use the MDT rules to set a custom property depending on the isLaptop/isDesktop properties, send that custom property to the stored procedure, and use it as prefix.

/ Johan

Notaes
Notaes
7 years ago

Hi Johan

Just finished getting this setup at our site. I am also wanting to add an additional prefix based on desktop or laptop. Could you give me an idea of which additional parameters would be required in the store procedure? Unfortunately my SQL skills are limited.

Thanks

Chris

Notaes
Notaes
7 years ago

Hi Johan

Just finished getting this setup at our site. I am also wanting to add an additional prefix based on desktop or laptop. Could you give me an idea of which additional parameters would be required in the store procedure? Unfortunately my SQL skills are limited.

Thanks

Chris

Admin
Admin
7 years ago

You can extend the store procedure to accept additional parameters.

/ Johan

tes-com
tes-com
7 years ago

Re: Generate computer names in MDT 2012/2013 based on prefix and a sequence number

Hello This Works Great. But now i have LAptops and Desktops So i want to use two Prefixes Like LT- and DT-

How is this posable ?

Admin
Admin
7 years ago

Hey Davidt, for troubleshooting, run the stored procedure manually on the server (In SQL Server Management Studio).

Did you grant the needed execute permissions on the stored procedure for the account you are using?

/ Johan

davidt
davidt
7 years ago

Hi Johan, I followed your guide, and customized it for my naming scheme. It works perfectly on MDT2012/SQL2012, which I tried to replicate on a totally new server running MDT2013/SQL2012, copying the customized scripts over. The computer will find it's name if it already exists, but won't auto-generate a new entry. Any ideas? ============================================USE [MDT2013]GO/****** Object: StoredProcedure [dbo].[InsertComputerName] Script Date: 2/25/2014 11:02:24 AM ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO ALTER PROCEDURE [dbo].[InsertComputerName]@SerialNumber CHAR(17),@Model VARCHAR(50) AS DECLARE @Cnt INT, @Prefix VARCHAR(50), @Sequence INT, @NewName VARCHAR(50) SET NOCOUNT ON /* See if there is an existing record for this machine */ SELECT @Cnt=COUNT(*)… Read more »

tes-com
tes-com
7 years ago

Hello This Works Great. But now i have LAptops and Desktops So i want to use two Prefixes Like LT- and DT-

How is this posable ?

Admin
Admin
7 years ago

Should not take that long, most likely is a database connection issue. Check the ZTIGather.log to see the communication between the client and the database. Also check this post for troubleshooting tips: xtremeconsulting.com/blog/troubleshooting-database-issues-with-mdt-2010

/ Johan

evald@elhoej.com
7 years ago

No, just used an different Prefix and sequence number
have tried PC and 80 as mentioned in step 10, no improvement.

the database is on a seperate server running windows server 2012 r2 and sql Server 2012, named pipes enabled.
i connected and created the database from the MDT console without any problems.

when I pxe boot a client it takes about 5 minutes to process the CSettings and Identify Rules.
Can this be optimized or is this root cause of my problem ?

deployment share has been updated.

Admin
Admin
7 years ago

Nope, but you probably forgot to type in "PC" in step 10. 🙂

/ Johan

evald@elhoej.com
7 years ago

Tried the setup mentioned but the generated name is not with prefix and secuence number.
Is there some additional setup with is not mentioned?

ogeccut
ogeccut
7 years ago

Thank you. I had a client requesting this few years ago. Had to convince them to use serial number as part of the name 🙂


>