Jump to content


anyweb

Setting computername during deployment

Recommended Posts



only thing to note is if you are using MDT integration to add scripts etc, then you'll need to use MDT 2012 Rc1 (currently)

Share this post


Link to post
Share on other sites

I have modified a version of the following computer rename script. Details of the edit can be found in the header of the script, however this script will not allow blank input and does a check to ensure that the computername is 15 characters or less, if neither conditions apply the task sequence aborts. Also you need to set your task sequence up so that it does a conditional check on the value of ALLOWOSBUILD. If the value = "No" then the task sequence will abort:

 

'==========================================================================
' NAME: ZTI-ComputerName.vbs
'
' AUTHOR: Nick Moseley
' DATE  : 6/1/2009
'
' v1.2 Edit: Christopher Nienaber
' DATE  : 4/4/2012
'
' 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 (4/4/2012)- Added check to ensure name is less than 16 characters, and that name
'  is not blank
'==========================================================================

Dim sNewComputerName, oTaskSequence, sTSMachineName, bPromptName, oAllowBuild
Dim bLength
Dim mBox
Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")
Set oAllowBuild = 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."
Do
 sNewComputerName = InputBox ("Enter Desired computer name to continue.", "ComputerName", , 30, 30)
 If sNewComputerName = "" Then
  bLength = False
 End If
 ' Check Length - Must not equal null and must be less than 16 characters
 If Len(sNewComputerName) <= 15 and Len(sNewComputerName) >= 1 Then
  bLength = True
 Else
  wscript.echo "Computer name must not equal null and must be less than 16 characters, prompting user to re-enter name."
  mBox = MsgBox ("ComputerName must not equal null and must be less than 16 characters, click ok to enter a new name or cancel to abort the task sequence!",1,"Invaild Computer Name")
 End IF
 If mBox = 2 Then
Exit Do
 End If
Loop While Not (bLength)
If blength = True Then
 oTaskSequence("OSDComputerName") = UCase(sNewComputerName)
 wscript.echo "Set Task Sequence variable OSDComputerName to: " & sNewComputerName
 oAllowBuild("ALLOWOSBUILD") = "YES"
 wscript.echo "A proper computer name was entered, continuing task sequence!"
Else
 oAllowBuild("ALLOWOSBUILD") = "NO"
 wscript.echo "Task Sequence aborted by user!"
End If
Else
wscript.echo "Computer Account already exists in SCCM Database, continuing Task Sequence"
oAllowBuild("ALLOWOSBUILD") = "YES"
End If

 

post-11614-0-69439000-1333640572_thumb.png

Share this post


Link to post
Share on other sites

Hi, I've been trying to get automatic computer names working in OSD for a while with Dell machines, but not much luck, finally got it working today though so I've written a quick guide on how I got mine to work if it can help any one else...

 

Set Computer Name Automatically During OSD

Share this post


Link to post
Share on other sites

Hello i'm new with sccm 2012, this forum saved my life several times during this few days :).

 

Now i am stuck...

 

I try to figure out a solution to automatically set the computer name during the windows 7 deployment.

 

The computer name cannot be entered manually during the deployment.it must be quiet (business requirement)

 

The workstation manufacturer has already put the computer name on a sticker at the front of the machines. (machines a delivered without OS)

 

The Computer names are linked to the machines serialnumbers in a DB. i can export it to an csv file or else.

 

I need to create the following tasks in the windows 7 deployment task sequence:

 

1: Get serialnumber (from win32_bios)

2: find the related computer name. (in a csv file or else)

3: finally apply the computer during the task sequence.

 

The problem is, I dont know if it is possible, if yes, where to begin :wacko:.

 

Thanks a lot

 

SCCM 2012 SP1 windows 2008 r2 windows 7 x64

 

 

 

Share this post


Link to post
Share on other sites

Hello i'm new with sccm 2012, this forum saved my life several times during this few days :).

 

Now i am stuck...

 

I try to figure out a solution to automatically set the computer name during the windows 7 deployment.

 

The computer name cannot be entered manually during the deployment.it must be quiet (business requirement)

 

The workstation manufacturer has already put the computer name on a sticker at the front of the machines. (machines a delivered without OS)

 

The Computer names are linked to the machines serialnumbers in a DB. i can export it to an csv file or else.

 

I need to create the following tasks in the windows 7 deployment task sequence:

 

1: Get serialnumber (from win32_bios)

2: find the related computer name. (in a csv file or else)

3: finally apply the computer during the task sequence.

 

The problem is, I dont know if it is possible, if yes, where to begin :wacko:.

 

Thanks a lot

 

SCCM 2012 SP1 windows 2008 r2 windows 7 x64

 

