• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 158
  • Last Modified:

Active Directory Management

Hi there,

I am trying to configure automatic user account expiration in Windows 2008 R2 Active Directory.  I would like i tot use the DSQuery and DSMod commands.  I have piped a DSMod in a DSQuery but syntax is wrong.  I need it to automatic disable user accounts after 90 days of inactivity.  Can someone help?

Thanks in advance.
0
jasonhdz
Asked:
jasonhdz
3 Solutions
 
Will SzymkowskiSenior Solution ArchitectCommented:
This is very easy to accomplish using Powershell. I have added code below to accomplish what you are looking for...

Import-module activedirectory
$expires = get-date
$UserName = read-host "Enter Username Here"
Set-ADUser $Username -AccountExpirationDate $expires.adddays(90)

This script will do accounts 1 by 1 if you want me to modify it based on a CSV or txt file, please advise.


Will.
0
 
jasonhdzAuthor Commented:
Thanks everyone.

I basically need the script to be able to check:
1.  The last time users in active directory logged in
2.  If this is more than 60 days, then disable the account.

I dont have a X number of static users, it may increase or decrease significantly. that is why i need it to be able to check all users...maybe on a daily basis.

Thanks.
0
 
dave121Commented:
Hi,

You can refer to the link mentioned below for the powershell code-
http://ss64.com/ps/set-adaccountexpiration.html
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now