Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to access "msDS-ResultantPSO" attribute value of AD user using C#,I applied the Password Policy on a user, and its showing the value in "msDS-ResultantPSO" attribute.Now, I am trying to get this value using C# in the same way to get Normal attributes of AD user such as "FirstName, LastName,Email...".I added ResulantPSO attribute along with other normal attributes to load.My code bringing all normal attributes values except "msDS-ResultantPSO".

Please can anyone help me in this regard.

What I have tried:

I am trying to get this value using C# in the same way to get Normal attributes of AD user such as "FirstName, LastName,Email...".I added ResulantPSO attribute along with other normal attributes to load.My code bringing all normal attributes values except "msDS-ResultantPSO".
Posted
Updated 25-Jun-22 13:07pm

1 solution

Create a DirectoryEntry to the user's path. You can authenticate as anyone who has access to that path, like a service account, or the user's own credentials depending on your needs. The username format and flags specified in the code below ensure Kerberos authentication will be used, but again, that is up to your specific needs.

Then, the key is to simply tell the DirectoryEntry.Properties beforehand that you want the msDS-ResultantPSO property by using the .RefreshCach() method.


C#
private void FgppTest()
{
    var path = "LDAP://a-dc.dev.contoso.local/CN=Fine Grained Password Policy User,CN=Users,DC=dev,DC=contoso,DC=local";
    var username = "fgppUser@dev.contoso.local";
    var password = "the password";
    var flags = AuthenticationTypes.Secure | AuthenticationTypes.Signing | AuthenticationTypes.Sealing | AuthenticationTypes.ServerBind;

    using (var de = new DirectoryEntry(path, username, password, flags))
    {
        // The msDS-ResultantPSO is what's called a "constructed" attribute. It
        // doesn't physically exist in the directory on disk. So we must
        // explicitly request it.
        de.RefreshCache(new string[] { "msDS-ResultantPSO" });

        // Note, if the user doesn't have a FGPP set, this would throw an index
        // out of range error. If you need this code to be more general, you can
        // check the property count beforehand.
        var fgpp = de.Properties["msDS-ResultantPSO"][0].ToString();
        
        System.Diagnostics.Debug.WriteLine(fgpp);
    }
}
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900