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
About these ads

,

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

  17. #33 by dani3l92 on July 19, 2012 - 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/

    • #34 by N. Moseley on July 19, 2012 - 12:45 pm

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

  18. #35 by Kyle Reyes on August 1, 2012 - 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 0×80070002.

    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.

    • #36 by N. Moseley on August 1, 2012 - 8:15 pm

      Kyle, any time you are troubleshooting task sequences, always reference the SMSTS.log file to help in troubleshooting. Error code corresponds 0×8007002 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

      • #37 by Kyle Reyes on August 1, 2012 - 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!

      • #38 by N. Moseley on August 2, 2012 - 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.

      • #39 by Kyle Reyes on August 2, 2012 - 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….

      • #40 by N. Moseley on August 2, 2012 - 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….

      • #41 by Kyle Reyes on August 2, 2012 - 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!!

      • #42 by N. Moseley on August 2, 2012 - 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

      • #43 by Kyle Reyes on August 2, 2012 - 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!

      • #44 by N. Moseley on August 2, 2012 - 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.

    • #46 by N. Moseley on September 20, 2012 - 2:08 pm

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

  19. #47 by ITGURU1982 on September 20, 2012 - 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.

  1. [SCCM 2007] SCCM - Linking collections to Active Directory OU's
  2. SCCM Task Sequence – Ask for Computer Name « windowsmasher
  3. Reinstall eines Computers mit alten Namen « dani3l92
  4. Script to Rename Computer During OSD « t3chn1ck
  5. SCCM Help! OSD Deployments to unknown computers

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 59 other followers

%d bloggers like this: