Add a User to a Local Group

Adds kenmyer to the local Administrators group on a computer named atl-ws-01.

 
 
 
 
 
5 Star
(1)
Add to favorites
8/10/2009
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • How to use this when the name of the computer is the serial number?
    1 Posts | Last post 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?