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

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

Add yours

  1. 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

      1. 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

    1. 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….

    1. 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.

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

  3. 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.

  4. 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.

  5. 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.

  6. 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

      1. 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

      2. 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…

  7. 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.

    1. 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 :-)

  8. 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)

  9. 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.

    1. 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

      1. 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!

      2. 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.

      3. 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….

      4. 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….

      5. 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!!

      6. 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

      7. 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!

      8. 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.

  10. 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.

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

  12. 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…

  13. 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

      1. 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.

    1. 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.

  14. 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.

  15. 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

      1. 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

  16. 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

Leave a comment

Blog at WordPress.com.

Up ↑