Advertisements
What's New

MDT Sequential Computername Workaround???…..Finally!

MDT Logo There are quite a few Windows Deployment Services fans out there who have decided to implement the Microsoft Deployment Toolkit to spice up their OS deployments only to find out that MDT does not have the same machine Naming Policy as WDS :( Sure you can use simple Visual Basic expressions to generate unique Computernames but what about the folks who just want to generate basic sequential computernames (SalesPC01,02,etc...)?

There are a handful of workarounds that have been floating around the Internet for some time but those of you who prefer a workaround that doesn’t involve implementing the MDT database or robust scripting languages like Powershell or VBS will be disappointed I’m afraid.

That’s why I developed a simple batch script to solve this problem. Before I get into how it works, please note the list of Prerequisites you must fulfill before adding this script to your Task Sequence.  Also, I know the video is a bit rushed so I will put together a more detailed video at a later time that goes a bit more in depth.

PREREQUISITES
—————-
A) In the Rules tab or CustomSettings.ini, Set OSDComputerName value to the first machine in the sequence(SalesPC01, MarketingPC01, etc..)

B) Create a shared folder  that each machine can access. Create a shared folder  that each machine can access

C) Add a “Run From Command Line” step to the Task Sequence and place it in the State Restore phase right above “Recover From Domain”
Editing The Script
———————
There are two changes you will have to make to the script that I didn’t mention in the video and that is the username and password of an account that can authenticate to the network share.

Add Admin Creds

1) Find the :CreateLog step in the script,
2) Read my comments
3) Enter the your user credentials where applicable.

Click here to get MDTSequential code!

Have fun and enjoy!! 🙂

Advertisements

