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
Next
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
Else
oLogging.CreateEntry "Old computername name could not be found", LogTypeWarning
End If
Else
oLogging.CreateEntry "Could not mount offline registry " & sOldSystem, LogTypeWarning
End If
oShell.Run "REG UNLOAD HKLM\Z", 0, True
Else
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].
UserExit=UserExit.vbs
OSDComputername=#GetOfflineComputername()#
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!
ITMagician
This is awesome. Thank you for posting!
ReplyDeleteI wish I would have known about this a few years ago. Much time saved now! Thanks!
ReplyDeletethumbs up!
ReplyDeleteI 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!
Great work! Works perfectly, and defaults the name when setting up from fresh install
ReplyDelete