How to find Inactive AD users and disable them using PowerShell script

preview_player
Показать описание
Inactive users are created in AD and not used for certain number of days. Its a security risk leaving the inactive users in AD.
How to find the inactive users in AD using powershell.
Search-ADAccount -AccountInactive -TimeSpan 60 -UsersOnly | Where-Object { $_.Enabled -eq $true } | Format-Table Name, UserPrincipalName, DistinguishedName
How to disable these inactive users in AD using powershell
Search-ADAccount -AccountInactive -TimeSpan 60 -UsersOnly | Where-Object { $_.Enabled -eq $true } | Disable-ADAccount
Рекомендации по теме
Комментарии
Автор

the search above included accounts that neve logon. How do you separate them? Instead of disable them, how do you move inactive account to inactive OU?

miravida
Автор

There is an Ad for the next video that comes up and covers your video text right when the most important commands come up. Need to change that. Thanks

RichyK
Автор

Sir what is the meaning of search-AdAccount -AccountInactive -([Timespan]16d) -usersonly

charithareddy