0

I am trying to read Expiration time of administrator password from ActiveDirectory:

Dim DC = New  PrincipalContext(ContextType.Domain)
Dim cmp = ComputerPrincipal.FindByIdentity(DC, hostnm)
Dim desting As String = cmp.DistinguishedName
Dim de As New DirectoryEntry("LDAP://" & desting)
pwdexp = de.Properties("ms-Mcs-AdmPwdExpirationTime").Value.ToString()

But what I see is just <COM Type>: enter image description here

However, expiration time of administrator password can be easily read by PowerShell:

$TestValue = [adsi]"LDAP://CN=xxx,OU=xxx,OU=xxx,OU=xxx,OU=xxx,DC=xxx,DC=xxx,DC=xx"
$TestValue.ConvertLargeIntegerToInt64($Testvalue."ms-Mcs-AdmPwdExpirationTime"[0])

And I know that there is a such property: enter image description here

Interestingly, but I can read another parameter ms-Mcs-AdmPwd:

Dim DC = New  PrincipalContext(ContextType.Domain)
Dim cmp = ComputerPrincipal.FindByIdentity(DC, hostnm)
Dim desting As String = cmp.DistinguishedName
Dim de As New DirectoryEntry("LDAP://" & desting)
pwdexp = de.Properties("ms-Mcs-AdmPwdExpirationTime").Value.ToString()

and value can be seen from debugger:

enter image description here

How to read a property ms-Mcs-AdmPwdExpirationTime correctly?

  • FYI... You might look over the simple command net user /domain administrator just like that and then see the value for the field Password Expires. – Pimp Juice IT Oct 13 '17 at 22:13
2

This works for me in powershell:

$comp = Get-ADComputer Laptop8 -Properties ms-MCS-AdmPwdExpirationTime
$([datetime]::FromFileTime([convert]::ToInt64($comp.'ms-MCS-AdmPwdExpirationTime',10)))

good luck Sem

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.