Monday 25 February 2013

MDT Naming Trick - Show Machine's Existing Name

MDT Pre-Populate Name Trick

You ever had it when a machine needs to be rebuilt because it's either crashed completely or is suffering issues that you know, deep down in your technical heart, a rebuild will sort it all out.

So what do you do?

You press that magical network boot key, PXE boot that machine and start the MDT process.  Fantastic, you the go through the wizards to eventually get to the "Computer Name" stage where it then prepopulates the name with a MiniNT name and you go.. hmm.. bugger what the name of the machine again?

You look for a sticker, which has obviously fallen off or worn away, you think i'll need to reboot to get to the login screen to find the name there.. which isn't an option if the machine is totally broke.

Wouldn't it be nice to have the machine put in its actual, existing name in place of that MiniNT name, still editable if required, but there for a reference at least.  Well you can, using some minor trickery and awesomeness.

Thanks to Michael Klinteberg from Technet forums, a simple script copied into the Scripts folder in your deploymentshare and two lines added to your customsettings.ini file will give you the desired effect.

Copy the below script into notepad and save it as "UserExit.vbs"

Function UserExit(sType, sWhen, sDetail, bSkip)
 oLogging.CreateEntry "entered UserExit ", LogTypeInfo
 UserExit = Success
End Function

Function GetOfflineComputername()
On Error Goto 0

 If oEnvironment.Item("OSVERSION")="WinPE" Then
  Dim CompName : CompName = ""
  Dim ret, sOldSystem : sOldSystem = ""
  For Each drv In Array("C", "D", "E", "F")
   If ofso.FileExists(drv & ":\windows\system32\config\system") Then
    sOldSystem = drv & ":\windows\system32\config\system"
    Exit For
   End If
  oLogging.CreateEntry "Mounting Offline registry " & sOldSystem, LogTypeInfo
  ret = oShell.Run ("reg load HKLM\z " & sOldSystem, 0, True)
  If ret = 0 Then
   CompName = oShell.RegRead("HKLM\z\ControlSet001\Services\Tcpip\Parameters\Hostname")
   If CompName <> "" Then
    oLogging.CreateEntry "Found old computername '" & CompName & "'", LogTypeInfo
    oLogging.CreateEntry "Old computername name could not be found", LogTypeWarning
   End If
   oLogging.CreateEntry "Could not mount offline registry " & sOldSystem, LogTypeWarning
  End If
  oShell.Run "REG UNLOAD HKLM\Z", 0, True  
  CompName = oShell.ExpandEnvironmentStrings("%Computername%")
 End If

 GetOfflineComputername = CStr(CompName)
End Function

Copy this file to the Scripts folder in your DeploymentShare.

Open up your CustomSettings.ini file, (in the control folder if you want to go through windows rather than through  the MDT deployment workbench) and add the following two lines underneath [Default].


Make sure that if you have already typed in any reference to OSDComputerName in your customsettings.ini, you must remove it.  See this as its replacement. 

Update your deploymentshare, re-input your litetouch images in WDS and you're done.  

Essentially, every time your machine starts MDT, this script will run and query the inbuilt WMI database on your windows machine, pulling out the true name and once it has that name it puts it into the computername field in your MDT wizard.

The only time this would not work is if your machine is so badly corrupt, WMI isn't working, but trust me, that's usually the last bit to go, if that isn't working then you might have a faulty hard drive as even machines that refuse to bootup still manage to maintain their WMI database.

Hope this helps some of you out there!



  1. This is awesome. Thank you for posting!

  2. I wish I would have known about this a few years ago. Much time saved now! Thanks!

  3. thumbs up!

    I Have been looking for this solution for ages, multiple websites discus "this topic" but eventually after reading through the whole topic they seems end up naming a pc using namingconventions based on serial or model.

    I Finally found what I needed, thank you so much!

  4. Great work! Works perfectly, and defaults the name when setting up from fresh install


Please enter your comment here, all comments are subject to moderation