Solved

Computer attributes

Posted on 2008-06-15
5
323 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
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This is an addendum to the following article: Acitve Directory based Outlook Signature (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24950055.html) The script is fine, and works in normal client-server domains…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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