I'm using "GetAdsProp" to obtain LDAP Attiributes. Is it possible to obtain the status of a User's Active Directory account to determine whether it is disabled or not?
Thanks for your assistance,
John
AD Account Status
-
- GoldLounger
- Posts: 2640
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
AD Account Status
Regards,
John
John
-
- Administrator
- Posts: 79686
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: AD Account Status
GetAdsProp is not a standard function. Are you referring to Query Active Directory from Excel?
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2640
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
-
- GoldLounger
- Posts: 2640
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: AD Account Status
Hans,
I found this code on-line
and it is encountering a run-time error when "Set objRecordSet = objCommand.Execute"
I'm not sure why. Although I expect it is how I fill in the variables such as:
Msgbox = GetStatus("mail","yourEmailAddress@something.com")
Thanks for taking a look at this,
John
I found this code on-line
Code: Select all
Function GetStatus(ByVal SearchField As String, ByVal SearchString As String) As String
'Get the domain string ("dc=domain, dc=local")
Dim strDomain As String
Dim ReturnField As String
strDomain = GetObject("LDAP://rootDSE").Get("defaultNamingContext")
ReturnField = "distinguishedName"
'ADODB Connection to AD
Dim objConnection As ADODB.Connection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
'Connection
Dim objCommand As ADODB.Command
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
'Search the AD recursively, starting at root of the domain
objCommand.CommandText = _
";(&(objectCategory=User)" & _
"(" & SearchField & "=" & SearchString & "));" & SearchField & "," & ReturnField & ";subtreeâ€"
'Recordset
Dim objRecordSet As ADODB.Recordset
Set objRecordSet = objCommand.Execute
If objRecordSet.RecordCount = 0 Then
GetStatus = "not found" 'no records returned
Else
Set objUser = GetObject("LDAP://" & objRecordSet.Fields(ReturnField))
If objUser.AccountDisabled = True Then
GetStatus = "Disabled" 'return value
End If
If objUser.AccountDisabled = False Then
GetStatus = "Enabled" 'return value
End If
End If
'Close connection
objConnection.Close
'Cleanup
Set objUser = Nothing
Set objRecordSet = Nothing
Set objCommand = Nothing
Set objConnection = Nothing
End Function
I'm not sure why. Although I expect it is how I fill in the variables such as:
Msgbox = GetStatus("mail","yourEmailAddress@something.com")
Thanks for taking a look at this,
John
Regards,
John
John
-
- Administrator
- Posts: 79686
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
-
- Administrator
- Posts: 79686
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: AD Account Status
I have moved this thread to the VBA forum because it is not specific to Excel.
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2640
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: AD Account Status
I have developed a means of obtaining the "FullName" of an Active Directory Account through a Function. What I would like to do is pass the contents of an myArray to the code. My challenge is noted in the code below.
Thanks for your suggestions,
John
Code: Select all
Function ListMembers(strDomainName As String, strUserName As String)
Dim objUser As Object
Dim myArray
Set objUser = GetObject("WinNT://" & strDomainName & "/" & strUserName)
myArray = Array("FullName", "Name", "AccountDisabled", "Description", "IsAccountLocked", "LastLogin", "PasswordExpirationDate", "PasswordRequired")
For k = LBound(myArray) To UBound(myArray)
MsgBox objUser.FullName 'Works
MsgBox objUser & "." & myArray(k) 'Challenge is here
Next k
End Function
John
Regards,
John
John
-
- Administrator
- Posts: 79686
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: AD Account Status
I can't test it myself, but try
Code: Select all
For k = LBound(myArray) To UBound(myArray)
MsgBox objUser.Get(myArray(k))
Next k
Best wishes,
Hans
Hans
-
- GoldLounger
- Posts: 2640
- Joined: 26 Jan 2010, 16:31
- Location: Southern California
Re: AD Account Status
Hans,
Thank you for the suggestion, it worked.
A little less than 4 hours to go and I can depart a "Happy Camper".
Regards,
John
Thank you for the suggestion, it worked.
A little less than 4 hours to go and I can depart a "Happy Camper".
Regards,
John
Regards,
John
John