One of my client had a requirement of a OSD computer name prompt to use in OSD task sequence. The requirements were;
- Prompt for machine name
- OSD Name should not be accepting certain characters
- OSD name should not accept empty value
- The length should be higher than 5 and less then 12
- The script should change the input values to uppercase if a technician typed lower case.
The following OSD Computer name script will accommodate above requirements.
This is not my own script, however i have used the base script from internet and changed it as per the requirements.
************************************
'Prompt for Computer name
Dim env, objRegEx
Dim Matches, Match
Dim strPattern, strInputBox, strReason
Dim boolLength, boolValid
Set ProgressUI = CreateObject("Microsoft.SMS.TsProgressUI")
ProgressUI.CloseProgressDialog
Set env = CreateObject("Microsoft.SMS.TSEnvironment")
Set objRegEx = New RegExp
'Define valid patterns as and character not in (a-z, A-Z, 0-9, or -)
strPattern = "[^a-zA-Z0-9-]"
Do
strReason = ""
strInputBox = InputBox("Enter desired machine name." & VbCrLf & VbCrLf & "Machine names must be 6-12 characters, and include a-z, 0-9, - ONLY.","Machine Name")
If strInputBox = "" Then
strReason = strReason & "Machine name must NOT be empty." & VbCrLf & VbCrLf
boolLength = False
End If
' Check length - must be 6 - 12 characters length.
If Len(strInputBox) <= 12 and Len(strInputBox) >= 6 Then
boolLength = True
Else
strReason = strReason & "Machine name must be 6 to 12 characters in length." & VbCrLf
boolLength = False
End If
' Check character validity
boolValid = True
' Return all matches for invalid characters
objRegEx.Global = True
objRegEx.Pattern = strPattern
' Generate collection of matches
Set Matches = objRegEx.Execute(strInputBox)
' Check for matches on invalid characters
For Each Match In Matches
strReason = strReason & "Invalid character """ & Match.Value & """ found. Please use only a-z, A-Z, 0-9, and -." & VbCrLf
boolValid = False
Next
If Not (boolLength And boolValid) Then MsgBox "Invalid name """ & strInputBox & """ entered!" & VbCrLf & VbCrLf & strReason,vbCritical+vbOKOnly,"Invalid Name Entered"
Loop While Not (boolLength And boolValid)
MsgBox "Computer name set to " & UCase(strInputBox) & ".",vbInformation+vbOKOnly,"Computer Name Set"
env("OSDComputerName") = UCase(strInputBox)
************************************
How to use OSD Computer Name prompt script in SCCM OSD task sequence:
1/ Create a package using above VBScript
2/ Open the deploy task sequence in edit mode
3/ Create a Run Command Line Step just after Restart in Windows PE step then add below command
X:\Windows\System32\CScript.exe OSDComputerName.vbs
Select Disable 64-bit file system redirection
Select package and browse to the package we have created in step 1
No comments:
Post a Comment