Looking for a way to disable a new account if the user has not signed on within 10 days. I can't find any MS setting within Active Directory. Maybe someone knows of a powershell script I can run or third-party utility that can do this for us?
I would imagine the script would look something like: if the account option for "user must change password at next logon" is checked and the user hasn't done so within 10 days, disable account.
Is this possible? We are running a Windows 2012 domain.
Thanks!!
Active DirectoryWindows Server 2012
Last Comment
nreich
8/22/2022 - Mon
Mahesh
You can check Powershell script mentioned in below article
You could run a powershell script to check if users havent logged in for say 10 days.
ADAccount -AccountInactive -TimeSpan ([timespan]10d) -UsersOnly | Set-ADUser -Enabled $false
If you want to test and see what would be disabled add -WhatIf to the above line.
This is offcourse applicable on all your users.
Workaround would be creating a special newby OU and point that script only to this OU by adding.
-SearchBase string
nreich
ASKER
Those suggestions are a start! However, I need it to explicitly look to see if the account option for "user must change password at next logon" is set. Is there a script setting that checks for this?
Only you need to know Attribute name in order to add it
Also you can export output to csv \ excel format if wanted to
Mahesh
SubSun
Following command will give you the inactive accounts with "user must change password at next logon" is set.. You can pipe this result to Disable-ADAccount to disable the accounts.. Or You can use Export-csv to export the result to a csv file and then disable it using the csv file..
http://social.technet.microsoft.com/Forums/windowsserver/en-US/e21e61c7-4c79-490e-b136-69bbef9e328e/powershell-that-disables-active-directory-users-that-have-not-logged-on-for-x-number-of-days?forum=winserverDS
Mahesh