Script to Prompt for System Name in SCCM OSD

When doing a baremetal image in SCCM OSD, the task sequences will generate a random name for the system. To define a specific name the system is to receive, use the following VBScript.  It will prompt the end-operator to input a name and then it will set the TS variable “OSDComputerName”. 

Add the script to the TS by adding a Run Command Line task after Partition Disk and before Apply Operating System.

promptsystemname

 

'==========================================================================
' NAME: PromptForSystemName.vbs
'
' AUTHOR: Nick Moseley 
' DATE  : 6/1/2009
'
' COMMENT: This script will detect if the current assigned value for the computer name 
' begins with MININT, indicating that this image is bare metal image.  It then prompts
' the end-user to enter a new computer name.
'
' VERSION : 1.1
' 1.0 (12/08/2008)- Intial script to check if the computer name begins with 
'  "minint", which indicates the system was booted with CD or PXE.
' 1.1 (06/01/2009)- Added check if the computer name equals "minwinpc", 
'  which indicates the system was booted with USB key
'==========================================================================
 
Dim sNewComputerName, oTaskSequence, sTSMachineName, bPromptName
Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")
' Get the name the computer is set to receive and truncate to first 6 letters
sTSMachineName = lcase(oTaskSequence("_SMSTSMachineName"))
If left(sTSMachineName,6) = "minint" Then
 bPromptName = True
ElseIf sTSMachineName = "minwinpc" Then
 bPromptName = True
Else
 bPromptName = False
End If
' Note: The wscript.echo commands are logged in SMSTS.log for troubleshooting.  They are not displayed to the end user.
If bPromptName = True Then
 wscript.echo "Detected that the computer name is scheduled to receive a random value.  Prompting user to input a standard name."
 sNewComputerName = InputBox ("Please enter a standard computer name to continue.", "Computer Name", , 30,30)
 oTaskSequence("OSDComputerName") = UCase(sNewComputerName)
 wscript.echo "Set Task Sequence variable OSDComputerName to: " & sNewComputerName
Else
 wscript.echo "Computer set to receive a standard name, continuing as is."
End If

 

