Rename computername during SCCM Tasksequence
At one of my customers I was responsible for deploying computers using SCCM 2007 R2.
The customer asked me to add computers to SCCM using a continuous number, but during the deployment the computers must be renamed to identify if it’s a laptop or a desktop.
e.g. for a laptop: LT000001
To fix this issue and rename the computers I created a VBScript, called Computername.vbs
Computername.vbs
First I’ve set the variables for the script, where I use the TaskSequence variable to receive the computername from the SCCM-database.
Set oShell = CreateObject("Wscript.Shell")
Set oTSEnv = CreateObject("Microsoft.SMS.TSEnvironment")
strMachineName = lcase(oTSENV("_SMSTSMachineName"))
strComputer = "."
Then I added an option to set the continuous number if the deployment was executed by Task Sequence Media (e.g. USB-stick).
If left(strMachineName,6) = "minint" Then strMachineName = inputbox("Please enter your computernumber (Last 6 digits of the serial, or the 6 digits of your CI-Code)","Computer Name",,30,30)
The customer used Fujitsu hardware and for laptops they only used “Lifebook”-computers. So I used the following check to identify if the hardware was a laptop or a desktop.
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Computersystem")
For Each Item In colItems
strModel = UCase(item.model)
If left(strModel,8) = "LIFEBOOK" then
strType = "LT"
Else
strType = "PC"
End If
Next
Now the renaming can begin, this is the easy part. 🙂
oTSEnv("OSDComputerName") = UCase(strType & strMachineName)
Of course you can add more conditions to the script, but the most important part of the renaming is when and how you run the script.
To run the script I added a Command Line-job where I selected the package-name and in the Command Line-box I added the name of the script:
Then I made sure this script runs BEFORE you apply the Operating System:
That’s it! With these settings you can rename your computer during deployment.
I hope this article will help you in your SCCM environment! If you have any additional comment, please let me know!
4 comments
Skip to comment form
From this script the user will be prompted to enter the computer name?
IS there a way to script to step?
Author
Hi Mike,
The script uses the computername you’ve entered in SCCM, BUT if you use a “Task Sequence Media”, like a prepared USB stick, then the computername will start with “MiniNt”. In my script the computername is checked and when it starts with “MiniNt”, then you will get a prompt to enter the computername. I use it, because the only reason a “Task Sequence Media” is used in my current environment is when a admin or engineer is working with the computer. Real users will never use a “Task Sequence Media” in my current environment.
I hope this answers your question.
Kind Regards,
Ruben Koene
Mike,
This is just what I am looking for but I am having issues with it, I keep getting a scrip error at “line 1 charecter 27”
Can you help?
Kind Regards
Kevin
Author
Hi Kevin,
I guess you copied it including layout. Replace all the “ with default notepad “. That will do the trick.
regards, Ruben