Three Month Inactive User Need To Be Automatically Disable in AD and run this script automatically.

Noyon Chandra Das 346 Reputation points
2023-11-08T07:37:18.2+00:00

Dear all,

we have run below this command to find out the inactive users:

$DaysInactive = 90 #define days

$time = (Get-Date).Adddays(-($DaysInactive))

Get-ADUser -Filter {LastLogonTimeStamp -lt $time and } -Properties LastLogonTimeStamp | select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv c:\Inactive_UserList.csv -notypeinformation

Also run this command to disable these users:

$USERS = Import-CSV c:\Inactive_UserList.csv

foreach ($USERS in $USERS ) {

Set-ADUSer -Identity $USERS.Name -Enabled $false

Write-Host AD_Account has been sucessfully desabled for $USERS.Name

}

Now we want to do this process automatically on every 7 days later. Please help me to run.

Thanks

Noyon

Windows for business | Windows Client for IT Pros | Directory services | Active Directory
0 comments No comments
{count} votes

Answer accepted by question author
  1. Anonymous
    2023-11-09T03:20:24.07+00:00

    Hello Noyon Chandra Das,

    Thank you for posting in Q&A forum.

    You can create a task schedule on Domain Controller, followed the steps in the link below.

    https://www.windowscentral.com/how-create-automated-tasks-windows-11

    Please note: Information posted in the given link is hosted by a third party. Microsoft does not guarantee the accuracy and effectiveness of information.

    I hope the information above is helpful.

    If you have any question or concern, please feel free to let us know.

    Best Regards,
    Daisy Zhou


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.