none
Rename Computer before joining to domain?

    Question

  • Hey guys I was just in another section of technet where they helped me with this: Link Here

    I basically need some assistance with naming the computer.

    I have it setup to pull the serial number "OSDComputerName=%SerialNumber%" set in the Rules area of the MDT Deployment Share.

    I would like to have THAT computer name changed or replaced before joining the domain, with the specifications shown in my other post.

    Can it be done? How? 

    Thank you very much in advance. This simple (what appears simple) task could save us tons of time during deployment.

    Friday, October 04, 2013 2:27 PM

All replies

  • Hi,

    I have looked at the other thread on technet, seems to me you need to put the code: 

    $name = "2CE1234FTS"
    $length = $name.length
    $lastThree = $name.Remove(0,$length-3)
    $newName = $lastThree + $name.TrimEnd($lastThree)
    $computerName = Get-WmiObject Win32_ComputerSystem
    $computerName.Rename($newName)

    In a powershell script, open notepad, paste the code:

    $name = "OSDComputerName"
    $length = $name.length
    $lastThree = $name.Remove(0,$length-3)
    $newName = $lastThree + $name.TrimEnd($lastThree)
    $computerName = Get-WmiObject Win32_ComputerSystem
    $computerName.Rename($newName)

    Save the script in the MDT Deployment Shares 'SCRIPTS' folder as: "ZTIOSDComputerRename.ps1"

    Then create a 'run command line' in your task sequence before the following step:

    and call the powershell script as following:

    powershell -noprofile -executionpolicy bypass -file "%SCRIPTROOT\ZTIOSDComputerRename.ps1%"

    After the rename, add an additional reboot

    Hopefully this will work :)

    Good luck!


    If this post is helpful please click "Mark for answer", thanks! Kind regards


    Friday, October 04, 2013 6:52 PM
  • Not to take anything away from the script that Rens put together, but I don't think this will work. Doing it this way will cause you to have 2 machine objects in your environment, 1 with the old machine name and 1 with the new. The only way this would work is if you delayed the domain join in MDT. Regardless, there is a much more effective way of doing this, and my apologies if I am not understanding what you are trying to do but it looks like you just want the last 3 characters of the serial number placed at the beginning of the characters that are leftover. To better achieve this use a UserExit script in MDT.

    Copy this code into notepad, save as UserExit.vbs, and place at the root of your Scripts folder in your deployment share:

    Function UserExit(sType, sWhen, sDetail, bSkip) 
    	UserExit = Success
    End Function
    
    Function GetPCName(sSerialNumber)
    
    	Dim rSerial, lSerial
    	
    	rSerial = Right(sSerialNumber,3)
    	lSerial = Left(sSerialNumber,Len(sSerialNumber)-3)
    
    	GetPCName = rSerial & "" & lSerial
    	
    End Function

    Than in your customsettings.ini file, add these 2 rules:

    UserExit=UserExit.vbs
    OSDComputerName=#GetPCName("%SERIALNUMBER%")#


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”

    Saturday, October 05, 2013 5:48 PM
  • I should add that there is a very easy way to test what computer name MDT is gathering without having to run a deployment:

    1. Create a folder called TEST-CS (I have mine at the root of C: - C:\TEST-CS)
    2. From the scripts folder in your deployment share, copy the ZTIDataAccess.vbs, ZTIGather.wsf, ZTIGather.xml, and the ZTIUtility.vbs scripts to your TEST-CS folder
    3. Now copy your customsettings.ini that you want to test to the same folder
    4. Open an elevated command prompt, navigate to your TEST-CS folder and run

    cscript .\ZTIGather.wsf /debug:TRUE /inifile:.\customsettings.ini

    This will create the MININT folder under the root of C: where you will find the ZTIGather log that shows the rules processed by MDT, or you could just look at the output from the CMD window. Just make sure you delete the MININT folder when you run another test.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. ”

    Saturday, October 05, 2013 6:02 PM