Solved

Computer attributes

Posted on 2008-06-15
5
325 Views
Last Modified: 2010-04-16
I have about 600 XP Pro Dell workstations running on a 2003 AD. I would like
to script a domain-wide workstation rename, based in the Dell service tag. I
want to pull the SerialNumber from WMI (unless there's a better way), prepend
2 letters to the SerialNumber, and rename the computer on the domain based on
this info. i.e. XY-95RDW71.mydomain.local. Also want "if possible" to use the same script to set the computer attributes like location and description with the help of inputBox function. My problem is; I don´t know how to do that and where to place the commands to set the computer attributes. I mean before renaming the computer or after, and what commands I need to use.


I've done quite a bit of reading on this, and found some help on how to get the service tag and rename the computer on the domain, but not much help on how to get all I want in one script.
Any one have a script to put a computer attributes and rename the computer based on what I have below all in one script.


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

Set colSMBIOS = objWMIService.ExecQuery _
("SELECT * FROM Win32_bios")

For Each objSMBIOS in colSMBIOS
strSerialNo = objSMBIOS.SerialNumber
Next

'construct new machine name, based on serial number
strNewName = "XY" & strSerialNo

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

For Each objComputer in colComputers
err = objComputer.Rename(strNewName)
Next


Thanks
0
Comment
Question by:Tog_97
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 21789761
Hi, this should work.....to set the description via an InputBox, before renaming the computer account.  The renamed account will retain the property values...

Regards,

Rob.
Set objADSysInfo = CreateObject("ADSystemInfo")
strADComputerDN = objADSysInfo.ComputerName
Set objComputer = GetObject("LDAP://" & strADComputerDN)
strDescription = InputBox("Enter the computer description: ", "Computer Description")
objComputer.Description = strDescription
objComputer.SetInfo
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery _
("SELECT * FROM Win32_bios")
 
For Each objSMBIOS in colSMBIOS
strSerialNo = objSMBIOS.SerialNumber
Next
 
'construct new machine name, based on serial number
strNewName = "XY" & strSerialNo
Set colComputers = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
For Each objComputer in colComputers
	err = objComputer.Rename(strNewName)
Next

Open in new window

0
 

Author Comment

by:Tog_97
ID: 21794493
Thanks a lot, that worked perfect.

Just one more question. Is it possible to ad on the script to join a computer to a domain too, but keeping what the script dose?

The reason I want that too is; I am buying around 100 more new dell computers and would like to use the script to join them to the domain too.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21800184
Hi, sorry for my delay! I've been very busy today!

You can use this script, which required NetDom.exe to join a computer to the domain.

Have a copy of NetDom.exe in the same folder as the script, and you should be right to go.

Regards,

Rob.
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strResponse = MsgBox("This computer's name is " & objNetwork.ComputerName & ". Do you want to rename it?", vbYesNo, "Rename Computer?")
If strResponse = vbYes Then
	Set objADSysInfo = CreateObject("ADSystemInfo")
	strADComputerDN = objADSysInfo.ComputerName
	Set objComputer = GetObject("LDAP://" & strADComputerDN)
	strDescription = InputBox("Enter the computer description: ", "Computer Description")
	objComputer.Description = strDescription
	objComputer.SetInfo
	 
	strComputer = "."
	Set objWMIService = GetObject("winmgmts:" _
	& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colSMBIOS = objWMIService.ExecQuery _
	("SELECT * FROM Win32_bios")
	 
	For Each objSMBIOS in colSMBIOS
	strSerialNo = objSMBIOS.SerialNumber
	Next
	 
	'construct new machine name, based on serial number
	strNewName = "XY" & strSerialNo
	Set colComputers = objWMIService.ExecQuery _
	("Select * from Win32_ComputerSystem")
	For Each objComputer in colComputers
		err = objComputer.Rename(strNewName)
	Next
End If
 
strResponse = MsgBox("Do you want to joing this computer (" & objNetwork.ComputerName & ") to the domain?", vbYesNo, "Join Domain?")
If strResponse = vbYes Then
	If objFSO.FileExists(objFSO.GetSpecialFolder(1) & "\NetDom.exe") = False Then
		If objFSO.FileExists(Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "NetDom.exe") = True Then
			objFSO.CopyFile Replace(WScript.ScriptFullName, WScript.ScriptName, "") & "NetDom.exe", objFSO.GetSpecialFolder(1) & "\"
			WScript.Echo "NetDom.exe has been copied to " & objFSO.GetSpecialFolder(1) & "\"
		Else
			WScript.Echo "NetDom.exe does not exist at " & objFSO.GetSpecialFolder(1) & "\NetDom.exe.  Cannot continue script."
			WScript.Quit
		End If
	End If
	strDomain = InputBox("Enter the name of the domain to join:", "Domain to Join", "DOMAIN")
	strAdminUser = InputBox("Enter the name of the domain account with rights to add a computer to the domain:", "Domain Account", "DOMAIN\ACCOUNT")
	strAdminPass = InputBox("Enter the password for " & strAdminUser, "Domain Account Password")
	strCommand = "cmd /c NETDOM JOIN " & objNetwork.ComputerName & " /Domain:" & strDomain & " /userD:" & strDomain & "\" & strAdminUser & " /passwordD:" & strAdminPass & " /REBOOT 10"
	objShell.Run strCommand, 1, False
	MsgBox "This computer will be joined to the domain shortly, and reboot automatically. Please wait."
End

Open in new window

0
 

Author Comment

by:Tog_97
ID: 21804360
Hi Rob,
Thanks a lot for the very good and clear scripts. That really helped me a lot and saved me lots of time.

Thank you
Best Regards
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 21809953
No problem. Thanks for the grade.

Regards,

Rob.
0

Featured Post

Independent Software Vendors: 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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
Suggested Courses

738 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