none
Check against AD and automatically name computers based on naming convention RRS feed

  • Question

  • Hello,

    A customer has a requirement to automatically name computers as they are deployed and conform to a naming convention.

    The way I'm thinking to achieve this is by getting the computers to check with AD what computer names already exist, elect a free one and then join with that to the domain.

    Now on to the technical stuff:
    Based on the research I've done so far, checking against AD for a list of computer names can either be done using PowerShell or using dsquery. Using PowerShell is more complicated as it requires the AD module and other pre-requisites and while getting that working seems possible it's just way more complicated than I'd like. dsquery is a lot more appealing as it seems that all it takes to make it work in the client OS is copying dsquery.exe and dskquery.dll and calling dsquery from the full local path (%windir%\system32\dsquery.exe).

    The dsquery line that gives me the output I want is this:
    dsquery computer "OU=Computers,DC=domain,DC=local" -o rdn

    So if dsquery is the more reasonable choice, we now have to think how are we going to make that work during the deployment. The main problem is that dsquery can only work if the machine is a member of the domain. To solve that we either
    a) create a "Run Command Line" step and use the "Run this step as the following account" option (probably won't work) or
    b) join the computer to the domain using the auto-generated MDT name (which I believe is unique per machine unless I'm wrong) and then run dsqeury and rename the computer based on the first available name.

    The next question is how do we get the deploying computer to generate a first available computer name after it has obtained the list of existing computers from dsquery. I found a couple of options online, mainly this guy here who seems to have worked out a batch file that does that (goes through a list of results and settles on the first unsued one):
    https://bjtechnews.files.wordpress.com/2014/07/mdtsequential.pdf
    Credit and original page: http://bjtechnews.org/2014/07/30/mdt-sequential-computername-workaround-finally/
    One key element to his script is the creation and checks of text files. This is a great idea as another problem that can arise is what happens if you've got 10 computers (or more) deploying at the same time all getting the same dsquery result and electing the same name. To ensure every computer gets a unique name we need to create a text file as soon as a computer has elected a name, or even go a step back and get all computers to wait while each one elects a name and posts it in a text file for all to see and skip.

    Does this sound like a good plan or is there a better way of doing this?

    Thanks in advance!


    • Edited by turmoil Wednesday, November 25, 2015 11:06 PM
    Wednesday, November 25, 2015 11:05 PM

All replies