Re: Adding a domain user to the local Administrators Group
From: Torgeir Bakken \(MVP\) (Torgeir.Bakken-spam_at_hydro.com)
Date: 07/07/04
- Next message: ylekiot : "RE: Add / Remove user from AD Groups"
- Previous message: Celler Dweller: "Get computer name from IP"
- In reply to: Mike A.: "Adding a domain user to the local Administrators Group"
- Next in thread: Mike A.: "Re: Adding a domain user to the local Administrators Group"
- Reply: Mike A.: "Re: Adding a domain user to the local Administrators Group"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 07 Jul 2004 19:18:25 +0200
Mike A. wrote:
> Does anyone know if there is a way to add a domain user to the local
> Administrators group using a script? The following script works if the user
> is a local user.
>
> strComputer = "MyComputer"
> Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
> Set objUser = GetObject("WinNT://" & strComputer & "/mike,user")
> objGroup.Add(objUser.ADsPath)
>
> Any help on this would be greatly appreciated.
Hi
Set objWshNet = CreateObject("WScript.Network")
strComputer = objWshNet.ComputerName
' hard code domain name here if necessary:
strNetBIOSDomain = objWshNet.UserDomain
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
Set objUser = GetObject("WinNT://" & strNetBIOSDomain & "/mike,user")
On Error Resume Next ' suppress error in case user is already a member
objGroup.Add(objUser.ADsPath)
On Error Goto 0
-- torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway Administration scripting examples and an ONLINE version of the 1328 page Scripting Guide: http://www.microsoft.com/technet/community/scriptcenter/default.mspx
- Next message: ylekiot : "RE: Add / Remove user from AD Groups"
- Previous message: Celler Dweller: "Get computer name from IP"
- In reply to: Mike A.: "Adding a domain user to the local Administrators Group"
- Next in thread: Mike A.: "Re: Adding a domain user to the local Administrators Group"
- Reply: Mike A.: "Re: Adding a domain user to the local Administrators Group"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|