7 Comments on MDT Sequential Computername Workaround???…..Finally!

  1. OK I get the reasoning behind the text file creation: it’s a way to ensure the naming election process doesn’t produce duplicates, necessary and clever indeed.

    I am thinking of a better way to do this:
    1. Leave the CustomSettings.ini computer name in the default random value and forget about using it as a variable. The name will change anyway in the next steps.
    2. Just before the domain join as in your method, run dsquery computer “OU=Computers,DC=domain,DC=local” -o rdn | find /i “pcname” to get a list of all computers in the destination OU and elect an available name from the result (i.e., start the process of incrementing from 1 until you find a name that doesn’t exist). In a large domain it may be necessary to create a “election_in_progress” text file that tells other machines to wait while this process runs on one machine to ensure reliability and reduce load on AD.
    Note: this step is theoretical at this point. dsquery can only work from a domain joined machine. As this script runs on a non-domain member it will fail, however my idea is to try and run the dsquery script as a domain user using the “Run this step as the following account” option which may or may not work. If dsquery cannot run before the domain join, we can simply join the machine to the domain using the default random MDT computer name (which my understanding is unique) and then run steps 2 and 3.
    3. Then create a text file with the elected name so that other running deployments can check and make sure they don’t elect that name as it can take a few seconds (or more in large environments) between the time the computer has elected a name and an AD computer object has been created for it. The process then continues to join the domain and at some point, maybe after a reboot and validation, the pcname text file should be deleted as subsequent dsqueries will contain this name anyway.

    This ensures that computers always get an available name based on the current status in AD rather than going by text files.

  2. Hi, I had a look at your script and it gave me an idea: why not simply use nslookup as the only method to check if a computer name already exists in the domain? I’m not sure I understand why you do all the text file creations and checks. Thanks

  3. Thank you for this! I made a couple changes that may be useful if you want to keep consistent name lengths and have it run quicker. For our names PCEND is 4 characters and 0001 becomes 02 and 0009 is 010. If you change ‘set PCNAME=%PCBEG%0%PCEND%’ to set ‘PCNAME=%PCBEG%000%PCEND%’ then 0001 becomes 0002 but 0009 becomes 00010. To maintain consistent length and increment the max computer number without checking all of them in between 1 and max I changed the :TRYAGAIN to:

    echo.
    set max=0
    for /f “tokens=1-3 delims=-.” %%A in (‘dir /b /a-d %MDTSHARE%\NOMEN-*.txt’) do if %%B gtr !max! set max=%%B REM Find the last computer name created
    FOR /F “tokens=* delims=0” %%A IN (“%max%”) DO SET max=%%A REM Remove Leading Zeros for batch math
    set /a “max=max+1”
    set PCEND=%max% REM This is likely an unnecessary step
    if %PCEND% GTR 0 if %PCEND% LSS 10 set PCNAME=%PCBEG%000%PCEND%
    if %PCEND% GEQ 10 if %PCEND% LSS 100 set PCNAME=%PCBEG%00%PCEND%
    if %PCEND% GEQ 100 if %PCEND% LSS 1000 set PCNAME=%PCBEG%0%PCEND%
    if %PCEND% GEQ 1000 set PCNAME=%PCBEG%%PCEND%
    goto RETRYLOGCHECK

    You DO need some type of deliminator character in your computer names for this to work properly. We added a – to our names since we didn’t have a unique character right before the numbers. Also since this method results in leading zeros we had to strip them out (in line 5) for the increment to work since batch file math treats numbers with leading zeros as octal.

  4. Thank you for this! I made a couple changes that may be useful if you want to keep consistent name lengths and have it run quicker. For our names PCEND is 4 characters and 0001 becomes 02 and 0009 is 010. If you change ‘set PCNAME=%PCBEG%0%PCEND%’ to set ‘PCNAME=%PCBEG%000%PCEND%’ then 0001 becomes 0002 but 0009 becomes 00010. To maintain consistent length and increment the max computer number without checking all of them in between I changed the :TRYAGAIN to:

    echo.
    set max=0
    for /f “tokens=1-3 delims=-.” %%A in (‘dir /b /a-d %MDTSHARE%\NOMEN-*.txt’) do if %%B gtr !max! set max=%%B
    FOR /F “tokens=* delims=0” %%A IN (“%max%”) DO SET max=%%A
    set /a “max=max+1”
    set PCEND=%max%
    if %PCEND% GTR 0 if %PCEND% LSS 10 set PCNAME=%PCBEG%000%PCEND%
    if %PCEND% GEQ 10 if %PCEND% LSS 100 set PCNAME=%PCBEG%00%PCEND%
    if %PCEND% GEQ 100 if %PCEND% LSS 1000 set PCNAME=%PCBEG%0%PCEND%
    if %PCEND% GEQ 1000 set PCNAME=%PCBEG%%PCEND%
    goto RETRYLOGCHECK

    You DO need some type of deliminator character in your computer names for this to work properly. We added a – to our names since we didn’t have a unique character right before the numbers. Also since this method results in leading zeros we had to strip them out (in line 5) for the increment to work since batch file math treats numbers with leading zeros as octal.

  5. Thanks for response. I am not syspreping – I am deploying a captured image of Win8 (not upgraded) The deployment work fine and freezes on the run command line when booted after full deployment. When I run the script standalone on client or server it comes back with the panther error – the beginning of the script works “no machine with this name has joined the domain” – then the access denied error. What is the panther part of the script used for
    Thanks
    H

  6. Hi
    I have been looking for a solution like this for a long time – my scripting experience is not good so I followed your instructions. I have the server and the client on private network with DHCP and DNS enabled. I havn’t set the clients to join the domain in the customsettings.ini. I am getting an error C:\ Windows\Panther\setupact.log access denied O files copied the system cannot find the file specified. Any help would be appreciated. My deployment share in on an external E drive which is shared and I have added username and password
    Thanks
    Howard

    • The most typical reason for your error message is that the Windows is upgraded? An upgraded Windows cannot be sysprepped.

      This means that if you have for instance in-place upgraded Vista to Seven, or using Anytime Upgrade upgraded for instance a Home Premium to Ultimate, you cannot sysprep. Notice that a repair install is also an upgrade install, so if you have ever done a repair install in-place upgrade to same edition), you cannot sysprep.

Leave a Reply

%d bloggers like this: