This batch is used with a few other files as start-up scripts as a part of the Symantec Ghost Cast re-imaging process for Windows 7 we are about to undertake. Together they totally automate the entire re-imaging process of Sysprep, renaming the computer from text file, then joining the computer to the domain and placing in the correct OU.
I know there are other programming languages and scripting languages that can perform these same processes far better but no time for learning them at this moment. Sure MSs Power-shell and VBS are better candidates but I am not spent up on those just quite yet, nor are my coworkers. Other renaming applications works intermittently for me. Compname.exe does not work with Windows 7. Wsname works intermittently or not at all with our some of Dell models 790, Power Edge servers 850, 860, and R200. Our other models do not seem to have any major issues using the third party applications--GX620, 740, 745, 755, 760, and 780.
I prefer to use native applications already within the OS. Obviously netdom.exe is not native (have to obtain files from the RSAT executable) but it is an easy OS import and a must have on the images.
So please, provide any answers with the programs I am currently using (batch, netdom, getmac, and good ole text files).
This batch file accomplishes the following:
- Uses getmac.exe to find the MAC address of the local machine (being reimaged)
- Variablizes the local MAC address (%%G)
- Pipes the variablized MAC address and compares it to getmac2.txt file (%%A)
- Grabs the associated variable (%%B) and
- Places the %%B as the strComputername
- The && statement stops the operation when the MAC address is found instead of parsing the entire file
- The :insert_name label runs netdom.exe, closes the batch and reboots the computer. The /FORCE switch is used but not listed here while testing. The 'pause' is used only for testing as well.
A subsequent script joins the computer to the domain.
Now, this is what I would like to try... I would like to be able to modify the %%G variable by replacing the dashes '-' in the MAC address with colons ':'. Getmac.exe produces the MAC address like this 11-22-33-44-55-66. However, another admin program provides me a list with MAC addresses like this 11:22:33:44:55:66. My getmac2.text file lists the MAC addresses with the colons. Obviously, I can automatically remove the colons from a text editor but the intent is to reduce as many steps as possible. Also piping the %%G variable to another file would not be a problem if it is easier to perform the string replacement.
BELIEVE IT OR NOT, THE SCRIPT DOES WORK PERFECTLY!
getmac2.txt file contents are formatted like this:
11:22:33:44:55:66,88D-350-03-780 11:22:33:44:55:77,44E-351-13-790 11:22:33:44:55:88,66F-352-23-760 11:22:33:44:55:99,22G-353-33-R200 11:22:33:44:55:00,11H-354-43-620
setlocal enabledelayedexpansion FOR /F "usebackq delims= " %%G IN (`getmac.exe /FO table /NH`) DO ( FOR /F "usebackq delims=, tokens=1,2" %%A IN (`type C:\wsname\getmac2.txt`) DO if %%G EQU %%A SET strComputername=%%B && goto insert_name ) :insert_name C:\windows\system32\netdom.exe renamecomputer %COMPUTERNAME% /NewName:%strComputername% pause