Este es el método más sencillo que era capaz de llegar a ...
using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;
using ActiveDs;
//...
PrincipalContext domain = new PrincipalContext(ContextType.Domain);
UserPrincipal user = UserPrincipal.FindByIdentity(domain, "username");
DirectoryEntry entry = (DirectoryEntry)user.GetUnderlyingObject();
IADsUser native = (IADsUser)entry.NativeObject;
Console.WriteLine(user.GivenName + "'s password will expire on " + native.PasswordExpirationDate);
Nota # 1: ActiveDs
aparece en la pestañaCOM del Agregar referencia de diálogo como Active DS Type Library
Nota n. ° 2: Por lo que puedo decir, el PasswordExpirationDate
está en hora UTC.
Gran respuesta. ¡Gracias! un consejo: a veces, utilizar 'FindByIdentity' es muy lento. principalmente en máquinas locales. en estos casos, es mejor usar 'PrincipalSearcher' – itsho
Normalmente no utilizo las clases" * Principal * ". Prefiero los objetos DirectoryEntry y DirectorySearcher. En mis pruebas, tienden a ser más rápidos. –
¿En qué ensamblaje viven los ActiveDs? – Bartosz