MDT 2012 PART VIII – Automatically Set computer Name

OSD

Hello World,

Today, again, we will speak a little bit about MDT 2012.  The idea of this post came because of a discussion we had with one of our customers.  This customer was not able to automate the deployment process because by default MDT generates a random computer name.  The customer had first to rename the computer before joining it into the domain makin impossible for him to fully automate the deployment process.

This post will quickly show you can use the CustomSettings.in (or equivalent rules GUI editor) to automatically set a computer name based on your naming convention. You will see that MDT 2012 can be tweaked in order to fit your situation.

Let’s go !

Set computer Name using OSDComputerName variable

Common Scenarios

By default, MDT 2012 allows you to define some rules in order to set the correct computer name during the deployment process.  In order to set computer name during the deployment process, you can use the variable OSDComputername.   In order to define the rule that will be used to set the proper computer name, you have to understand the naming conventions used within your customer organization.  In our situation, a naming convention was available (sweet) and the computer name to be generated would be the combination of a prefix text  and the serial number of the machine.  In other words, the computer naming convention was something like

WS-%SerialNumber%

Based on this naming convention, it’s easy to automate the process with MDT 2012.  Open the Deployment workbench > right-click on your deployment share and select properties.

Click on picture for better resolution

In the properties page, click on the rules tab.   In this tab, add the following line

OSDComputerName=WS-%SerialNumber%

Click on picture for better resolution 

By adding this line, you simply tell MDT to set the computername to the value you’ve just defined.  Where MDT will find the %SerialNumber% value ?  Basically, MDT will run a series of scripts that will be performing wmi queries and store the results into variables.  %SerialNumber% is one of the variable.  MDT has more than 100 pre-defined variables that you can use.  You can see the list of available variables by running the script ZTIGather.wsf and by having a look at the file ZTIGather.xml.  Both files are located under %DriveLetter%\DeploymentShare\Scripts\.  You can use other variable as well such as

  • %Architecture%  (ex: x86 or x64)
  • %Model%  (ex: Vaio xxxx or Inspiron,..)
  • %Make% (Dell,HP,Sony…)
  • %IsLaptop% or %IsDesktop% or %IsServer% or %IsVM% (to detect if the client is a laptop or a desktop or Server or a VM)

Using multiple variables within the Customsettings.ini file (or the rules tab via the GUI), we can accommodate quite some situations. As an example, some organizations in their naming convention might require to make a distinction between desktop and laptop (or even server).  Another common scenario is to make the distinction between virtual machine and physical machines.   If you encounter such situation, you can configure your rules as shown in the following screenshot

Click on picture for better resolution

Another common scenario for naming convention is to use a site code in the computer name.  Depending on your network infrastructure and your MDT setup, you might be able to automatically set the name of the computer. For this one, I have to say that I had to google a little bit in order to find the variable that I could use.  All the posts I’ve found are using the variable %DefaultGateway%

So, if you need to make a distinction between two locations, you could edit your CustomSettings.ini file (see screenshot below) and append this kind of information as long as you are using default gateway information.  In my case, we generally perform the deployment in a staging area where the default gateway is always the same whatever the location the computer will be send to.

Click on picture for better resolution

Advanced tweaks on OSDComputerName variable

So far, we have seen that there are a bunch of possibilities in the process of automatically set the computer name. You can use variables, type of computers….whatever.  Since, a lot of us are working with virtualization solution; there will be a situation were we will encounter a small issue when trying to automatically set the computername using the serial number variable.

Indeed, there is a technical limitation in the number of characters you can use in a computer name.  a computername cannot exceed 15 characters.  Serial numbers generated by hypervisor are generally longer than 15 characters.   I had the same issue (computer name length) with physical laptop.  Some manufacturer might have longer serial numbers than other.  When combining the prefix and the serial number, the number of characters were exceding the limit of 15.

You have two options to solve this issue.  The first one is quite simple and consist of using again the Customsettings.ini files (or rules via the GUI).  Yes, you read it correctly, you can perform some string manipulation directly in the GUI.  The other option would be to create your own script and perform the modification that you need in order to generate a valid computer name.

In the screenshot below, I’ve defined a rule that would take the last 8 digit of the serial number.

Click on picture for better resolution


You can check that during the deployment process, the computer name will be generated based on the rule you have defined.

Click on picture for better resolution

As mentioned, the other option would be to use a script.  In MDT 2012 Update 1, you should know that you can use PowerShell Script.  Below, you can see a screenshot of a powershell script that perform a rename operation.  In a future post, we will briefly describe how to have this script running within your MDT infrastucture.

