Link to home
Start Free TrialLog in
Avatar of samiam41
samiam41Flag for United States of America

asked on

Place stale user accounts into "dormant" OU

Hey Experts.  I'm cutting my teeth on PowerShell and wanted some help building this new script.

I'd like the script to disable user accounts that haven't been logged into for 30 or more days.  After disabling it, move it to the "dormant" ou.  Finally output which account(s) were disabled and moved.

Again, pretty new to PowerShell and would appreciate your help!  Thank you experts!

Here is what I've come up with so far but needs tweaking.
Search-ADAccount  -accountinactive -timespan 30 -usersonly -SearchBase "ou=depts,dc=domain"|ft name,userprincipalname,lastlogondate,DistinguishedName|out-file C:\tools\Logs\logon-ad-user.log

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ajit Singh
Ajit Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of samiam41

ASKER

Thanks Kevin.  Checking into your suggestions now.
Thanks for your help!!