Find Users who didn’t Login for specific period and Move them to Specific OU

One of the requirement i was searching for is to find the users who didn’t login for a long time and to move them to a specific OU to be disabled and deleted  later.

I found this scripts to do that:

To search on the Whole domain:

Search-ADAccount -AccountInactive -TimeSpan 180.00:00:00 | where {$_.ObjectClass -eq ‘user’} | Move-ADObject –TargetPath “OU=

PrepareforDeletion,DC=Contoso,DC=Com”

To search on a specific OU:

Search-ADAccount -AccountInactive -Searchbase "OU=Users,OU=HR users,dc=Contoso,dc=Com" -TimeSpan 180.00:00:00 | where

{$_.ObjectClass -eq ‘user’} | Move-ADObject –TargetPath “OU=PrepareforDeletion,OU=HR Users,DC=Contoso,DC=Com”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: