Powershell Script to list expiration dates for accounts in Active Directory 2008 or 2012.

Hello All, I am looking for a Powershell script that I can use for listing user accounts in Active Directory (2012) with any of the following criteria
1) expired account with the expiration date, or 2) active accounts that have expiration dates and (if possible) the due date for expiration.

This is an ongoing project and any assistance is deeply appreciated. Thank you in advance.
howard temproSystems AdministratorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
That should do the trick:
Get-ADUser -Filter "(accountExpires -lt $([Int64]::MaxValue)) -and (accountExpires -gt 0)" -Property accountExpires, AccountExpirationDate -ResultSetSize $null |
	Select-Object SamAccountName, AccountExpirationDate, @{n='Expired'; e={$_.AccountExpirationDate -lt [DateTime]::Now}}, DistinguishedName |
	Export-Csv -NoTypeInformation -Path C:\Temp\AccountExpiration.csv

Open in new window

Replace the last line with this to see the results in a table instead of a csv:
	Out-GridView

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Naveen SharmaCommented:
You can try the powrshell script to get a list of enabled Active Directory accounts and their password expiry time

Get-ADUser -filter {Enabled -eq $True -and PasswordNeverExpires -eq $False} –Properties "DisplayName", "msDS-UserPasswordExpiryTimeComputed" |

Select-Object -Property "Displayname",@{Name="ExpiryDate";Expression={[datetime]::FromFileTime($_."msDS-UserPasswordExpiryTimeComputed")}} 

Open in new window

For more information, please refer to the below links.

http://password-expiration-notification.blogspot.in/

https://4sysops.com/forums/topic/list-ad-accounts-with-expiration-date/
0
howard temproSystems AdministratorAuthor Commented:
Working on your solution now. Thank you very much for the work. I will update this post as soon as I get a test result.
0
howard temproSystems AdministratorAuthor Commented:
I cannot thank you all enough for the work that you posted. All of these were helpful, and I appreciate your swift responses. My problem has been resolved.
0
howard temproSystems AdministratorAuthor Commented:
Thank you all for your swift reply and excellent contributions. You have resolved my issue. I appreciate the work that you posted.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.