Link to home
Start Free TrialLog in
Avatar of FLPeople
FLPeopleFlag for United States of America

asked on

Get Active Directory Domain Password Policy Attribute

I've seen lots of C# code to get this, but how do I get the default domain password policy - specifically the maxPwdAge attribute using VB.NET?

Here's my first line of code:
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")

Open in new window

Avatar of YZlat
YZlat
Flag of United States of America image

something like that?

 Dim DirEntry As DirectoryEntry = New DirectoryEntry(AdsiPath, "username", "password")
        Dim oSearcher As DirectorySearcher = New DirectorySearcher(DirEntry)
        Dim resultset As SearchResult

        With oSearcher
            .Filter = ("(objectClass=computer)")
            .PageSize = 5000
        End With

resultset = oSearcher.FindAll();
 
                if resultset.Properties.Contains("maxPwdAge") then
               
                    maxPwdAge = resultset.Properties("maxPwdAge")
            end if
oops, just realized it refers to user and not computer. Try this:

Dim DirEntry As DirectoryEntry = New DirectoryEntry(AdsiPath, "username", "password")
        Dim oSearcher As DirectorySearcher = New DirectorySearcher(DirEntry)
        Dim resultset As SearchResult

        With oSearcher
            .Filter = ("(objectClass=user)")
            .PageSize = 5000
        End With

resultset = oSearcher.FindAll();
 
                if resultset.Properties.Contains("maxPwdAge") then
               
                    maxPwdAge = resultset.Properties("maxPwdAge")
            end if
could you tell me exactly what are you trying to do
Avatar of FLPeople

ASKER

I am trying to find out how many days it will be until users' passwords expire in VB.NET.
ASKER CERTIFIED SOLUTION
Avatar of FLPeople
FLPeople
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Came up with my own math to convert C# code to VB.NET