Re: Add User to Local Administrators Group
- From: "mariuss" <isiuksliudeze@xxxxxxxxxx>
- Date: Wed, 31 Jan 2007 15:58:38 +0200
Hi
Try this
i write this not for all domain but for selected OU
On error resume next
Set objOU = GetObject (LDAP://ou=Test,dc=XXX,dc=XX) ' write OU and domain
ObjOU.Filter= Array("computer") ' this filter
computers from selected OU
For Each objUser in objOU
strComputer = objUser.CN
Set objWMIService = GetObject("winmgmts:" _
&"{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery ("Select * from
Win32_ComputerSystem")
For Each objComputer in colComputer
logUser = replace(objComputer.UserName,"\","/") ' return logged user name in
format "domain/user name"
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser_Local = GetObject("WinNT://"&logUser)
objGroup.Add(objUser_Local.ADsPath) ' add logged user to Local admins group
Next
Next
Run script as Domain admin user
to test create Ou in AD for example "Test", add one or more computers,
modify script for OU "test", run script and check result
Good luck
Mariuss
"kbj" <kbrucejones@xxxxxxxxxxx> wrote in message
news:F2248B6B-8D67-4864-B77A-FC70268575DE@xxxxxxxxxxxxxxxx
Hi all-I
I need a script that I can run from my admin workstation. It would add a
user to the remote workstations Administrators group. Now the tricky part,
need to be able to add the current user who is logged on to thethat
Administrators group. Why you ask? We use a legacy app that requires the
user be a local admin and I screwed up and set a Restricted Groups policy
that erased all of the local admins except the Domain Admin group.
I am not a script writer, I'm only an editor :)
I have found scripts to add users/groups to the local admin (easy if you
know who to add) and scripts that detect the logged on user but nothing
I can cobble together to do both. I'm thinking of something like this:
get list of domain computers from AD
use generated list to call psloggedon and get the user info
use that list to call psexec and cmd /c net localgroup administrators
"psloggedon user"/add
log success / failure
Anyone want to take a crack at it?
.
- References:
- Add User to Local Administrators Group
- From: kbj
- Add User to Local Administrators Group
- Prev by Date: How to copy an object in a array?
- Next by Date: Re: How to copy an object in a array?
- Previous by thread: Add User to Local Administrators Group
- Next by thread: execquery using variable
- Index(es):
Relevant Pages
|