Etiket arşivi: Local Admin Hesaplarını Listelemek

Local Admin Hesaplarını Listelemek

Domain ortamındaki son kullanıcı bilgisayarlarında tanımlı Local Admin hesaplarını liste olarak almak için aşağıdaki VBS’i kullanabiliriz.

Local Admin listelerini “C:\adminaccounts-” & strTimeDate & _  “.txt” dosyasında  bulabilirsiniz.

On Error Resume Next
Const ForWriting = 2
‘ Variable for admin group name, modify this
‘ variable if the administrators account has
‘ been renamed.
strAdminGroup = “Administrators”
‘ Format date/time stamp for output file
strTimeDate = Year(Date) & “-” & Month(Date) & _
“-” & Day(Date) & “~~” & Hour(Time) & “-” & _
Minute(Time)
‘ Output file name and path
strLogFile = “C:\adminaccounts-” & strTimeDate & _
“.txt”

‘Create Log File
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objFile = objFSO.OpenTextFile (strLogFile, _
ForWriting, True)

‘ Connect to domain and collect computer accounts
Const ADS_SCOPE_SUBTREE = 2
Set objConnection = CreateObject(“ADODB.Connection”)
Set objCommand = CreateObject(“ADODB.Command”)
objConnection.Provider = “ADsDSOObject”
objConnection.Open “Active Directory Provider”
Set objCommand.ActiveConnection = objConnection
set objRootDSE = GetObject(“LDAP://RootDSE“)
objCommand.CommandText = _
“SELECT Name, Location FROM ‘LDAP://” & _
objRootDSE.Get(“defaultNamingContext”) & “‘” _
& “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

‘ Output domain computer accounts, connect to each
‘ computer, and enumerate admin account members
Do Until objRecordSet.EOF
strComputer = objRecordSet.Fields(“Name”).Value
objFile.Write “System: ” & strComputer & VbTab
Set objGroup = GetObject(“WinNT://” & strComputer & _
“/” & strAdminGroup)
If Err <> 0 Then
objFile.Write(“*** System Unreachable ***”)
Err.Clear
Else
For Each member In objGroup.Members
objFile.Write member.Name & VbTab
Next
End If
objFile.WriteLine(“”)
objRecordSet.MoveNext
objfile.writeline()
Loop

Kaynak

http://cagatayisikci.wordpress.com/2011/05/04/local-admin-hesaplarini-listelemek/