Instead of automating the way a new computer is being named during OSD with ConfigMgr 2012 SP1, you might want to be prompted instead and have to enter the name manually. There are numerous ways of doing this and most of them are doing it with a VB script. Since WinPE 4.0 we now have support for running PowerShell scripts. And since my skills in VB isn’t that great, I’m turning to PowerShell and Windows Forms in order to create a prompt asking me to enter the computer name.

The script

Save this script as OSDComputerNamePrompt.ps1 and store it in your Content Library location. In my lab environment the path is \\CM01\ContentLibrary$\OSD\Scripts\OSDComputerName.

As for naming your computers correctly, I’ve added some error handling in the script so that it accepts maximum 15 character. It will also remove any invalid characters that are not supported for a NetBIOS name.

Dave Green has created a modified version of this script, that allows you to hit Enter instead of clicking on the OK button. His script can be found here, thanks Dave for contributing!

function Load-Form {
    $Form.Controls.Add($TBComputerName)
    $Form.Controls.Add($GBComputerName)
    $Form.Controls.Add($ButtonOK)
    $Form.Add_Shown({$Form.Activate()})
    [void] $Form.ShowDialog()
}

function Set-OSDComputerName {
    $ErrorProvider.Clear()
    if ($TBComputerName.Text.Length -eq 0) {
        $ErrorProvider.SetError($GBComputerName, "Please enter a computer name")
    }
    else {
        if ($TBComputerName.Text.Length -gt 15) {
            $ErrorProvider.SetError($GBComputerName, "Computer name cannot be more than 15 characters")
        }
        else {
            $OSDComputerName = $TBComputerName.Text.Replace("[","").Replace("]","").Replace(":","").Replace(";","").Replace("|","").Replace("=","").Replace("+","").Replace("*","").Replace("?","").Replace("<","").Replace(">","").Replace("/","").Replace("\","").Replace(",","")
            $TSEnv = New-Object -COMObject Microsoft.SMS.TSEnvironment 
            $TSEnv.Value("OSDComputerName") = "$($OSDComputerName)"
            $Form.Close()
        }
    }
}

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$Global:ErrorProvider = New-Object System.Windows.Forms.ErrorProvider

$Form = New-Object System.Windows.Forms.Form    
$Form.Size = New-Object System.Drawing.Size(285,140)  
$Form.MinimumSize = New-Object System.Drawing.Size(285,140)
$Form.MaximumSize = New-Object System.Drawing.Size(285,140)
$Form.StartPosition = "CenterScreen"
$Form.SizeGripStyle = "Hide"
$Form.Text = "Enter Computer Name"
$Form.ControlBox = $false
$Form.TopMost = $true

$TBComputerName = New-Object System.Windows.Forms.TextBox
$TBComputerName.Location = New-Object System.Drawing.Size(25,30) 
$TBComputerName.Size = New-Object System.Drawing.Size(215,50)
$TBComputerName.TabIndex = "1"

$GBComputerName = New-Object System.Windows.Forms.GroupBox
$GBComputerName.Location = New-Object System.Drawing.Size(20,10) 
$GBComputerName.Size = New-Object System.Drawing.Size(225,50) 
$GBComputerName.Text = "Computer name:" 

$ButtonOK = New-Object System.Windows.Forms.Button 
$ButtonOK.Location = New-Object System.Drawing.Size(195,70) 
$ButtonOK.Size = New-Object System.Drawing.Size(50,20) 
$ButtonOK.Text = "OK"
$ButtonOK.TabIndex = "2"
$ButtonOK.Add_Click({Set-OSDComputerName})

Load-Form

Obtain serviceUI.exe from MDT 2012 and create a package

In order for the PowerShell script to be visible during a Task Sequence, we need to launch it with the help of a file called serviceUI.exe. That binary is available with MDT 2012 (you’d need to install MDT first). The file is located in these locations, depending on the architecture:

C:\Program Files\Microsoft Deployment Toolkit\Templates\Distribution\Tools\x64
C:\Program Files\Microsoft Deployment Toolkit\Templates\Distribution\Tools\x86

Depending on your boot image architecture, be sure to grab the correct version of serviceUI.exe (thanks to Donald for pointing out that an x64 boot image only works with the x64 version of serviceUI.exe). Copy the serviceUI.exe to the same folder you stored the Set-OSDComputerNamePrompt.ps1 file (in my case \\CM01\ContentLibrary$\OSD\Scripts\OSDComputerName).

52_1

Create a package in ConfigMgr 2012 SP1 and call it OSDComputerName (or something else). The package does not need to have any program, but specify the content source folder where you stored serviceUI.exe and Set-OSDComputerNamePrompt.ps1. Remember to distribute your package.

Update your boot image to support PowerShell

If you havn’t already updated your boot images with PowerShell support, follow these instructions.

1. Right-click on your boot image and select Properties.
2. Select the Optional Components tab.
3. Click on the yellow star and select the following components:

  • Microsoft .NET (WinPE-NetFx4)
  • Windows PowerShell (WinPE-PowerShell3)

Note! In ConfigMgr 2012 R2 the names of the optional components differ a bit. Add the following:

  • Microsoft .NET (WinPE-NetFx)
  • Windows PowerShell (WinPE-PowerShell)

4. Click OK and then OK again. Let the wizard update your DP’s.

Implement the script in a Task Sequence

1. Edit the Task Sequence that you wish to add this functionality to.
2. Add a Run Command Line step in between the Partition Disk and Apply Operating System steps.
3. Rename the Run Command Line step to Prompt for ComputerName.
4. Edit the Command Line so that it looks like this:

ServiceUI.exe -process:TSProgressUI.exe %SYSTEMROOT%\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -File Set-OSDComputerNamePrompt.ps1

5. Put a check mark in the Package box, click Browse and select your newly created package (OSDComputerName).

52_2

Results

When you execute the Task Sequence on a client during OSD, you’ll now get a prompt where you can enter the computer name for that particular system.

52_3

If you enter more than 15 characters or none at all, the script will give you a corresponding error.

52_5

Enter a computer name and click OK.

52_4

I hope this helps. Let me know if you find any bugs or have suggestions for additional functions.

(7001)

Nickolaj Andersen

Principal Consultant and Enterprise Mobility MVP since 2016. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows devices and deployments including automation. Currently working for TrueSec as a Principal Consultant. Awarded as PowerShell Hero in 2015 by the community for his script and tools contributions. Creator of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService to name a few. Frequent speaker at conferences and user groups.

comments
  • Lyle
    Posted at 11:50 November 4, 2013
    Lyle
    Reply
    Author

    Hi There

    Great tutorial, but I was wondering if you had a customised WinPE image with Powershell enabled, as “%SYSTEMROOT%\System32\WindowsPowerShell”, if run from a TS would be pointing to “X:\”, which by default Powershell is not enabled in WinPE 4.0, and needs a custom image?

    • Nickolaj
      Posted at 12:14 November 4, 2013
      Nickolaj
      Reply
      Author

      Hi Lyle,

      I’ve modified the WinPE image from within ConfigMgr and added the PowerShell and .NET components. When those are added, you’ll be able to launch powershell.exe with the command line provided in this guide. Actually, I see now that I havn’t mentioned that in this post. Will update it to reflect how my WinPE image is configured.

      Regards,
      Nickolaj

  • Donald
    Posted at 22:52 February 10, 2014
    Donald
    Reply
    Author

    RE: “If you’re using an x64 boot image to deploy Windows, any of the files should work (I’ve only tested the x64 version though)”

    FYI – I tested a 64 bit deployment with the 32 bit version of serviceUI.exe and it did not work. Once I swapped with the 64 bit version all was well. Great tutorial.

    • Nickolaj
      Posted at 08:35 February 11, 2014
      Nickolaj
      Reply
      Author

      Hi Donald,

      Thanks for pointing that out! I’ve updated the post to reflect your comment.

      Best regards,
      Nickolaj

  • Alaa
    Posted at 11:44 June 9, 2014
    Alaa
    Reply
    Author

    you don’t need to do this, just add the OSDComputerName as a collection variable on the collection you are deploying to.

  • Dave Green
    Posted at 22:05 July 17, 2014
    Dave Green
    Reply
    Author

    Hi Nickolaj,

    Thanks for your script, it certainly started me out on the right path.

    I’ve been using your script and have made some alterations that improve the detection of invalid computer names and allow the enter key to be used instead of clicking OK. It can be found at https://gist.github.com/davegreen/453cee5ef2db1063a007 (with credit to you for the original)

    Thanks,
    Dave

    • Nickolaj
      Posted at 23:39 July 17, 2014
      Nickolaj
      Reply
      Author

      Hi Dave,

      Thanks for contributing to this script! I’ve added a comment about it in the post, so that people can find it easier 🙂

      Regards,
      Nickolaj

  • canadiandrums
    Posted at 21:01 August 27, 2014
    canadiandrums
    Reply
    Author

    Awesome guide, just what I was looking for! I believe I did everything correctly but I may be missing something simple. Powershell opens and everything at the point it should, but I get error code 0xFFFD0000 when it seems to try running the script.

    • Nickolaj
      Posted at 16:18 September 8, 2014
      Nickolaj
      Reply
      Author

      Hi,

      You’re welcome!

      Could you please provide a screenshot of how you’ve configured your TS and then a snippet from the smsts.log where it fails?

      Regards,
      Nickolaj

      • David
        Posted at 18:27 October 12, 2014
        David
        Reply
        Author

        I think I got stuck on the same problem as canadiandrums, error code 0xFFFD0000.

        @Nickolaj, In the beginning of this guide you name the PS script “OSDComputerNamePrompt.ps1”. When you add the command line it’s named “Set-OSDComputerNamePrompt.ps1″…

        Other than that, thanks for a great guide 🙂

        • Nickolaj
          Posted at 19:03 October 13, 2014
          Nickolaj
          Reply
          Author

          Hi David,

          Thank you for pointing that out, it has been remediated now 🙂

          Regards,
          Nickolaj

          • Jesse
            Posted at 20:07 July 17, 2017
            Jesse
            Author

            It still has “Set-OSDComputerNamePrompt.ps1″. I got hung up on this.

  • Scott W
    Posted at 22:36 August 28, 2014
    Scott W
    Reply
    Author

    Great tutorial. Thanks. Is it possible to set the OSDComputerName Environment Variable from within a 64 bit .NET C# application running within WinPE?

    • Nickolaj
      Posted at 16:16 September 8, 2014
      Nickolaj
      Reply
      Author

      Hi Scott,

      As long as the required .NET Framework version that the application is based upon is available in the WinPE image, I don’t see any problems.

      Regards,
      Nickolaj

  • siggi
    Posted at 17:19 October 29, 2014
    siggi
    Reply
    Author

    Spot on, great stuff. Thanks for sharing!

    • Nickolaj
      Posted at 09:10 November 5, 2014
      Nickolaj
      Reply
      Author

      Thanks Siggi, let me know if you run into any problems.

      Regards,
      Nickolaj

  • Mike
    Posted at 11:16 November 7, 2014
    Mike
    Reply
    Author

    Hi!

    How I can create a package? SCCM says that UNC path folder is empty.

    “Create a package in ConfigMgr 2012 SP1 and call it OSDComputerName (or something else). The package does not need to have any program, but specify the content source folder where you stored serviceUI.exe and Set-OSDComputerNamePrompt.ps1. Remember to distribute your package.”

    • Nickolaj
      Posted at 08:05 November 13, 2014
      Nickolaj
      Reply
      Author

      Hi Mike,

      Creating a Package is one of the simplest tasks that every ConfigMgr administrator should know how to do. Here’s a high-level step-by-step:

      1. Right-click on the Packages node under Software Library\Application Management and select Create Package.
      2. Enter a name, description manufacturer, language and version. Check the ‘This package contains source files’ box and enter the UNC path to where you’ve stored the Set-OSDComputerNamePrompt.ps1 file. Click Next.
      3. On the Program Type page, select ‘Do not create a program’. Click Next and finalize the wizard.

      I hope this helps, if not let me know!

      Regards,
      Nickolaj

      • Mike
        Posted at 14:56 November 17, 2014
        Mike
        Reply
        Author

        Thanks a lot!

        I make a first steps into SCCM, so from first look I was a little bit confused about creating a package.

  • Mike
    Posted at 09:25 November 18, 2014
    Mike
    Reply
    Author

    Hello again!

    I have a problem with task sequence. It shows me an error “0xffffffff” on running command line step. Not for so long time I don’t had issues.

    • Matt Gerber
      Posted at 20:51 September 2, 2016
      Matt Gerber
      Reply
      Author

      First time trying to set this up, and I’m getting the error too. Using SCCM 1606 and Windows 10.

  • Blaine
    Posted at 14:56 March 8, 2015
    Blaine
    Reply
    Author

    This guide is awesome! I have just started using PowerShell and I really want to add on to this script to make a check box or something to add the same computer to my domain at the same time that I rename it. Is that possible? If so how would I go about it?
    We don’t have SCCM setup or anything but this would speed up my re-imaging tremendously.
    Thanks!

    • Nickolaj
      Posted at 12:47 March 11, 2015
      Nickolaj
      Reply
      Author

      Hi Blaine,

      I’m glad that you like it! PowerShell is truly king 🙂

      I’m curious, why would want to create the domain computer account at the stage where you specify the computer name? The task sequence will at a later stage domain join the computer and when that happens, the computer account will be created automatically. How did you plan to leverage the script, in MDT or something?

      Regards,
      Nickolaj

      • Blaine
        Posted at 16:36 March 11, 2015
        Blaine
        Reply
        Author

        Nickolaj,

        Thanks for the response! I figured out how to get what I wanted in MDT. Thanks!

  • dooty22
    Posted at 10:54 March 13, 2015
    dooty22
    Reply
    Author

    Regard candiandrum issue with the 0xFFFD0000 error. I had the same thing, and in an effort to troubleshoot, I had to enable the F8 command support on the winpe image, and then the error went away. Im not sure how this would fix it but thought I would share.

  • Matt
    Posted at 11:36 April 20, 2015
    Matt
    Reply
    Author

    Thanks for this, has made my life so much easier! 🙂
    I’ve been looking into creating an addition part to this, where you are given a yes/no box asking if you would like to change the computer name. If yes, then your prompt pops up where you can type the computer name. If no, then the sequence will continue, keeping the previous machine name. I was able to get this to work, but the box appears behind the task sequence window.
    I’m not particularly great with scripting, do you know how I would be able to create a box that stays at the top like your one does?

  • Matt
    Posted at 11:04 April 24, 2015
    Matt
    Reply
    Author

    Hi Nickolaj,

    I ended up using the code that Dave Green provided, and then adding some messagbox code to the beginning of that. I’m a total beginner when it comes to this sort of stuff, so I’m sure there’s probably a whole bunch of rules that I’ve broken by doing it the way that I have. It seems to be working the way that I wanted it to though, the only problem is getting it to appear on top! Here’s the code anyway: http://pastebin.com/2Gk6tsiQ

    Just trying to get this working has at least got me interested in learning PowerShell, so that’s a good thing at least 😀

    • Nickolaj
      Posted at 15:40 April 24, 2015
      Nickolaj
      Reply
      Author

      Hi Matt,

      Awesome that you were able to create the code you were looking for. PowerShell is just great, isn’t it? 🙂

      Thanks for sharing your code as well.

      Regards,
      Nickolaj

  • Tim
    Posted at 16:42 June 1, 2015
    Tim
    Reply
    Author

    This works without the need to have MDT and still having your Task Sequence deployed as Purpose Required. However, I didn’t use the form above and I wanted to point out that I just have a Read-Host in my script. No fancy nice window showing up mainly because I’m not a programmer and don’t understand how to create forms quickly. I also needed to install MDT on a machine just to get the file referenced above in the directions, but only for that purpose.

    Nonetheless, I couldn’t get the above to work for me until I noticed that when running PowerShell the -WindowStyle Hidden was in the command. Once I remove this (The default value of -WindowStyle being “Normal”) then finally the console of PowerShell would display with my Read-Host now able to be used!! 😀 Hopefully someone else may will find this information handy.

    • Nickolaj
      Posted at 19:20 June 2, 2015
      Nickolaj
      Reply
      Author

      Hi Tim,

      Excellent! I’m glad that you were able to find a solution that suits your needs, and is easy for you to maintain, that’s the whole point really. And yeah, if you’re just running a command, you’d not use the -WindowStyle parameter unless your script is showing a UI or something.

      Regards,
      Nickolaj

  • KellyS
    Posted at 01:24 June 12, 2015
    KellyS
    Reply
    Author

    Hi Nickolaj,
    I am very new to creating task sequences. I have completed your step-by-step instructions and I am getting a 0x8007010B error which I understand could be bad or missing file path? I have double checked and everything looks good. When the sequence starts, the format window pops up for a moment before the server name pop up window even though I have the entry between Partition Disk 0 and Apply OS. Any thoughts would be greatly appreciated. Thank you.

  • Joe
    Posted at 21:49 August 21, 2015
    Joe
    Reply
    Author

    What’s the best way to restrict this step to only run on new computers that haven’t been named yet?

  • Dave
    Posted at 14:45 September 16, 2015
    Dave
    Reply
    Author

    I am getting an error (oxffffffff) after the script starts.

  • AN
    Posted at 21:42 September 16, 2015
    AN
    Reply
    Author

    Failed to run the action: Prompt for ComputerName.
    Unknown error (Error: FFFFFFFF; Source: Unknown)

  • Tommy
    Posted at 18:33 February 15, 2016
    Tommy
    Reply
    Author

    Hi Nickolaj, thank you for this great post. I’m wondering is I can do kind of the same process but in different way, let said, instead to prom for “Computer name” could be possible prompt for “Domain user name” store it as a TS variable, then connect to AD to get user name, an so get the user department and from that generate a computer name following standards like e.g. Domain + Laptop or Workstation + department + consecutive number (MSWIT001). I’ll appreciate any help. Thank you,

    Tommy.

  • Carlos
    Posted at 14:13 March 4, 2016
    Carlos
    Reply
    Author

    Failed to run the action: Prompt for ComputerName.
    Unknown error (Error: FFFFFFFF; Source: Unknown)

  • drappleyea
    Posted at 16:04 July 21, 2016
    drappleyea
    Reply
    Author

    Those receiving errors you likely need to specify the full path to powershell rather than using %systemroot%.

    “x:\windows\system32\windowspowershell\v1.0\powershell.exe”

  • Jay Connor
    Posted at 05:52 December 20, 2016
    Jay Connor
    Reply
    Author

    Thanks for the gui,
    Changed the script to name the computer it’s asset tag unless already in SCCM or a vm
    https://github.com/happysccm/Files/tree/master/Check%20for%20Asset%20Tag%20-%20OSD%20AssetTag%20Check%20-%20Most%20code%20by%20Nickolaj%20and%20Dave%20Green

  • Kasia
    Posted at 16:06 January 5, 2017
    Kasia
    Reply
    Author

    Hi Nikolaj,
    Thank you for sharing your work with us.
    We have modified your script a little bit with option for setting netcard properties like dns, static ip. disable dhcp osv…
    you can find our version on:

    http://joogle.dk/index.php/8-osd/1-promt-computer-name-and-netcard-settings-during-osd-tasksequence-in-sccm

    Maybe it can be useful for somebody.

    Regards
    Kasia

  • Tyler
    Posted at 04:51 July 3, 2017
    Tyler
    Reply
    Author

    Would anyone know how to use this exact script (where it prompts the user for text entry), but instead of settings the computer name, it sets the computer description? Ideally, I’d love to be able to set the computer name, then straight away prompt for the computer description. Any help would be greatly appreciated! 🙂

  • JOHNI
    Posted at 23:17 July 9, 2017
    JOHNI
    Reply
    Author

    Hi. thanks I was able create drop down menu from powershell. it select computer type L-CITY=7 SECRIAL NUMBER AND CONNECTS TO SPECIFIC OUS.

  • Guiga
    Posted at 18:07 August 1, 2017
    Guiga
    Reply
    Author

    Hello and manu thinks for your post.
    I have followed the steps to add teh script in the Task Sequence and i can see the popup to enter the new server name but i reboot the server and check the name, it’s still the old one.
    Do you have any idea about this problem please ?
    Thanks in advance for your assistance.

  • Leave a Reply