Re: run script as local admin fails
- From: "Richard Mueller [MVP]" <rlmueller-nospam@xxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 5 Feb 2008 13:16:12 -0600
tony wrote:
Here is my script to add a domain user to the local admin group on each
machine.
The problem i am seeing is I am logged in as a local admin and the local
admin cannot browse and add users from the domain.
What should i do to resolve this situation? so far, I have to add a domain
user to the local admin group on each machine and then run the script as
that domain user.
-----------------
on error resume next
Set objNet = WScript.CreateObject( "WScript.Network" )
Const FOR_READING = 1
strFilename = "c:\scripts\hosts.txt"
strUser = "testuser"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextStream = objFSO.OpenTextFile(strFilename, FOR_READING)
Do Until objTextStream.AtEndOfStream
strComputer = objTextStream.ReadLine
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
Set objUser = GetObject("WinNT://domain/user")
objGroup.Add(objUser.ADsPath)
Loop
------------------------
Logon as a member of the Domain Admins group. By default, the group Domain
Admins is a member of the local Administrators group on all computers joined
to the domain. Then you can add members to the local Administrators group
remotely. In order to bind to domain user objects, you must be authenticated
to the domain, not a local computer.
Using "On Error Resume Next" will make troubleshooting very difficult. In
your snippet you are not using the variable strUser. I would expect the "Set
objUser" statement to raise an error. Also, performance would be much better
if the user object were bound outside of the loop, so it is only bound once.
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--
.
- References:
- run script as local admin fails
- From: tony
- run script as local admin fails
- Prev by Date: run script as local admin fails
- Next by Date: Script to rename PC's
- Previous by thread: run script as local admin fails
- Next by thread: Script to rename PC's
- Index(es):
Relevant Pages
|