Help!
I have been tasked with producing a report for the new requirements from
Sabanes-Oxley.
I have to remotely connect to a list of servers, export the local admin
users and groups and
get any nested groups and users.
Below is the script I have so far but it does not appear to be getting the
nested groups and their members.
Any help would be great,
Thanks,
Tim
*****************************************************************************************************
Option Explicit
'on error resume Next
Dim FSO, ReadFile, InputFilePath, ReadFileArraySize, strComputer, iEntry,
group, user, objConn
Dim objRS, strRecordMessage, CmdShell, strCurrentDirectory, DelAdmins
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
InputFilePath = "ServerList.txt"
Set CmdShell = WScript.CreateObject("WScript.Shell")
Set FSO = CreateObject("Scripting.FileSystemObject")'Setup the file system
object.
Set ReadFile = FSO.OpenTextFile(InputFilePath, ForReading) 'Open the text
file containing the list of servers.
Set objConn = CreateObject("ADODB.Connection") 'Create a connnection to the
database.
Set objRS = CreateObject("ADODB.Recordset") ' Create a recordset to the
administrators table.
objConn.Open "DSN=InUse;" 'Open the ODBC connection to the database.
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM Administrators" , objConn, 3, 3 'Select the
administrators table.
DelAdmins = MsgBox ("Do you want to clear existing data? ", 4,"Remove
Records")
If DelAdmins = 6 Then
Call RemoveAdmins
End If
Function RemoveAdmins
objRS.Close
objRS.Open "DELETE * FROM Administrators" , objConn, 3, 3
strRecordMessage = MsgBox ("The records have been cleared.",0,"NOTICE")
'objRS.Close
End Function
ReadFileArraySize = 0
Do Until ReadFile.AtEndOfStream
ReDim Preserve ReadFileArray(ReadFileArraySize)
ReadFileArray(ReadFileArraySize) = ReadFile.ReadLine
ReadFileArraySize = ReadFileArraySize + 1
Loop
ReadFile.Close ' Close the text file after import of all servers.
For Each strComputer In ReadFileArray 'Read through the list of servers
'Start with the local administrators group
Call ListGroups("WinNT://" & strComputer & "/Administrators")
Next
'MsgBox "That's all!"
'wscript.sleep 15000
strCurrentDirectory = CmdShell.CurrentDirectory
CmdShell.Run strCurrentDirectory & "\" & "Administrators.mdb"
Function ListGroups(strADSGroup)
'Dim iEntry, group, user
On Error Resume Next
WScript.Echo strComputer
objRS.Open "SELECT * FROM Administrators" , objConn, 3, 3 'Select the
administrators table.
'If Err.Number <> 0 Then
'WScript.Echo "New Group: " & strADSGroup
'Call ServerNotFound
'Err.Clear
'Exit Function
'End If
objRS.AddNew
If user.lastLogin = "" then
objRS("LastLogin") = "Account Never Logged In"
Else
'bjRS("LastLogin") = user.lastlogin
End If
objRS("Server") = strComputer
objRS("Group") = strADSGroup
objRS("Member") = "NA"
objRS("LastLogin") = "NA"
objRS("LastPasswordChange") = "NA"
objRS("Class") = "Group"
objRS("AuditDate") = DATE
Set group = GetObject(strADSGroup)
for each iEntry in group.members
'WScript.echo "Group: " & group.Name & "; Member: " & iEntry.ADSpath & ";
class: " & iEntry.Class
objRS.AddNew
objRS("Server") = strComputer
objRS("Group") = strADSGroup
'objRS("Group") = group.Name
objRS("LastLogin") = "NA"
objRS("LastPasswordChange") = "NA"
objRS("AuditDate") = DATE
objRS("Member") = iEntry.ADSpath
objRS("Class") = iEntry.Class
if iEntry.Class="User" then
set user = GetObject(iEntry.ADSpath & ",user")
If user.lastLogin = "" then
objRS("LastLogin") = "Account Never Logged In"
Else
objRS("LastLogin") = user.lastlogin
End If
'wScript.echo "Here I am"
'Wscript.echo " User details
login: " & user.Name & "; last login: " & user.LastLogin
objRS("LastLogin") = user.LastLogin
objRS("Member") = user.name
If user.fullname = "" Then
objRS("Name") = "NA"
Else
objRS("Name") = user.fullname
End If
'WScript.Echo user.LastLogin
objRS("LastPasswordChange") = user.PasswordExpirationDate - 60
objRS("AuditDate") = DATE
objRS.Save
end If
if iEntry.Class="Group" then
Call ListGroups(iEntry.ADsPath)
end If
Next
End Function
Function ServerNotFound
objRS.AddNew
objRS("Group") = "Not Available"
objRS("AuditDate") = CurrentDate
objRS("LastPasswordChange") = "Not Available"
objRS("Server") = strComputer
objRS("Users") = "Not Available"
objRS("LastLogin") = "Not Available"
objRS.Save
objRS.Close
Msgbox
End Function
*********************************************************************************************************