none
MDT and Computer Name

    Question

  • I'm looking at trying to keep the computer name when I reimage using WDS 2012.  We name our computers a certain way and would like to keep from having to retype the name over and over when we reimage.  Hopefully someone can help me.  I need this to work on existing computers that are being reimaged.  Our naming schema goes XXX-0YYYYY-ARRR.  XXX represents the second quadrant of the ip address it is given by DHCP, 0YYYYY represents and interna fix asset numbering system, and ARRR refers to the room location of the computer.

    I know with new computer, I will have to give them a name so I would like to have the field editable when PXE booted into WinPE but just populated on the existing machine name if it had one.

    • Edited by MShirey Wednesday, May 09, 2012 9:28 PM
    Wednesday, May 09, 2012 9:27 PM

Answers

  • I've a userexit script that will mount the offline registry and read the computer name.

    Here's the userexitscript. Save it as UserExit.vbs in the scripts folder.

    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

    Then customsettings.ini, under General section add

    UserExit=UserExit.vbs
    OSDComputername=#GetOfflineComputername()#

    • Marked as answer by MShirey Thursday, May 10, 2012 3:02 PM
    Wednesday, May 09, 2012 10:47 PM

All replies

  • Not sure if you meant WDS or MDT 2012. In the case you meant WDS, I strongly suggest you use MDT instead. It's a much more flexible tool than WDS. Personally I never bother looking at WDS as it's too limited except of course for the PXE point.

    Now if you're already using MDT, according to your description, the deployment scenario you're referring to is a REFRESH. Therefore if you start the litetouch.vbs from the scripts folder from windows and set your deploymenttype variable in your customsettings.ini to REFRESH it will autofill the computername field with the current computer name. Also make sure that you have set SkipComputerName=NO in your customsettings.ini if you want to edit it before imaging.

    A bit out of context but I found your naming schema questionable. IP address given by a DHCP aren't fixed and can change with time unless your reserved them of course. Here's an example of what I consider a better naming schema for computers: [LOCATION,MAX 3 Letters]-[TYPE]-[#ID] So for instance

    NYC-WKS-030 - New York-Workstation-030
    CHI-LAP-AA549 - Chicago-Laptop-AA549 - Add letters if you organization has more than 999 computers
    NYC-DC01 - NewYork-DomainController01 - For server I like to keep it to only 2 variables.

    The hiffen are used to created delimitation to isolated each part of the name.

    Hope it helps!

     


    Alexandre Pitre, MCTS:Deploying Win 7 & Office 2010

    • Proposed as answer by JoeZeppy Thursday, May 10, 2012 3:14 AM
    Wednesday, May 09, 2012 10:32 PM
  • I've a userexit script that will mount the offline registry and read the computer name.

    Here's the userexitscript. Save it as UserExit.vbs in the scripts folder.

    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

    Then customsettings.ini, under General section add

    UserExit=UserExit.vbs
    OSDComputername=#GetOfflineComputername()#

    • Marked as answer by MShirey Thursday, May 10, 2012 3:02 PM
    Wednesday, May 09, 2012 10:47 PM
  • [Settings]
    Priority=Default
    Properties=MyCustomProperty
    
    [Default]
    DeployRoot=\\WDS\XP-DS
    OSInstall=YES
    SkipAppsOnUpgrade=YES
    SkipCapture=YES
    SkipAdminPassword=YES
    SkipProductKey=YES
    
    SkipFinalSummary=YES
    
    SkipLocaleSelection=YES
    KeyboardLocale=en-US
    UserLocale=en-US
    UILanguage=en-US
    
    SkipTimeZone=YES
    TimeZone=020
    TimeZoneName=Central Standard Time
    
    SkipUserData=YES
    
    SkipDomainMembership=YES
    JoinDomain=domain.contoso.net
    EventService=http://WDS:9800

    @ Michael - Thank you so much for the script.  I created the script and put it in the folder that you said to put it in.  When I go to the Rules tab of my deoployment share, I wasn't 100% sure where to add the two lines.  I have attached below what my current CustomSettings.ini looks like.

    Thursday, May 10, 2012 1:47 PM
  • [Settings]
    Priority=Default
    Properties=MyCustomProperty
    
    [Default]
    DeployRoot=\\WDS\XP-DS
    OSInstall=YES
    SkipAppsOnUpgrade=YES
    SkipCapture=YES
    SkipAdminPassword=YES
    SkipProductKey=YES
    
    SkipFinalSummary=YES
    
    SkipLocaleSelection=YES
    KeyboardLocale=en-US
    UserLocale=en-US
    UILanguage=en-US
    
    SkipTimeZone=YES
    TimeZone=020
    TimeZoneName=Central Standard Time
    
    SkipUserData=YES
    
    SkipDomainMembership=YES
    JoinDomain=domain.contoso.net
    EventService=http://WDS:9800

    @ Michael - Thank you so much for the script.  I created the script and put it in the folder that you said to put it in.  When I go to the Rules tab of my deoployment share, I wasn't 100% sure where to add the two lines.  I have attached below what my current CustomSettings.ini looks like.

    Hi

    I'm sorry I confused you. It is not under the General section as a wrote, it is the default section. Like this

    [Settings]
    Priority=Default
    Properties=MyCustomProperty

    [Default]
    UserExit=UserExit.vbs
    OSDComputername=#GetOfflineComputername()#

    DeployRoot=\\WDS\XP-DS
    OSInstall=YES
    SkipAppsOnUpgrade=YES
    SkipCapture=YES
    SkipAdminPassword=YES
    SkipProductKey=YES

    SkipFinalSummary=YES

    SkipLocaleSelection=YES
    KeyboardLocale=en-US
    UserLocale=en-US
    UILanguage=en-US

    SkipTimeZone=YES
    TimeZone=020
    TimeZoneName=Central Standard Time

    SkipUserData=YES

    SkipDomainMembership=YES
    JoinDomain=domain.contoso.net
    EventService=http://WDS:9800

    Thursday, May 10, 2012 2:39 PM
  • Thanks Michael.  That worked great for me.  I had one other question that is kinda off topic but didn't know if you would know anything about it.  I have 3 pieces of software that I needed to add to my image.  Is there a way to add that software without having to pull the image down to a machine, make the changes, and then push it back up to the server?
    Thursday, May 10, 2012 2:50 PM
  • Thanks Michael.  That worked great for me.  I had one other question that is kinda off topic but didn't know if you would know anything about it.  I have 3 pieces of software that I needed to add to my image.  Is there a way to add that software without having to pull the image down to a machine, make the changes, and then push it back up to the server?

    You could but that will be hard to do. Basically you need to mount the image. Copy the files, mount the registry and update what is needed for the application. And finally commit the changes. But wait... MDT can install applications for you so it will not be that hard anymore :)
    In MDT workbench, add your applications. In your task sequence go to State restore and add your applications somewhere between Recover from domain and Imaging.

    Thursday, May 10, 2012 3:31 PM
  • Cool.  Thank you very much.  Also, what do you use, if anything, to create answer files to MSI installers?
    Thursday, May 10, 2012 3:33 PM
  • Cool.  Thank you very much.  Also, what do you use, if anything, to create answer files to MSI installers?

    I use Insted it. (little better than Orca)
    Thursday, May 10, 2012 3:36 PM
  • Is there anyway to do this with active directory?

    When I use to use RIS, when I first imaged a PC it would ask me for a PC name during RIS setup. Once that was set it would go and pull down the image. If I was to Re-Image that PC, it would pull down the name from AD automatically and the computer name would be auto-populated with the original computer name. MDT seems to generate a new one regardless

    Thursday, July 26, 2012 10:33 AM
  • Is there anyway to do this with active directory?

    When I use to use RIS, when I first imaged a PC it would ask me for a PC name during RIS setup. Once that was set it would go and pull down the image. If I was to Re-Image that PC, it would pull down the name from AD automatically and the computer name would be auto-populated with the original computer name. MDT seems to generate a new one regardless

    For the computername you don't need active directory. The computername is stored in the registry at HKLM\ControlSet001\Services\Tcpip\Parameters\Hostname. It is possible to query active directory but that is not supported. However you need a few files in WinPE and a few tweaks in WinPE registry.

    A guide to the files you need are here http://www.deployvista.com/Blog/JohanArwidmark/tabid/78/EntryID/127/language/en-US/Default.aspx
    The registry tweak so that the HTA can query some domain controler is here http://social.technet.microsoft.com/Forums/en-US/mdt/thread/c1790e56-311b-4122-98fe-a21370c36213/#f0586c8f-00a3-45c9-a9cd-79b55872ed81

    And how to implement this in WinPE automatically http://social.technet.microsoft.com/Forums/en-us/mdt/thread/f1758b88-b679-42fb-aca7-65ee16e36ad5

    Thursday, July 26, 2012 9:20 PM
  • Hello Michael,

    I am using MDT 2012 and  I'm looking to name workstations based on machine type USTRWLxxxx for Laptops and USTRWDxxxx for Desktops, the xxxx represents a automatically generated number which is from 1-9999

    Sunday, April 14, 2013 1:35 AM
  • Hi Abdur,

    Have you got any update on this. Even me too having the similar requirement.

    Below is the blog where we can get Location+Machine type+serialORAsset tag number.

    We need to alter for sequence number.

    Let me know if you find any ans.

    regards

    Kriz

    Friday, June 21, 2013 9:07 AM
  • [Default]
    UserExit=UserExit.vbs
    OSDComputername=#GetOfflineComputername()#

    Hello Michael,

    With the ComputerName already existing in AD, I assume I won't be able to utilize LiteTouch's feature where it will Autojoin the PC to the Domain?  I assume I need to delete the Computer From AD prior to initiating the Refresh Task Sequence?

    Another Question I have, is, I currently use the following in my Customsettings.ini. 

    OSDComputername=XXX-nnn-#right("%SerialNumber%",7)#

    I utilize this method of pulling in the Serial Number (Dell Service Tag in this case) so that when I do a mass imaging of multi PC's to put 'on the shelf' for use later, the Computer name has the Serial number in it. 

    (PC is to be renamed later with XXX changed to the site name, nnn get changed to the room number, and Serial number is removed.)

    Is there a way to utilize my current method for computer name for NEW Computers, and your method for REFRESHED Computers?

    MININT-S13849 is of no use to me when I've 30 PC's on the Bench with no Monitor, Keyboard, Mouse connected to them, and I simply need to remote to one via VNC or RDP.  But if the PC name has the Dell Service Tag (or Serial number) in it, that process becomes a bit easier.

    UPDATE:

    Upon testing setting up and testing the use of UserExit.vbs in my Virtual Environment, I see that LiteTouch had no problem with the PC already existing in AD.  I rebooted the VM a few times, logged into the domain, and did not run into any issues.  I'll be testing this against 30 PC's in a Lab as soon as I get my Images replicated out to the 'Production' DeploymentShare.

    One thing I did notice was the ability to display the name of the PC using the _SMSTSOrgName variable in the CustomSettings.ini file has been lost.

    My original settings:

    OSDComputername=LAB-nnn-#right("%SerialNumber%",7)#

    were replaced with:

    UserExit=UserExit.vbs
    OSDComputername=#GetOfflineComputername()#

    and now %OSDComputername% in not producing the name of the Computer name as it did before:

    _SMSTSOrgName=Running %TaskSequenceID% On %OSDComputername%

    Is there another Variable I can use instead of %OSDComputername% ?

    Currently, I"m getting a '.' (Period) where the name should be.

    thank you,

    Stephen


    • Edited by StephenJN Tuesday, July 29, 2014 2:13 AM Update
    Tuesday, July 29, 2014 12:51 AM
  • Hi Stephen

    I'm on holiday and have no access to files at work. But could you try

    _SMSTSOrgName=Running %TaskSequenceID% On #GetOfflineComputername()#

    Wednesday, July 30, 2014 2:05 PM