Hi Im fairly new to all this
Ive used this script to query what I require but there are two things wrong
Here is the script after i amended it
Dim ObjWb
Dim ObjExcel
Dim x, zz
Set objRoot = GetObject("[link=http://www.visualbasicscript.com/ldap://RootDSE]LDAP://RootDSE[/link]")
strDNC = objRoot.Get("DefaultNamingContext")
Set objDomain = GetObject("LDAP://" & strDNC) ' Bind to the top of the Domain using LDAP using ROotDSE
Call ExcelSetup("Sheet1") ' Sub to make Excel Document
x = 1
Call enummembers(objDomain)
Sub enumMembers(objDomain)
On Error Resume Next
Dim Secondary(20) ' Variable to store the Array of 2ndary email alias's
For Each objMember In objDomain ' go through the collection
If ObjMember.Class = "user" then
x = x +1 ' counter used to increment the cells in Excel
objwb.Cells(x, 1).Value = objMember.Class
' I set AD properties to variables so if needed you could do Null checks or add if/then's to this code
' this was done so the script could be modified easier.
SamAccountName = ObjMember.samAccountName
Cn = ObjMember.CN
Department = objMember.Department
LastLogin = objMember.LastLogin
PasswordLastChanged = objMember.PasswordLastChanged
' Write the values to Excel, using the X counter to increment the rows.
objwb.Cells(x, 2).Value = SamAccountName
objwb.Cells(x, 3).Value = CN
objwb.Cells(x, 4).Value = Department
objwb.Cells(x, 5).Value = LastLogin
objwb.Cells(x, 6).Value = PasswordLastChanged
' Blank out Variables in case the next object doesn't have a value for the property
SamAccountName = "-"
Cn = "-"
Department = "-"
LastLogin = "-"
PasswordLastChanged = "_"
End If
' If the AD enumeration runs into an OU object, call the Sub again to itinerate
If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then
enumMembers (objMember)
End If
Next
End Sub
Sub ExcelSetup(shtName) ' This sub creates an Excel worksheet and adds Column heads to the 1st row
Set ObjExcel = CreateObject("Excel.Application")
Set objwb = objExcel.Workbooks.Add
Set objwb = objExcel.ActiveWorkbook.Worksheets(shtName)
Objwb.Name = "Active Directory Users" ' name the sheet
objwb.Activate
ObjExcel.Visible = True
objwb.Cells(1, 2).Value = "SamAccountName"
objwb.Cells(1, 3).Value = "CN"
objwb.Cells(1, 4).Value = "Department"
objwb.Cells(1, 5).Value = "LastLogin"
objwb.Cells(1, 6).Value = "PassWordLastChanged"
'formatting for header
Set objRange = objExcel.Range("A1","Z1")
objRange.Interior.ColorIndex = 33
objRange.Font.Bold = True
objRange.Font.Underline = True
End Sub
'autofit the output
Set objRange = objwb.UsedRange
objRange.EntireColumn.Autofit()
ObjExcel.Save("ADoutput.xls")
MsgBox "Done" ' show that script is complete
Firstly the last login stamp isn't working as we have more than one dc, and it only gets the information from the dc the computer you are logged into. How can i get the information from all the dcs for the last login stamp?
Secondly I dont want admin accounts to be included. If i add them all to one group how can i specify the script to exclude all accounts added to that group?