Solved

Computer attributes

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now