title: Days until password expires
body: <pre><code>(([datetime]::FromFileTime((Get-ADUser –Identity username -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed"))-(Get-Date)).Days
  </code></pre>
  
  <p>Will output the amount of time until an AD account expires. However, when I try to place this in a script by setting a variable equal to it, it will crash and close real fast and it doesn't work. I am unsure why.</p>
  
  <p>EDIT:</p>
  
  <p>Running this command only in my script, I get an error:</p>
  
  <pre><code>$Expiration = (([datetime]::FromFileTime((Get-ADUser –Identity 'MyTestUser' -Properties "msDS-UserPasswordExpiryTimeComputed")."msDS-UserPasswordExpiryTimeComputed"))-(Get-Date)).Days
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>At C:\Users\ajstepanik\Desktop\test.ps1:1 char:161
  + ... iryTimeComputed"))-(Get-Date)).Days
  +                    ~~~~~~~~~~~~~~~~~~~~
  The string is missing the terminator: ".
  At C:\Users\ajstepanik\Desktop\test.ps1:1 char:181
  + ... Get-Date)).Days
  +                    ~
  Missing closing ')' in expression.
  At C:\Users\ajstepanik\Desktop\test.ps1:1 char:181
  + ... Get-Date)).Days
  +                    ~
  Missing ')' in method call.
      + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordEx
     ception
      + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
  </code></pre>