Hi - I think you would maybe need to use Orchestrator to do something like this?

Share this post


Link to post
Share on other sites

I am also facing the same issue.



I am using SCCM 2012.



The requirement for me is same, I am trying to assign the computername to the Workstations with respect to Serial number.


and for example the name should appear as "ABC00000000", some text+serial number.



I wrote the VBscript, this gets the serial number and adds the number to the text and then assigns the computer name to the workstation.


The script is working like a Champ when I am testing manually.


But I am missing the order to keep the script in the Task-Sequence.



Please help me to get the sequence where to place exactly.



I dont have the script with me right now to post it. I will post the script ASAP.



Thanks All.

Share this post


Link to post
Share on other sites
On 4/17/2013 at 10:46 PM, Veerla said:

 

I am also facing the same issue.

 

I am using SCCM 2012.

 

The requirement for me is same, I am trying to assign the computername to the Workstations with respect to Serial number.

and for example the name should appear as "ABC00000000", some text+serial number.

 

I wrote the VBscript, this gets the serial number and adds the number to the text and then assigns the computer name to the workstation.

The script is working like a Champ when I am testing manually.

But I am missing the order to keep the script in the Task-Sequence.

 

Please help me to get the sequence where to place exactly.

 

I dont have the script with me right now to post it. I will post the script ASAP.

 

Thanks All.

 

This process will do exactly what you are trying to do (I use this process every single day without any problems) and tells you where to put it in your task sequence - however, it does use MDT so if you do not have this integrated this will not help:

 

Set Company Name Automatically During OSD

Share this post


Link to post
Share on other sites

Here is the same case that you are telling, I dont want to use the MDT integration with SCCM.

I trying for a solution only with SCCM.

Share this post


Link to post
Share on other sites

Dim strSN

'************************************************************************************************************************************************
Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colBattery = objWMIService.ExecQuery("SELECT * FROM Win32_Battery")
'************************************************************************************************************************************************

Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

'************************************************************************************************************************************************
'Part 1 – Acquire serial/service tag number
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
strSN = objSMBIOS.SerialNumber

' Is this a Desktop or a Laptop
If colBattery.Count = 1 Then
' Is a Laptop
strSN = "LPT" & strSN
Else
' Is a Desktop
strSN = "DSK" & strSN
End If

If strSN <> "" Then exit For
Next
'************************************************************************************************************************************************

Set objWMIService = GetObject ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")


Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")


For Each objComputer in colComputers

ErrCode = objComputer.Rename(strSN)

Next

 

 

I got this scenario worked 90%, but I am getting a small error when i am using the above script.

the script is not giving me the battery information in the logic I am using...

if I am running the script manually on the OS it is working fine. but when I am doing OSD it is not working :(

can someone please help me if I am missing something?

 

Share this post


Link to post
Share on other sites

I haven't done much with testing for a laptop in a task sequence, so you'll want to test this, but one idea might be to change your chunk of code that says:

' Is this a Desktop or a Laptop
If colBattery.Count = 1 Then
' Is a Laptop
strSN = "LPT" & strSN
Else
' Is a Desktop
strSN = "DSK" & strSN
End If

 

 

With this chunk of code and see if it works as expected:
strSN = "DSK" & strSN
For Each objItem in colBattery
strSN = "LPT" & strSN
Next

 

For what it's worth, I always use "Option Explicit" to make sure I declare all my variables in a script...

Share this post


Link to post
Share on other sites

Hey Guys,

 

firstly, I love this site, without it setting up SCCM 2012 & deploying images to tablets would of taken a lot longer.

 

Anyway I would like to use a script to automatically assign a computer name to the tablet in its deploy TS

 

I need the computer name to start with the static name "tablet" followed by the last 5 digits of the serial number i.e tabletxxxxx

 

Scripting wouldn't be my strong side so any help would be greatly appreciated.

 

James

Share this post


Link to post
Share on other sites

I got this working if anyone is interested:

 

Dim objWMIService
Dim colItems
Dim colBattery
Dim objSMSEnv
Dim strNewName
Const strSite = "Tablet"

 

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Bios")
Set colBattery = objWMIService.ExecQuery("SELECT * FROM Win32_Battery")

' Get the Serial Number
For Each objItem In colItems
' Remove all beginning, trailing and containing spaces and change to all upper case
strNewName = UCase(Trim(Replace(objItem.SerialNumber, " ", "")))
Next

strNewName = Right(strNewName, 5)

'Site Code + Last 5 of Serial Number
strNewName = strSite & strNewName

' Set the Environment Variable that controls the Computer Name
Set objSMSEnv = CreateObject("Microsoft.SMS.TSEnvironment")
objSMSEnv("OSDCOMPUTERNAME") = strNewName

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...