How to read a property `ms-Mcs-AdmPwdExpirationTime` from ActiveDirectory

11,766

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

Share:
11,766

Related videos on Youtube

StepUp
Author by

StepUp

Updated on September 18, 2022

Comments

  • StepUp
    StepUp over 1 year

    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?

    • Vomit IT - Chunky Mess Style
      Vomit IT - Chunky Mess Style over 6 years
      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.
  • Michał Sacharewicz
    Michał Sacharewicz about 5 years
    Please note that the question was about VB solution. PowerShell solution was already known in original question.