Link to home
Create AccountLog in
Avatar of Tog_97
Tog_97

asked on

Computer attributes

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
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Tog_97
Tog_97

ASKER

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.
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

Avatar of Tog_97

ASKER

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
No problem. Thanks for the grade.

Regards,

Rob.