Hi,
I have a script that I've been peacing together for sometime now and I'm wondering how to find the dates the users acct were disabled and how I get the user IDs to show up.
I'm posting a copy here(most of it works), currently is will pull disabled acct info and open it up to an excel spreadsheet displaying the "Last Name, First Name" but now I need to be able to pull the date the account was actually disabled, how can I do that??? whats the attribute?
Any help/advise is very much welcome!!! thx!
Const ADS_SCOPE_SUBTREE = 2
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Disabled Users Report"
objExcel.Cells(1, 1).Font.Bold = TRUE
Set objRange = objExcel.Range("A1","A1")
objRange.Font.Size = 12
objExcel.Cells(3, 1).Value = "Last Name"
objExcel.Cells(3, 2).Value = "First Name"
objExcel.Cells(3, 3).Value = "Date Disabled"
objExcel.Cells(3, 4).Value = "User ID"
objExcel.Cells(3, 1).Font.Bold = TRUE
objExcel.Cells(3, 2).Font.Bold = TRUE
objExcel.Cells(3, 3).Font.Bold = TRUE
objExcel.Cells(3, 4).Font.Bold = TRUE
Set objRange = objExcel.Range("A3","D3")
objRange.Font.Size = 11
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Const ADS_UF_ACCOUNTDISABLE = 2
objCommand.CommandText = _
"SELECT userAccountControl, givenName, SN, DisabledDate, UserLogonID FROM " _
& "'LDAP://dc=corp,dc=jitb, dc=net' WHERE " _
& "objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x = 4
Do Until objRecordSet.EOF
intUAC = objRecordset.Fields("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then
objExcel.Cells(x, 1).Value = _
objRecordSet.Fields("SN").Value
objExcel.Cells(x, 2).Value = _
objRecordSet.Fields("givenName").Value
objExcel.Cells(x, 3).Value = _
objRecordSet.Fields("DisabledDate").Value
objExcel.Cells(x, 4).Value = _
objRecordSet.Fields("UserLogonID").Value
x = x + 1
End If
objRecordSet.MoveNext
Loop
objRange.EntireColumn.Autofit()
objExcel.Cells(x+1, 1).Value = "Total Disabled Users ="
I have a script that I've been peacing together for sometime now and I'm wondering how to find the dates the users acct were disabled and how I get the user IDs to show up.
I'm posting a copy here(most of it works), currently is will pull disabled acct info and open it up to an excel spreadsheet displaying the "Last Name, First Name" but now I need to be able to pull the date the account was actually disabled, how can I do that??? whats the attribute?
Any help/advise is very much welcome!!! thx!
Const ADS_SCOPE_SUBTREE = 2
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Disabled Users Report"
objExcel.Cells(1, 1).Font.Bold = TRUE
Set objRange = objExcel.Range("A1","A1")
objRange.Font.Size = 12
objExcel.Cells(3, 1).Value = "Last Name"
objExcel.Cells(3, 2).Value = "First Name"
objExcel.Cells(3, 3).Value = "Date Disabled"
objExcel.Cells(3, 4).Value = "User ID"
objExcel.Cells(3, 1).Font.Bold = TRUE
objExcel.Cells(3, 2).Font.Bold = TRUE
objExcel.Cells(3, 3).Font.Bold = TRUE
objExcel.Cells(3, 4).Font.Bold = TRUE
Set objRange = objExcel.Range("A3","D3")
objRange.Font.Size = 11
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 100
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Const ADS_UF_ACCOUNTDISABLE = 2
objCommand.CommandText = _
"SELECT userAccountControl, givenName, SN, DisabledDate, UserLogonID FROM " _
& "'LDAP://dc=corp,dc=jitb, dc=net' WHERE " _
& "objectCategory='user'"
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
x = 4
Do Until objRecordSet.EOF
intUAC = objRecordset.Fields("userAccountControl")
If intUAC And ADS_UF_ACCOUNTDISABLE Then
objExcel.Cells(x, 1).Value = _
objRecordSet.Fields("SN").Value
objExcel.Cells(x, 2).Value = _
objRecordSet.Fields("givenName").Value
objExcel.Cells(x, 3).Value = _
objRecordSet.Fields("DisabledDate").Value
objExcel.Cells(x, 4).Value = _
objRecordSet.Fields("UserLogonID").Value
x = x + 1
End If
objRecordSet.MoveNext
Loop
objRange.EntireColumn.Autofit()
objExcel.Cells(x+1, 1).Value = "Total Disabled Users ="