Check accounts which will Expire soon

Hello,

i need a script to run it on Active Directory to check accounts which will expire in less than one week to send for them email to contact HR or line manager to renew the accounts.

and if there is a way to send for them email automatically as a notification.

Regards,
LVL 2
fadyazAsked:
Who is Participating?
 
helpfinderIT ConsultantCommented:
checkk this powershell script for passwords expirting whitin defined time

earch-ADAccount -AccountExpiring -TimeSpan "365" | Select-Object Name,AccountExpirationDate | Sort-Object AccountExpirationDate | Export-Csv Expiring-Accounts.csv

Open in new window

0
 
fadyazAuthor Commented:
Thanks helpfinder for your reply.

Does this script will export the account which will expire within 7 days. ?
0
 
helpfinderIT ConsultantCommented:
no, this is for 365 days, just change -TimeSpan value for desired number
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
fadyazAuthor Commented:
thanks a lot for your fast reply.  i want to make it as a batch file to just run it once every 7 days.
0
 
fadyazAuthor Commented:
I tried to run the script but it show for me an error message in attachment
error.png
0
 
fadyazAuthor Commented:
I found another script on the internet but it is not working can any body help me to modify it to check the expired account within 7 days.

dsquery * "ou=recipients,ou=exchange,dc=contoso,dc=com" -r -limit 999999 -filter " (&(objectCategory=Person)(objectClass=User)(!accountExpires=9223372036854775807)(!accountExpires=0)(accountExpires<=128947832000000000))"  -attr sAMAccountname displayName > expired.txt

Open in new window


http://gallery.technet.microsoft.com/scriptcenter/Batch-file-to-fine-expired-ddb246d3
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.