Script to Prompt for System Name in SCCM OSD

Posted on Updated on

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
Advertisement

67 thoughts on “Script to Prompt for System Name in SCCM OSD

    Lux said:
    August 18, 2009 at 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

      Nicolas Moseley responded:
      August 18, 2009 at 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?

        Lux said:
        September 14, 2009 at 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

    Craig said:
    September 30, 2009 at 12:18 pm

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

    Jason O said:
    January 13, 2010 at 3:24 pm

    What is in your Task Sequence Script Package?

    Thanks,
    Jason

      Nicolas Moseley responded:
      January 13, 2010 at 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.

    Raghavendra said:
    April 19, 2011 at 6:34 am

    Hi,

    Why is Task Sequnce Script package is required?

      Nicolas Moseley responded:
      April 19, 2011 at 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….

    Matz said:
    April 27, 2011 at 6:42 am

    Hi!

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

    Cheers, Matz

      Nicolas Moseley responded:
      April 27, 2011 at 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.

    Karl said:
    May 4, 2011 at 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?

    Alex said:
    May 14, 2011 at 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.

    Alex said:
    May 16, 2011 at 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.

    Mike said:
    June 3, 2011 at 8:28 am

    This worked perfectly for us. Thanks!

    Edward said:
    November 7, 2011 at 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.

    Edward said:
    November 7, 2011 at 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.

      Nicolas Moseley responded:
      November 7, 2011 at 2:13 pm

      Good call on adding a field for the description!

    Tony said:
    November 7, 2011 at 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

      Nicolas Moseley responded:
      November 8, 2011 at 8:42 am

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

        Tony said:
        November 8, 2011 at 5:30 pm

        Hi Nick,

        The TS error code i get is (0x00000001) 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

        Nicolas Moseley responded:
        November 9, 2011 at 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…

    Richard said:
    November 14, 2011 at 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.

    […] […]

    Stranger said:
    December 31, 2011 at 9:06 pm

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

      Nicolas Moseley responded:
      January 3, 2012 at 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 :-)

    Archee said:
    January 27, 2012 at 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)

      Nicolas Moseley responded:
      January 27, 2012 at 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 https://t3chn1ck.wordpress.com/2011/09/22/osd-options-chooser-v2/

        Archee said:
        January 27, 2012 at 9:12 am

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

        Nicolas Moseley responded:
        January 27, 2012 at 9:15 am

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

    […] Scripting First, save the following source as “PromptForSystemName.vbs”. It’s modified version of the script from t3chn1ck’s wordpress blog post found here: PromptForSystemName vbScript. […]

    peichen said:
    April 26, 2012 at 8:10 pm

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

      Nicolas Moseley responded:
      April 27, 2012 at 1:27 am

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

    […] dieser Webseite t3chn1ck.wordpress.com wird ein fertiges VBS Script angeboten, welches für eure Task Sequence genutzt werden kann. Der […]

    dani3l92 said:
    July 19, 2012 at 12:06 pm

    Hi Nick,

    i used your code for a blog entry and also put a link to your blog into it. If you dont like it, tell me then i will delete the code and only left the link in the entry.

    Greeds from Germany.
    dani3l

    PS: http://dani3l92.wordpress.com/2012/07/19/reinstall-eines-computers-mit-alten-namen/

      N. Moseley responded:
      July 19, 2012 at 12:45 pm

      No worries – I’m glad that it takes care of what you need!

    Kyle Reyes said:
    August 1, 2012 at 4:40 pm

    Howdy Nick!
    Well it would appear that this script is exactly what I am looking for, but I am not having any luck with getting this configured correctly for some reason. I am trying this on SCCM 2012 RTM and I have created a package that is solely the script and ensured it has been deployed to both my test collection and the Unknown Computers collection. I have configured the Task Sequence as you show above but when I attempt to run this I receive an error code of 0x80070002.

    I am fairly certain this has to do with regards to how I am creating the package, any suggestions on how to correctly create this package?

    -I did not choose the package contains source files
    -I did create a program for a client computer
    -I used the PromptForSystem.vbs for both the name of the package & program
    -For the command line of the program I used cscript.exe
    -I verified deployed to all distribution points
    -I verified all settings match what you for the Task Sequence image above

    I am quite lost on what I am not doing correctly as I’ve created packages/programs before without issues.

    Any advice would be greatly appreciated.

      N. Moseley responded:
      August 1, 2012 at 8:15 pm

      Kyle, any time you are troubleshooting task sequences, always reference the SMSTS.log file to help in troubleshooting. Error code corresponds 0x8007002 is “Failed to run the last action: Prompt for System Name. Execution of task sequence failed. The system cannot find the file specified.”

      So there’s the clue, the file cannot be found. If you do have the package on the local DP, then my guess is that maybe you have not set up the network access account in order for WinPE to access the DP share. For more info, see http://technet.microsoft.com/en-us/library/ded46139-8692-4dd6-bd80-64f7b4045924#BKMK_NetworkAccessAccount

        Kyle Reyes said:
        August 1, 2012 at 9:10 pm

        The Network Access Account has been set, and is actually used/working for all client deployments, software deployments, etc. without any issues at all.

        I tried to pull the SMSTS log but it was actually stating it didn’t exists which I found to be really odd as I’ve pulled it many other times in the past. One other time I was told “access denied” to the log, which was also strange. As soon as I removed the PromptForSystemName.vbs portion of the task sequence everything worked correctly again.

        Any other suggestions? Thank you for your help!

        N. Moseley responded:
        August 2, 2012 at 9:04 am

        You are certainly right, that is very strange. It works for me just fine in my CM12 lab. If you want to confirm that the script itself is working, then open a command prompt in the task sequence, map a drive letter to the server share, then run the script. The trick to running the script is that the task sequence needs to be actively running, otherwise it cannot create the VBScript object for the task sequence environment.

        An alternative to this prompting script is that you could create the task sequence variable on the collection itself, which can then be edited to set the value.

        Kyle Reyes said:
        August 2, 2012 at 9:24 am

        I did try the Task Sequence Variable option on the collection itself, and was able to get the prompt to input the name. Unfortunately it would never actually assign the value given as a computer name. Though it would assign the CM12 splash screen as the wallpaper, which was also interesting. Again, once I removed that part of the Task Sequence, all was back to normal.

        What steps are you taking to create the package? For some reason I have a feeling that is where my problem lies. Are you creating a program with the package? Using Source Files? Using anything for Command Line? I have created a share on the server specifically for Scripts at this point, I’m just extremely lost at this point…

        Grr… Sometimes I really hate CM….

        N. Moseley responded:
        August 2, 2012 at 9:31 am

        I create a standard package and add it to the local DP of course. I use the Run Command Line option. See the image on the post to see what I mean. Again, remember that that error code should indicate that it cannot locate the file. That should really be the issue that is occuring….

        Kyle Reyes said:
        August 2, 2012 at 11:03 am

        Well, I am not sure what it was but I got it working!

        I redid the package entirely, ensured the share permissions were correct, redistributed everything to my DP’s, and redid the entire task sequence.

        I just ran an bare metal image and was prompted for the name, verified after imaging the name is showing correctly on the machine as well as is populated in the CM12 console!

        Thank you for the script and the advice on everything, I TRULY appreciate it!!

        N. Moseley responded:
        August 2, 2012 at 11:14 am

        Sometimes that’s just the way it goes. We have shake our heads in disbelief and just say, “whatever – at least it’s working!”. LOL

        Kyle Reyes said:
        August 2, 2012 at 11:16 am

        Exactly… Oh how I hate to love CM some days…

        Thanks again, I’ll be sure to frequent your blog, you have some great information!

        N. Moseley responded:
        August 2, 2012 at 11:17 am

        Awesome, thanks for the compliment. If you like as well, at the top left corner of the blog you can sign up your email and it’ll be delivered to you automagically.

    ITGURU1982 said:
    September 20, 2012 at 1:54 pm
      N. Moseley responded:
      September 20, 2012 at 2:08 pm

      There are indeed a variety of ways to set the computer name. Thanks for contributing!

    ITGURU1982 said:
    September 20, 2012 at 2:11 pm

    No problem, I’ve spent so much time looking for different/best ways of doing it that when I finally found a simple way that (finally..) seemed to work with Dell Asset Tags, I thought it best to document it for others.

    […] after the “Gather” step, and it will prompt for a name input. You can see this method here. This is very simple and reliable, but there’s actually an easier […]

    David said:
    August 7, 2013 at 4:15 pm

    I run it just like you have it here, but it still gives me a 0x00000001 error and then crashes out….Any other ideas?

    Jurgen De Vlieger said:
    October 31, 2013 at 3:04 am

    Hi Nick,
    I Just implemented your script and it seems to work, thank you for the nice work. I just have one problem, the keyboard is set to US, do you have any idea how I could set this to Belgian Dutch? I have an unattended.xml which is being used to apply the OS and that changes the keyboard , but since you specify to run your script before applying the OS this seems to be nog solution…

    Ray said:
    December 10, 2013 at 10:50 pm

    Hello Nick, I just came across your script. Do you have any scripts that will do the above except insert the serial number if the computer name meets the query of minint instead of prompting for user input? I am trying to piece something together now but I am no programmer. So the script would need to query wmi for the serial number and insert into osdcomputername variable if the computer does not already have a name. Make sense?

    Thanks, Ray

      N. Moseley responded:
      December 11, 2013 at 5:28 pm

      Ray, there are plenty of other examples on the web for this, so you wouldn’t need to use my script necessarily.

      http://myitforum.com/myitforumwp/2011/11/02/vbscript-to-name-computers-during-osd/

        Ray said:
        December 11, 2013 at 5:32 pm

        Nick, thank you for taking the time to answer my post. I actually saw that script, however it requires a manual input for the name. What I would like to be able to do is query the name like your script does and if it finds those names then use the serial number instead without a techs input. Your script is the closest I have been able to find that does just that.

        Thanks again for your time.

    Peteros said:
    February 20, 2014 at 6:13 am

    How do you accomplish the package process? Few. Steps for a noob will be nice
    Thank you

      N. Moseley responded:
      February 20, 2014 at 7:53 am

      Creating a package is entry level operations for ConfigMgr. If you’re unfamiliar with this process, my advise is that you first take a course or receive formal training. As with any systems management tool, ConfigMgr is powerful system with the power to cause a lot of damage if not used incorrectly.

    MUTHU KUMAR said:
    March 9, 2016 at 7:56 pm

    Hi Nick, the script is awesome, it works fine when I dont use unattend.xml file as part of “Apply operating system” step in the TS, when I do use unattend.xml then I still get the random computer name. In my unattend.xml, I have *

    Any idea how to use your script as well as the unattend.xml as this has other settings like IE home page, language and so on.

      N. Moseley responded:
      March 9, 2016 at 8:13 pm

      Muthu, you will need to remove the reference within your unattend.xml file.

    Dave said:
    January 18, 2017 at 12:33 pm

    Is there a way to not let then user just click OK on the Computer Name box? Just clicking OK sets the PC name to the default MININT-xxxxxxx. Thanks

      N. Moseley responded:
      January 18, 2017 at 4:50 pm
        Dave said:
        January 19, 2017 at 7:21 am

        Nick that link is a lot more than I need but I modified the code to this…. Is this correct? I know the ; makes it a comment…..

        ;Dim oTaskSequence, sTSMachineName, bPromptName
        ;Set oTaskSequence = CreateObject (“Microsoft.SMS.TSEnvironment”)
        ;
        ; sTSMachineName = ucase(oTaskSequence(“_SMSTSMachineName”))
        ;
        ; If left(sTSMachineName,6) = “MININT” Then
        ; bPromptName = True
        ; ElseIf sTSMachineName = “MINWINPC” Then
        ; bPromptName = True
        ; Else
        ; bPromptName = False
        ; End If
        ;
        ; If bPromptName Then
        ; ComputerName.value = “”
        ; Else
        ; ComputerName.value = sTSMachineName
        ; End If
        ;End Sub
        ;
        ;Sub FinishClickTasks
        ; ‘====================================
        ; ‘ Get/set computer name
        ; ‘====================================
        ; Dim sComputerName
        ; sComputerName = UCase(ComputerName.Value)
        ;
        ; ‘ Check that a PC name was entered
        ; Do
        ; If sComputerName = “” Then
        ; MsgBox “Error: Computer name cannot be left empty!”, vbCritical, “Error”
        ; sComputerName = InputBox (“Please enter a computer name to continue”, “”, , 30,30)
        ; End If
        ; Loop Until sComputerName “”
        ;
        ; oTaskSequence (“OSDComputerName”) = sComputerName
        ;
        ; wscript.echo “Set Task Sequence variable OSDComputerName to: ” & sComputerName
        ;Else
        ; wscript.echo “Computer set to receive a standard name, continuing as is.”
        ;End If

        N. Moseley responded:
        January 19, 2017 at 12:01 pm

        At a glance, that looks correct.

    Dave said:
    January 20, 2017 at 3:13 pm

    This worked the above did not

    ;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 computer name to continue.”, “Computer Name”, , 30,30)
    ;
    ;
    ; ‘ Check that a PC name was entered
    ; Do
    ; If sNewComputerName = “” Then
    ; MsgBox “Error: Computer name cannot be left empty!”, vbCritical, “Error”
    ; sNewComputerName = InputBox (“Please enter a computer name to continue”, “Computer Name”, , 30,30)
    ; End If
    ; Loop Until sNewComputerName “”
    ;
    ; 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

    Thank Nick

    […] after the “Gather” step, and it will prompt for a name input. You can see this method here. This is very simple and reliable, but there’s actually an easier […]

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