Click on picture for better resolution

Final notes

As you can see, out-of-the-box, MDT 2012 offers you already a large set of options when you need to automate the computer name part of your deployment process.  By working with the MDT rules (the Customsettings.ini file), you can have a complete control of your deployment process. By tweaking this file, you should be able to achieve a zero touch installation using only MDT.

In the coming posts, we will see how to use PowerShell script and we will finally focus on how to achieve the zero touch installation

Till Next Time

See ya

51 thoughts on “MDT 2012 PART VIII – Automatically Set computer Name

  1. hi there i was wondering if you could help. i am using mdt 2012 to deploy windows 7 –
    It’s all working fine, however i have two issues and i don’t know where to start. 1st is that I would like to pull the names from a database / file I know you can use MS SQL and setup an database and link it up with the task sequence in mdt 2012… essentially I want to pre-stage the computer names so when the pc are re-imaged they get the correct name .
    Secondly I want to move the imaged computers into to the correct OU
    I would appreciate if you ca help

  2. Hello I tried putting the UUID option along side the below rules however the Computer type just appears as %ComputerType% when going through the sequence

    ■%IsLaptop% or %IsDesktop% or %IsServer% or %IsVM% (to detect if the client is a laptop or a desktop or Server or a VM)

    [Settings]
    Priority=ByLaptop, ByDesktop, MMSettings, MMRoles, RSettings, RApps, Default
    Properties=MyCustomProperty

    [ByLaptop]
    SubSection=Laptop-%IsLaptop%
    ComputerType=LT

    [ByLaptop]
    SubSection=Desktop-%IsDesktop%
    ComputerType=DT

    [Default]
    OSInstall=Y
    SkipCapture=NO
    SkipAdminPassword=YES
    SkipProductKey=YES
    SkipComputerBackup=YES
    SkipBitLocker=NO
    EventService=http://mdt:9800

    OSDComputerName=%ComputerType%#right(“%UUID%”,6)#

  3. Hello Gareth,

    I’m currently abroad…working on an heavy project…..
    Can you aleardy try the following…

    Check your CustonSettings.ini file… In the the [Settings] section, in the Properties line; you should have something like Properties=ComputerType,MyCustomProperty….

    give it a try and let us know if this fix your issue….

    Till next time
    See ya

  4. Hi, is there any possibility for getting the mac address of the client machines automatically and the installation process gives the name, specific drivers for the machines and configure them automatically?

  5. Heloo Arjun,

    can you be more specific about what you want to do ? I do not understand what you want to do. in the mdt task sequence, you can specify drivers to be installed, in MDT, you can automatically set the name of the computer based on different technics to meet your requirements. Yes, you can get MAC address automatically (using WMI during winpe phase of WINPE)..
    How to you put all these together ? What are you trying to achieve ?

    Provide a more exhaustive scenario and we will see if we can help you
    till next time
    See ya

  6. This is excatly what I needed. Thank you for this. I do have a question with pulling only a certain number of characters in the serial number. We have MS Surfaces we are deploying. With our prefix we add to our computer names we can only pull 11 characters from the serial number. However we use the first 11 digits, not the last.
    Would be switching it to left instead of right do this?
    Would the line be OSDComputerName=Prefix-#left(“%SerialNumber%”,11)# ??

    It seems to freeze my deployment before it starts when I use this

  7. Hello Corey,

    yes, this would be the approach…
    Ensure that you have not copy/paste this line from the web put retype it in order to ensure that no malformed character are there….
    Again, you should be on the good track

    Hope this help
    Till next time
    See ya

  8. Simple function to get unique part of serial number.

    Public Function UniqueSN(strManufacturer, strSerialNumber, intSerialLen)
    Select Case strManufacturer
    Case “ASUSTeK Computer Inc.”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “ASUSTeK COMPUTER INC.”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “Dell Computer Corporation”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “Dell Inc.”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “Hewlett-Packard”
    UniqueSN = Right(strSerialNumber, intSerialLen)
    Case “LENOVO”
    UniqueSN = Right(strSerialNumber, intSerialLen)
    Case “TOSHIBA”
    UniqueSN = Right(strSerialNumber, intSerialLen)
    Case Else
    UniqueSN = “strSerialNumber”
    End Select
    End Function

  9. edit:

    Public Function UniqueSN(intSerialLen)
    strSerialNumber= oEnvironment.Item(“SerialNumber”)
    Select Case oEnvironment.Item(“Make”)
    Case “ASUSTeK Computer Inc.”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “ASUSTeK COMPUTER INC.”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “Dell Computer Corporation”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “Dell Inc.”
    UniqueSN = Left(strSerialNumber, intSerialLen)
    Case “Hewlett-Packard”
    UniqueSN = Right(strSerialNumber, intSerialLen)
    Case “LENOVO”
    UniqueSN = Right(strSerialNumber, intSerialLen)
    Case “TOSHIBA”
    UniqueSN = Right(strSerialNumber, intSerialLen)
    Case Else
    UniqueSN = “strSerialNumber”
    End Select
    End Function

    and this article willbe helpfull

    https://blogs.technet.microsoft.com/benhunter/2007/04/15/bdd-2007-tips-and-tricks-how-to-write-a-custom-script

  10. Could you please let me know how we can setup this for pre staging computers. Computer name is already in the Active Directory. How MDT can pick the name from AD??

  11. @Ranga

    this is a interestng question…and multiple ways….

    I do not know your setup but I would try to write a script that Query the Active Directory looking up for the prestaged account. Using a Unique identifer(mac address,guid,…), when a match is found, the name found in AD can be set

    Same approach could be to use a web service
    Another approach would be to export prestaged account + unique attribute and use this as input file in a script. if mac address found in the list, then set name to proper value…

    If the MDT is join into the domain, you might be able to use the WDS functinoalites while running MDT….

    If I have time, I will have a look at it

    Hope this help
    Till next time
    See ya

  12. im having some issues setting the computer name via mac address from the DB. It just wont set the name iv given.

    What am i doing wrong. i think its something in the CS. Id appreciate any help
    Here is my CS

    Settings]
    Priority=CSettings, CRoles, Locations, LSettings, MMSettings, MMRoles, RSettings, Model, Default
    Properties=MyCustomProperty

    [Default]

    KeyboardLocale=ja-jp;0411:00000411
    UILanguage=ja-JP
    UserLocale=ja-JP
    Systemlocale=ja-JP
    TimeZone=235
    TimeZoneName=Tokyo Standard Time

    EventService=http://server addy:9800

    OSInstall=Y
    SkipBDDWelcome=YES
    SkipAppsOnUpgrade=YES
    SkipAdminPassword=YES
    SkipApplications=YES
    SkipProductKey=YES
    SkipComputerBackup=YES
    SkipDomainMembership=YES
    SkipUserData=YES
    SkipPackageDisplay=YES
    SkipLocaleSelection=YES
    SkipTimeZone=YES
    SkipBitlocker=YES
    SkipCapture=YES
    SkipSummary=YES
    SkipTaskSequence=NO
    DriversApplied=YES
    SkipFinalSummary=YES
    OSDComputerName=%Computer%

    DomainAdmin=user
    DomainAdminPassword=password
    MachineObjectOU=OU=Laptops,OU=Computers,OU=Tokyo,OU=Japan,DC=enworld,DC=com
    FinishAction=REBOOT

    [CSettings]
    SQLServer=192.168.xx.xx
    Instance=SQLEXPRESS
    Database=MDT
    Netlib=DBNMPNTW
    SQLShare=DeploymentShare$
    Table=ComputerSettings
    Parameters=UUID, AssetTag, SerialNumber, MacAddress
    ParameterCondition=OR

    [CRoles]
    SQLServer=192.168.xx.xx
    Instance=SQLEXPRESS
    Database=MDT
    Netlib=DBNMPNTW
    SQLShare=DeploymentShare$
    Table=ComputerRoles
    Parameters=UUID, AssetTag, SerialNumber, MacAddress
    ParameterCondition=OR

    [Locations]
    SQLServer=192.168.xx.xx
    Instance=SQLEXPRESS
    Database=MDT
    Netlib=DBNMPNTW
    SQLShare=DeploymentShare$
    Table=Locations
    Parameters=DefaultGateway

    [LSettings]
    SQLServer=192.168.xx.xx
    Instance=SQLEXPRESS
    Database=MDT
    Netlib=DBNMPNTW
    SQLShare=DeploymentShare$
    Table=LocationSettings
    Parameters=DefaultGateway

    [MMSettings]
    SQLServer=192.168.xx.xx
    Instance=SQLEXPRESS
    Database=MDT
    Netlib=DBNMPNTW
    SQLShare=DeploymentShare$
    Table=MakeModelSettings
    Parameters=Make, Model

    [MMRoles]
    SQLServer=192.168.xx.xx
    Instance=SQLEXPRESS
    Database=MDT
    Netlib=DBNMPNTW
    SQLShare=DeploymentShare$
    Table=MakeModelRoles
    Parameters=Make, Model

    [RSettings]
    SQLServer=192.168.xx.xx
    Instance=SQLEXPRESS
    Database=MDT
    Netlib=DBNMPNTW
    SQLShare=DeploymentShare$
    Table=RoleSettings
    Parameters=Role

  13. @Alex,

    Currently abroad and travelling a lot…Give me some days and I will have a look into it

    Sorry for the delay

    Till next time
    See ya

  14. Hello Thr,

    Please help with below requirement.
    I am trying to setup MDT to assign auto computer name.
    Desktop Name should start from SYS and four digit number (SYS0001 ) numbers should go in sequence
    Laptop Name should start from LAP and four digit number (LAP0001) numbers should go in sequence.

    Thanks,
    Shariff.

  15. @Shariff

    currently working abroad for a heavy project….if time permit, will have a look into this but if you want to do something incremental, you would need a list of some sort (I think)….

    Till next time
    See ya

  16. Hello Thanks for the advise you are giving
    I am new to MDT and was wondering if there is a way to have it the name in this format
    LH10+serial number

    where “L” stand for Laptop or Desktop

    “H” stand for HP or Dell or Lenovo and so on

    “10” stands for Win 10 or Win 8 or Win 7

    then the serial number

    L for Laptop and D for desktop

    Then OS like Windows 10 or Windows 8 or Windows 7

  17. @Walah,

    Technically this should be possible you would need to customize the the customSettings.ini file
    By default, MDT comes with pre-defined variable that you can then use within your customsettings.ini file
    You would need to define your variable in the [Settings] section ex MyLaptop,MyMake,….

    You would need to create subsections [MyLaptop] and [MyModel] or [MyMake] and create variable that can be used to construct the name you want to use….
    for example, if you want to identify a laptop, you would add something like this in your customsettings.ini file

    [MyLaptop]
    SubSection=Laptop-%IsLapTop%
    PCCategory=L

    and then in the same file, you would need to adapt your OSDComputername variable to concatenate your created variable
    something like
    OSDComputername=%PCCategory%-%PCSerialNumber%

    Hope this help
    Till next time
    See ya

    As currently, we do not have much time to create a post about that… We are really overloaded by work….

    Hope this help
    Till next time

  18. Griffon

    Thanks a million for the information. I will follow your advise and example and test and hopefully get it done

    Appreciate the help

  19. Hello,

    Does anyone know of a way to set the OSDComputerName variable to the computer’s hostname?

    Any advise would be greatly appreciated.
    -M

  20. I would also like to use the OSDComputerName variable to set the name of the computer to the DNS hostname of the computer I’m imaging.
    Does anyone know if this is possible?

    -M

  21. @Matthew Oliver,

    This should be possible but we have no time to test and provide info back to you… anyone who could help here….?

    Till next time
    See ya

  22. Hi, how can i add an highcounting number at the end.. And let a script check if this number is free in AD.
    Like this:
    OSDComputername=%PCCategory%-%Number%
    Result: PC-001, PC-002, PC-003….
    But a sript shoud check if PC-002 is alreday in use in AD.
    Is this possible?

    Thnaks

  23. @Thomas,
    You would need to create a custom script to query AD and check for existence or not of computer account in AD. Powershell would be probably the way to go. So you would need to create a custom step in your task sequence and use your custom script…

    Hope this help
    Till next time
    See ya

  24. Hey I’m 1 step away from my perfect setup, but:
    – LTI asks for a computername, I enter it.
    -deployment goes on and my PC is properly put into AD and in the right OU where i want it. When i log on, i check the computername and it’s generic, like DESKTOP-PDBNDS

    Why didn’t it take the Litetouch name i specified?
    thx

  25. @Tom,
    cannot tell why….
    If the system is configured properly (MDT i mean) This should be working…..
    The fact that the computer name looks like DESKTOP-PDBNDS let me think that there is a rule or a task step that set this value….If MDT was automatically generating computer account, it would be something like MINIT-xxxxx

    Hope this help
    Till next time
    See ya

  26. unfortunately there’s none defined in a tasksequence, customsettings.ini or bootstrap. I think the DESKTOP-stomething is the default windows10 nomination of newly installed computers. perhaps i have to ADD a step in the tasksequence somewhere!? how would the step be named or the script used to set the name? (as most are LTI-scripts or ZTI)

  27. seems that it also has to do with the “Joindomain” setting present in the customsettings.ini. I removed as it was necessary to be able to do captures again, and now the PC has taken the name

  28. I was wondering if you can help me with the correct syntax to automate the computer name to limit the %make% to 4 characters and include serial number, I have tried:
    #Left(“%Make%”,4)#-%SerialNumber%

    but does not work..

  29. @Ricardo;

    at first glance, the syntax seems correct. so you reading the 4 first character starting from left and then you add the serial number to it
    Do not forget that computername is limited to 15 characters. Second, have you added on top of your file, the parameters you want to use (serialnumber and the make variable )

    Hope this help
    Till next time
    See ya

  30. Question, is there a way to setup the prefix for the computer name based on the TS selected? For example, I have a Finance (FIN) and Database (DBA) team. If I use the Finance TS from MDT on a new machine, I want MDT to setup the computer name based on the team’s prefix, a dash, and the computer’s serial number (i.e. FIN-######). Is this possible? Thanks!

  31. @Jonathan,
    Not sure what you are trying to achieve here.. so if TS stands for Task Sequence and you are asking if you can use customSettings.ini only to have different computername, this might be possible. You have to modify the customsettings.ini file and set the TaskSequenceID in the Property rules (top of the file)
    Then you create 2 sections in Customsettings.ini you would end up with something like this
    [Settings]
    Priority=TaskSequenceID, Default

    [taskID1]
    ComputerName=Fin-#######

    [taskID1]
    ComputerName=DB-#######

    You might need to perform some additional changes within the Task Sequence file but I think this should be the way to go

    Hope this help
    Till next time
    See ya

  32. “Thanks for one’s marvelous posting! I certainly enjoyed reading it, you might be a great author.
    I will ensure that I bookmark your blog and will come back in the foreseeable future.
    I want to encourage you to ultimately continue your great work, have a
    nice day!”

  33. This is the right blog for anyone who wants to find out about this topic. You realize so much its almost hard to argue with you (not that I actually would want…HaHa). You definitely put a new spin on a topic thats been written about for years. Great stuff, just great!

  34. Hello there, I do believe your site might be having browser compatibility problems. Whenever I take a look at your web site in Safari, it looks fine however, when opening in IE, it’s got some overlapping issues. I merely wanted to provide you with a quick heads up! Apart from that, excellent blog!

  35. hello!,I like your writing very much! percentage we be in contact extra about your post on AOL? I require a specialist on this area to solve my problem. Maybe that’s you! Having a look forward to peer you.

  36. @Hannah,

    Ok, your message is not totally clear to us…. If you need some help and support in specific IT area, please feel free to contact us and describe your request with more details…we will then see availability and feasability….

    thanks for the visit

    Till next time
    See ya

  37. Hello there, just became alert to your blog through Google, and found that it is truly informative. I am gonna watch out for brussels. I’ll be grateful if you continue this in future. Lots of people will be benefited from your writing. Cheers.

  38. I like the helpful info you provide in your articles. I will bookmark your weblog and check again here frequently. I’m quite sure I’ll learn plenty of new stuff right here! Good luck for the next

  39. kindly help me to place suffix country code based on default gateway and D for desktop, L for Laptop, VM for Virtual followed by 6 digit last serial number
    UK–country code
    L–Laptop
    123456-serail number
    if it is desktop/Laptop/VM has to go to specific country OU

  40. @Unknown,

    There is not enough information here for us to help you… Where are you facing the issue ? have you updated the CustomSettings.ini file accordingly to make use of variables ?
    Using the CustomSettings.ini files, you can define rules to detect desktop vs Laptop. In the customSettings ini file, you can also specify OU where the machine would be located
    Your file could contain something like this


    [Settings]
    Priority= ByDesktop, ByLaptop, Default
    Properties=ComputerType,MyCustomProperty

    [ByLaptop]
    Subsection=Laptop-%IsLaptop%
    ComputerType=L

    [ByDesktop]
    Subsection=Desktop-%IsDesktop%
    ComputerType=D

    [Desktop-True]
    OSDComputerName=%ComputerType%-%SerialNumber%
    MachineObjectOU= OU=Desktop,DC=Demo,DC=LAB

    [Laptop-True]
    OSDComputerName=%ComputerType%-%SerialNumber%
    MachineObjectOU= OU=LAPTOP,DC=Demo,DC=LAB

    To join the domain, again you can use the CustomSetings.ini file and specify the information needed to join the domain or execute a task in your full task sequence to join the domain
    may be you can have a look at http://c-nergy.be/blog/?p=3962 and see if you can adapt it to your needs

    Hope this help
    Till next time

    See ya

  41. kindly help me how to add country code example UK- followed by L (laptop), D desktop, VM Virtual + Serial number number country code cam be selected from GUI popup or default gateway please provide hints
    UK country cde
    L Laptop
    Serial number

Leave a Reply