Name computer with serial # and join to domain?

Posted on 2011-04-19
Medium Priority
Last Modified: 2012-05-11
Does anyone have a working script or know of a way to script VBScript or Batch file that will do the following:

1. Name the computer with three parts to the name separated by a hyphen (- sign): three letter city code - the letters "LP" - then the service tag (it's a Dell). So the example computername would be HOU-LP-ServiceTag (where ServiceTag is the the 7 character serial like most Dells have.
2. Then join the system to the domain, AND POSSIBLY put it into the OU automatically (OU=Laptop,OU=Houston,OU=Initech Workstations,DC=Initech,DC=com).

I have this script below which is a script that successfully gets the service tag/serial number, but it merely inputs it into the clipboard (so you can go paste it somewhere).
I am not the author behind the script, do not have the expertise to manipulate it with the automation parts.
strComputer = InputBox("Enter a computer name to get service tag")
If IsEmpty(strComputer) Then
    MsgBox "Cancelled", vbExclamation, "Cancel Pressed"
ElseIf Len(strComputer) = 0 Then
    MsgBox "You did not enter a PC name.", vbInformation, "OK pressed"
    Set objWMIService = GetObject("winmgmts:" & _
            "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
    For Each objSMBIOS In objWMIService.ExecQuery("Select * from Win32_SystemEnclosure") 
        strSerialNumber = objSMBIOS.SerialNumber
        Set objIE = CreateObject("InternetExplorer.Application")
        objIE.document.parentwindow.clipboardData.SetData "text", strSerialNumber
        Wscript.Echo "The service tag for " & strComputer & " is: " & strSerialNumber
End If

Open in new window

Question by:garryshape
LVL 17

Accepted Solution

Tony Massa earned 1000 total points
ID: 35425811
Since the computer isn't a member of the domain, the user logging on won't be a domain member and have the ability to add the computer to the domain without hard-coding a user account and password into the script, and using VB encoder to obfuscate it.  (There is a script decoder, so it only prevents curious folks from reading the account)

Also, you can't rename a computer and join to a domain without a reboot between steps, which would kill the script...obviously.

I've started it for you, the script below should rename the computer for you...hopefully this will move you forward.
On Error Resume Next

strCityCode = InputBox("Enter City Code: ", "Get City Code")

strComputer = "."
Set WSHNetwork = CreateObject("WScript.Network")
strComputerName = WSHNetwork.ComputerName

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

Set colBIOS = objWMIService.ExecQuery _
    ("Select * from Win32_BIOS")
For each objBIOS in colBIOS
    strName = objBIOS.SerialNumber

strNewName = strCityCode & "-LP-" & strName
'WScript.Echo strNewName

strReNameCommand = "netdom renamecomputer " & strComputerName & " /newname:" & strNewName & " /usero:administrator /passwordo:* /reboot:10"
objShell.Run strRenameCommand

Open in new window


Assisted Solution

E0037633 earned 1000 total points
ID: 35429781
I would recommend taking a look at the Microsoft Deployment Toolkit (Microsoft Deployment Toolkit 2010).  It is a free tool from Microsoft that will allow you to create an image to support your computers..  We have our installation setup by the default gateway of the site (multi-site company) so each site is assigned to connect to create the computer accounts in a separate OU.

Author Closing Comment

ID: 35440956
Ok great, thx

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Assume you have an outside contractor who comes in seasonally or once a week to do some work in your office, but you only want to give him access to the programs and files he needs and keep all other documents and programs private. Can you do this o…
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 1 hour left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question