Video Screencast Help

Sysprep computer name

Created: 27 Jan 2014 | 18 comments

New to 7.5 and I need to be able to configure the computer name in the sysprep file. We have a large number of new computers earch year that aren't in the deployment database. I've read some stuff online but haven't found an exact solution to this. So how can I change the computer name in the sysprep file after the image is deployed?

Operating Systems:

Comments 18 CommentsJump to latest comment

SK's picture

The sysprep file can be populated via tokens, which means that the computer name thzat you want needs to be in the database before the imageing process, so your best bet will probably be to use the predefined computers list.

If you dont want the machines to be in the database until after the imaging process, then you will need to use a post configuration task to change the machine names once they have been imaged manually; however, if you are imaging large numbers of machines each time, then to use tokens with that task (I dont know if you can or not) would mean that a machine name list would need to exist in the database anyway.

Connect Etiquette: "Mark as Solution" those posts which resolve your problem, and give a thumbs up to useful comments, articles and downloads.

Gstrouth's picture

Yeah I'd really like to set the name correctly the first time without pre-loading the computers. We name the computers the serial number of the computer, I've seen different posts about users using a script to pull this and then inserting it into the sysprep file. Any idea on how to do that?

BugTastic's picture

Is this any good ?

I use this script after ghost has run and before reboot to production - it prompts for a hostname and updates the unnatend file with it. 

*update the unattend file to have _COMPUTERNAME_REPLACE_

 

Option Explicit
 Dim answer, computerName, unattendFile, WshShell, fso, unattendFileObject, strContents

unattendFile = "D:\windows\Panther\unattend.xml"
 
 Set WshShell = WScript.CreateObject("WScript.Shell")
 Set fso = CreateObject("Scripting.FileSystemObject")
 
 Do While answer <> vbYes
    computerName = InputBox("Enter the desired Computer Name:", "Computer Name")
    answer = MsgBox("Is this correct?" & vbCrLf & "Computer Name: " & computerName, vbYesNo, "Verify Name")
 Loop
 
 If fso.FileExists(unattendFile) = False Then
    wscript.echo "ERROR: Could not find the unattend file"
 Else
    'Read the unattend file in and replace apprpriate variables
    Set unattendFileObject = fso.OpenTextFile(unattendFile, 1)
    strContents = unattendFileObject.ReadAll
    strContents = Replace(strContents, "_COMPUTERNAME_REPLACE_", computerName)
    unattendFileObject.Close
 
    'Write the updated contents back to the unattend file
    Set unattendFileObject = fso.OpenTextFile(unattendFile, 2)
    unattendFileObject.Write(strContents)
    unattendFileObject.Close
 End If

Gstrouth's picture

I can't enter the names in manually, that would take forever for the number we do. I wonder if you could query the smbios in this script instead?

Gstrouth's picture
If I modified your script like this do you think it would work?
 
 
Option Explicit
Dim answer, computerName, unattendFile, WshShell, fso, unattendFileObject, strContents, strComputer, objWMIService, colSMBIOS, objSMBIOS
strComputer = "." 
Set objWMIService = GetObject("winmgmts:" _ 
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
Set colSMBIOS = objWMIService.ExecQuery _ 
    ("Select * from Win32_SystemEnclosure")
 
For Each objSMBIOS in colSMBIOS    
 
unattendFile = "C:\windows\Panther\unattend.xml"
  
  Set WshShell = WScript.CreateObject("WScript.Shell")
  Set fso = CreateObject("Scripting.FileSystemObject")
  
  If fso.FileExists(unattendFile) = False Then
     wscript.echo "ERROR: Could not find the unattend file"
  Else
     'Read the unattend file in and replace apprpriate variables
     Set unattendFileObject = fso.OpenTextFile(unattendFile, 1)
     strContents = unattendFileObject.ReadAll
     strContents = Replace(strContents, "_COMPUTERNAME_REPLACE_", objSMBIOS.SerialNumber)
     unattendFileObject.Close
  
     'Write the updated contents back to the unattend file
     Set unattendFileObject = fso.OpenTextFile(unattendFile, 2)
     unattendFileObject.Write(strContents)
     unattendFileObject.Close
  End If
 
   
Next 
 
BugTastic's picture

Can you not Apply system configuration in a job which renames it to the serial number using a token ?

SK's picture

If that was possible it would be a good method to use.

Connect Etiquette: "Mark as Solution" those posts which resolve your problem, and give a thumbs up to useful comments, articles and downloads.

BugTastic's picture

According to the Deployment Solution User Guide it is.

"For computer names, you can use tokens. For example, %CustomerToken%, %SERIALNUMBER%."

 

Gstrouth's picture

That is just if the computers are in the database though

BugTastic's picture

If the build job completes and a inventory has been sent then surely it would work then ?

 

BugTastic's picture

so I would have the job like this

deploy image
reboot
send inentory (if even needed)
Apply system configuration job with serial number token.
 

Would that not work!

 

Gstrouth's picture

But not all computers get the agent so inventory wouldn't be done. Would your script that I updated not work?

BugTastic's picture

Sorry - I'm not a scripter - I got the script from another site.

Gstrouth's picture



Ok well I know it works but not sure how it will work in the process. So would the job just have the deploy job and then the next step is this script?

JannasTo's picture

Yep,

Deploy Image
Run Script task
Reboot to production

That should do it.

 

Gstrouth's picture

So will this script work or not and what does the job need to look like to make this work?

JannasTo's picture

the utility that renames a PC to serial number is WSNAME.exe - google it.

this should save you scripting. stick it in a copy job then run.

 

SK's picture

Nice.

Connect Etiquette: "Mark as Solution" those posts which resolve your problem, and give a thumbs up to useful comments, articles and downloads.