In a Computer Refresh scenario on an un-encrypted machine, the old Computer Name is stored in plain text in the registry on the local disk. MDT can pull in this information and toss it into the OSDComputerName variable to hasten your Deployment Wizard.
1. Update your CustomSettings.INI (Rules) to call an external script to populate the OSDComputerName variable.
[Settings] Priority=Default Properties=MyCustomProperty [Default] OSInstall=Y SkipCapture=NO SkipAdminPassword=YES SkipProductKey=YES SkipComputerBackup=NO SkipBitLocker=NO UserExit=ZTIGrabOldCompName.vbs OSDComputerName=#fGrabOldCompName("MDT")#
2. Add the ZTIGrabOldCompName.vbs script to your <DeploymentShare>\Scripts directory.
https://github.com/brianfgonzalez/Scripts/blob/master/ZTIGrabOldCompName.vbs
' // *************************************************************************** ' // ' // Copyright (c) Microsoft Corporation. All rights reserved. ' // ' // Microsoft Deployment Toolkit Solution Accelerator ' // ' // File: ZTIGrabOldCompName.vbs ' // ' // Purpose: Grabs old CompName if avail. and returns to CS.INI. ' // ' // *************************************************************************** Function UserExit(sType, sWhen, sDetail, bSkip) UserExit=Success End Function Function fGrabOldCompName(sDefaultName) Dim sOldCompName, sLocalSWHiveFilePath oLogging.CreateEntry "UserExit:Pulling computername from local registry.", LogTypeInfo If oFSO.FileExists("C:\WINDOWS\system32\config\system") Then sLocalSWHiveFilePath = "C:\WINDOWS\system32\config\system" ElseIf oFSO.FileExists("D:\WINDOWS\system32\config\system") Then sLocalSWHiveFilePath = "D:\WINDOWS\system32\config\system" ElseIf oFSO.FileExists("E:\WINDOWS\system32\config\system") Then sLocalSWHiveFilePath = "E:\WINDOWS\system32\config\system" Else sLocalSWHiveFilePath = "FALSE" End If oLogging.CreateEntry "UserExit:Local system hive location set to: " & sLocalSWHiveFilePath, LogTypeInfo If sLocalSWHiveFilePath <> "FALSE" Then oShell.Run "reg load HKLM\sysimport " & sLocalSWHiveFilePath, 1, True sOldCompName = oShell.RegRead("HKLM\sysimport\ControlSet001\Control\ComputerName\ComputerName\ComputerName") oShell.Run "reg unload HKLM\sysimport", 1, True fGrabOldCompName = sOldCompName oLogging.CreateEntry "UserExit:Setting OSDComputerName variable to: " & sOldCompName, LogTypeInfo Else fGrabOldCompName = sDefaultName oLogging.CreateEntry "UserExit:Error locating old computername. Setting computername to default value: " & sDefaultName, LogTypeError End If End Function
3. Lastly, test a refresh machine deployment. The script will log to the BDD.log.
FYI: This script was tested on MDT2013 and MDT2012U1.
/Brian G
Hi Brian,
Great script, can this be incorporated with [DefaultGateway]?
‘If’ the machine has been previously built it uses the previous name as per the script.
‘If’ it has not then the machine should be labelled with OSDComputerName=%ComputerLocationName% which is a property used e.g.
[DefaultGateway]
192.168.2.0=Test
[Test]
ComputerLocationName=TE1100
Looking at the script it uses ‘MDT’. Can this be changed?
Thanks
Matt,
This script is meant to be used within an MDT (Microsoft Deployment Toolkit) CustomSettings.INI file, it is specific to that tool. Are you using this tool? If so, your example is good.
I am running MDT.
I have modified the script to work with my requirements.
Thanks again.
Hello Matt,
I’m trying to use the script. Having trouble getting it to populate name .
Here are mt settings:
UserExit=\\PC-LT\DeploymentShare$\Scripts\ZTIGrabOldCompName.vbs
OSDComputerName=#fGrabOldCompName(“MDT”)#
UserDataLocation=\\PC-LT\DeploymentShare$\Captures\%OSDComputerName%
%OSDComputerName% returns the function name “#fGrabOldCompName(“MDT”)#” ..
What did I miss?
Thanks,
Rick
Maybe its because you are setting UserExit to the full path of the vbs instead of just the vbs filename?
/BG