Written
November 26, 2013
So i'd like to use this script but the name of the computer will always be different and i have another script that pulls the name from the service tag. That is this script:
' Rename the computer
Set objWMIService = GetObject("winmgmts:\\" & "." & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("SELECT SerialNumber FROM Win32_BIOS")
For Each objItem In colItems
strSerial = objItem.SerialNumber
Next
Set objNetwork = CreateObject("WScript.Network")
strComputerName = objNetwork.ComputerName
strResponse = "KHO" & strSerial
If UCase(strResponse) <> UCase(strComputerName) Then
Set colComputers = objWMIService.ExecQuery ("Select Name from Win32_ComputerSystem")
For Each objComputer in colComputers
intErrorCode = objComputer.Rename(UCase(strResponse), strPassword, strDomain & "\" & strUser)
If intErrorCode <> 0 Then
WScript.Echo "Error renaming computer to " & strResponse & ". Error # " & intErrorCode
Else
WScript.Echo "Computer renamed"
End If
Next
End If
once the computer is renamed how can i make the "Add a user to local group" script reference the new name or take the current name of the computer?