none
Get-ADUser not returning future expiration dates RRS feed

  • Question

  • Hello all,

    FYI I am very new to PS scripting. I've ran this script with much success. However, it does return records that have future expiration dates which what I ultimately desire. Below is my script. Any insight will be appreciated and tested promptly. Thanks!

    Get-ADUser -Filter * -SearchBase 'OU=Users,DC=MyDomain,DC=CORP' -properties AccountExpirationDate | `
    Where-Object{$_.AccountExpirationDate -lt (Get-Date) -and $_.AccountExpirationDate -ne $null} | select-object name, samaccountname, `
    AccountExpirationDate

    Friday, May 22, 2015 3:38 PM

Answers

  • Minor point, but you can also filter, so you retrieve a much smaller resultset from the domain controller.

    $Today = [datetime]::Today
    Get-ADUser -Filter {AccountExpirationDate -gt $Today} -Properties AccountExpirationDate | Select Name, sAMAccountName, AccountExpirationDate


    Richard Mueller - MVP Directory Services

    Sunday, May 24, 2015 7:32 PM
    Moderator

All replies

  • Get-ADUser -Filter * -SearchBase 'OU=Users,DC=MyDomain,DC=CORP' -properties AccountExpirationDate |
        Where-Object{$_.AccountExpirationDate -gt [datetime]::Today} |
        select-object name, samaccountname, AccountExpirationDate
    
    Try it using the correct test.

    \_(ツ)_/

    • Proposed as answer by jrv Friday, May 22, 2015 4:12 PM
    Friday, May 22, 2015 4:08 PM
  • Minor point, but you can also filter, so you retrieve a much smaller resultset from the domain controller.

    $Today = [datetime]::Today
    Get-ADUser -Filter {AccountExpirationDate -gt $Today} -Properties AccountExpirationDate | Select Name, sAMAccountName, AccountExpirationDate


    Richard Mueller - MVP Directory Services

    Sunday, May 24, 2015 7:32 PM
    Moderator