title: Exclude disable user Get-aduser
body: <p>I want to exclude disabled user from this script but can't seem to find how i try the -exclude with no luck.</p>
  
  <p>if you have a better way to do it in open to suggestion too </p>
  
  <pre><code>import-module ActiveDirectory;
  
  $maxPasswordAgeTimeSpan = (Get-ADDefaultDomainPasswordPolicy).MaxPasswordAge
  
  Get-ADUser -filter * -properties PasswordLastSet, PasswordExpired, PasswordNeverExpires, EmailAddress, GivenName | foreach {
  
     $today=get-date
     $UserName=$_.GivenName
     $Email=$_.EmailAddress
  
     if (!$_.PasswordExpired -and !$_.PasswordNeverExpires) {
  
         $ExpiryDate=$_.PasswordLastSet + $maxPasswordAgeTimeSpan
         $DaysLeft=($ExpiryDate-$today).days
  
         if ($DaysLeft -lt 10 -and $DaysLeft -gt 0){
  
          $WarnMsg = "
  &lt;p style='font-family:arial'&gt;Bonjour $UserName,&lt;/p&gt;
  &lt;p style='font-family:arial'&gt;Votre mot de passe va expirer dans $DaysLeft jours, S.V.P. changer votre mot de passe.&lt;/p&gt;
  &lt;p style='font-family:arial'&gt;Merci.&lt;/p&gt;"
  
  $enc  = New-Object System.Text.utf8encoding
  ForEach ($email in $_.EmailAddress) { 
  send-mailmessage -to test@test -from noreply@test.com -Subject "Votre mot de passe va expirer dans $DaysLeft jours" -body $WarnMsg  -smtpserver x.x.x.x -BodyAsHtml -Encoding $enc }
  
      }
  
     }
  }
  </code></pre>