Tuesday, April 12, 2011

SCCM OSD Prompt For Computer Name

Looking for a way to allow you to prompt for a computer name during the baremetel imaging process? Well thanks to Nick Moseley over at http://t3chn1ck.wordpress.com/ we have a way to do that. Here is the code for the VBS with my changes .

 How To Add To Your Task Sequence

1. Create a New Package, and assign a DP for your script(s) you do not need to create a program for your script.
2. In your task sequence after the Partition Disk task add a task to run a Command Line.
3. In the command line section enter the name of the vbs.
4. Check the package and select the package you created in step 1.



















Code:

'==========================================================================
' 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
' 1.2 (04/07/2011)- Added check for vaild length of ComputerName -Matt Karel
'==========================================================================


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

    Do Until ValidName=1
        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",sTSMachineName, 30,30)
        ValidName=CheckComputerName(sNewComputerName)
    Loop

    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

Function CheckComputerName (CompName)
    If Len(CompName)=0 Then
        result=Msgbox("You must enter a computer name to continue.",vbExclamation+vbSystemModal,"Invaild Input")
        CheckComputerName=0
    ElseIf Len(CompName)<=15 Then
        CheckComputerName=1
    Else
        result=Msgbox(ucase(CompName) & " Is to long of a computer name. Computer names are limited to 15 characters or less.",vbExclamation+vbSystemModal,"Invaild Input")
        CheckComputerName=0
    End if
End Function

1 comment:

  1. You can also set up a Collection Variable on All Unknown Computers. I have two, one for the department and one for the computer name (OSDCOMPUTERNAME). Don't define any values and when you boot into PE you should get prompted for a computer name after you select your task sequence. Mind you, in this scenario this would only work on bare metal systems.

    ReplyDelete