Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

List all local admins in a text file 1

Status
Not open for further replies.

alepore

MIS
Jun 25, 2001
27
US
I am new to scripting and am having a problem getting this script to work. I want to first find all the computers in ADUC and then list all the local admins of those computers in a text file. Here is what I have so far. Any help will be appreciated. Thanks.

Const ADS_SCOPE_SUBTREE = 2
Set ws = CreateObject("WScript.Shell")
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "SELECT Name, Location FROM 'LDAP://OU=Test,DC=domain,DC=com' WHERE objectClass='computer'"
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 30
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
Wscript.Sleep 15000
Perm = ws.run("c:\local.exe administrators \\" & objRecordSet.Fields("name").Value & "">"" c:\localadmin.txt")
'Wscript.Echo "Computer Name: " & objRecordSet.Fields("name").Value
objRecordSet.MoveNext
Loop


Set ws = Nothing
Set objConnection = Nothing
Set objCommand = Nothing
Set objRecordSet = Nothing
 
If you want redirection, you must run a shell.
You also need to wait completion of the command.
Try something like this:
Perm=ws.Run("cmd /c c:\local.exe administrators \\" & objRecordSet.Fields("name").Value & ">> c:\localadmin.txt",1,True)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
You can use SysInternals PSEXEC to have the scripts run locally. This is a great free tool.

I hope you find this post helpful. Please let me know if it was.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top