,

  1. #1 by Lux on August 18, 2009 - 12:26 am

    Hi Nick, I followed your instruction and I am not getting the prompt to enter computer name.

    I will appriciate if you can let me know what I am doing wrong.

    Many thanks
    Lux

    • #2 by Nicolas Moseley on August 18, 2009 - 4:26 am

      Did you get the full code from the link “Full PromptForSystemName.vbs Code Here”? Also, did you place the code between Partition disk and Apply OS?

      • #3 by Lux on September 14, 2009 - 11:53 pm

        Hi Nick, I am extremely sorry; I didn’t get a alert of you reply to my comment. Yes I did copy the code from this site and followed your instruction to every word. Still I had no luck getting the prompt on the screen.

        In the end I have created an Access database and VB script to generate PC name based on the PC model and rename without user intervenstion.

        Many thanks for your reply and again sorry for not replying sooner.
        Lux

  2. #4 by Craig on September 30, 2009 - 12:18 pm

    This helped us out a ton!!! Thanks very much for posting this solution!

  3. #5 by Jason O on January 13, 2010 - 3:24 pm

    What is in your Task Sequence Script Package?

    Thanks,
    Jason

    • #6 by Nicolas Moseley on January 13, 2010 - 4:37 pm

      I use the “Run Command Line” task. If you click on the picture in the post, it’ll be easier to see.

  4. #7 by Raghavendra on April 19, 2011 - 6:34 am

    Hi,

    Why is Task Sequnce Script package is required?

    • #8 by Nicolas Moseley on April 19, 2011 - 8:41 am

      You don’t have to use a package, it’s just what I used for this example. You could cetainly just use the Run Command Line to execute the script from a server location. Or heck, you could even embed the script inside your boot.wim and then have it execute from there! There’s many ways to approach this….

  5. #9 by Matz on April 27, 2011 - 6:42 am

    Hi!

    I’m getting “Error: Invalid Character” when running this script.

    Cheers, Matz

    • #10 by Nicolas Moseley on April 27, 2011 - 7:43 am

      It’s probably a copy/paste issue, maybe caused by an invalid quotation mark. Start there. If you still can’t get it to work, I’ll try to email you a text file of the code.

  6. #11 by Karl on May 4, 2011 - 2:53 am

    Back on XP this scripts worked but now we are on Win7, it even doesn’t comes up.
    Is it compatible with Win7?

  7. #12 by Alex on May 14, 2011 - 5:27 am

    Thanks for the hard work and the tutorial Nick, helped me with my corporate image no end. Why the hell don’t MS have a task for naming the PC prior to joining the domain? SCCM makes manty things harder than they need to be. Still, problem solved thanks to you.
    Cheers Nick.

  8. #13 by Alex on May 16, 2011 - 8:14 am

    There is an easier way than scripting! Have a look at:
    http://sccmguy.com/2011/02/26/how-to-specify-the-computer-name-during-a-configmgr-os-deployment/

    Takes 5 seconds to set up.

  9. #14 by Mike on June 3, 2011 - 8:28 am

    This worked perfectly for us. Thanks!

  10. #16 by Edward on November 7, 2011 - 1:46 pm

    Nick,

    Thanks for your script; I’ve used it while testing SCCM2012 and it’s saved me lots of time.

    I made a slight modification to your script, since I have one requirement for my environment – I have to make sure that all computer names are the same length and case format.

    Basically, I need to make sure that all my computer names are no longer than 5 characters and have to meet a criteria, so I I’m checking the user’s input against a regular expression, and if all goes as expected, the application continues.

    If you’re interested, I can send you the modified script.

  11. #18 by Edward on November 7, 2011 - 2:11 pm

    Nick,

    That’s great. I’ll check it and see if it can help me in any way. I’ve been testing SCCM 2012 in a lab environment, so this is my first exposure to SCCM.

    Based on your script, I have another slight modification planned. I’m going to allow the user to type a ‘Description’, since all our computer objects in AD have a description – which is mainly the user’s name.

  12. #20 by Tony on November 7, 2011 - 6:35 pm

    Hi Nick, I followed your instruction and I am getting PromptForSystemName task sequence error after the disk partition step.

    I will appriciate if you can let me know what I am doing wrong.

    Thanks

    Regards,
    Tony

    • #21 by Nicolas Moseley on November 8, 2011 - 8:42 am

      Tony, what is the task sequence error code? Did you place the script in a package?

      • #22 by Tony on November 8, 2011 - 5:30 pm

        Hi Nick,

        The TS error code i get is (0×00000001) during run command line action. I did not place the script in a package as you said don’t have to use a package, it’s just used for example. What i did is just put the ( cscript.exe “%deployroot%\scripts\PromptForSystemName.vbs” ) inside the command line box.

        Please advise.

        Thanks :)
        Tony

      • #23 by Nicolas Moseley on November 9, 2011 - 7:22 am

        My hunch is that it cannot locate the script file or the command line that you’re using is inaccurate. For my task sequences, I keep a package that contains a bunch of different scripts. One package for build/capture scripts and one for deployment scripts. It makes for easier long term management. So try stuffing the script into a package. Look at the image on the post to see what I’ve done…

  13. #24 by Richard on November 14, 2011 - 9:25 am

    When you build the package, just use the full name for the program. The path is already specified by the package ID. Also there is no need to add cscript.exe first; the system knows to use vbs with cscript, unless your image is set to use wscript as the default. The above TS screenshot is correct. Also ensure you update your distribution points, as you will get 0×00000001 errors

    The script works pretty good, but i wanted more for my environment. I modified it to support naming a computer based on a model abbrevation with a serial number and detect if it s VDI machine (Vmware serial is a bit long). If you’d like the modifed version, just ask.

  14. #25 by Stranger on December 31, 2011 - 9:06 pm

    Just put the %OSDComputerName% as varailbe in the collection you are advertsing to, no scripting required

    • #26 by Nicolas Moseley on January 3, 2012 - 8:10 am

      It all depends upon your approach. If you want to always add/modify the collection variable(s), then sure go ahead and do it that way. However, I don’t want my technicians bugging and admin/engineer every time they image a computer. Therefore a script is better IMHO :-)

  15. #27 by Archee on January 27, 2012 - 8:58 am

    Initially the script did not work for me. So I looked at the variables values during the OSD phase. What turned out the machine was not given the name containing ‘minint’ nor ‘minwinpc’. Instead it got assigned the name that I specified whlie importing this particular machine manually into SCCM. So the conclusion is:
    - watch out how you import the machine into SCCM and what PC name it gets during WinPE – it is not always ‘minint’
    - if you want the prompt apear every time, then the simplest thing to do is edit the vbs and change bPromptName = False to bPromptName = True (or comment relevant lines)

    • #28 by Nicolas Moseley on January 27, 2012 - 9:02 am

      Yep, you bring up good a good point about the imported computer. Personally, importing computer records into SCCM is an administrative PITA. Unknown computer support with R2 or later is the way to go, which is what this script is intended for.

      Also, this script is VERY basic. Better still is something like creating a custom options chooser HTA http://t3chn1ck.wordpress.com/2011/09/22/osd-options-chooser-v2/

      • #29 by Archee on January 27, 2012 - 9:12 am

        Yes it is basic but sufficient for many cases. Thanks for your effort.

      • #30 by Nicolas Moseley on January 27, 2012 - 9:15 am

        Glad to help :-) Thanks again for the feedback….

  16. #31 by peichen on April 26, 2012 - 8:10 pm

    thanks for sharing! :)
    btw, can I apply this script for OSD USB deployment media?

    • #32 by Nicolas Moseley on April 27, 2012 - 1:27 am

      Should be able to do use it for USB, but let me know if it doesn’t work….

  1. [SCCM 2007] SCCM - Linking collections to Active Directory OU's
  2. SCCM Task Sequence – Ask for Computer Name « windowsmasher

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 39 other followers