I would like to implement a script to disable inactive users and exclude the user from disable if the user is one of the members of AD group. Is there a way I can simplify the script below?
$parentOU = ‘OU=test,DC=test1,DC=COM’
$Inactivity = “90.00:00:00”
$GroupName = “GG-EXCLUDE-Users”$members = Get-ADGroupMember -Identity $group -Recursive | Select -ExpandProperty Name
$DisabledUsers = Search-ADAccount -AccountInactive -TimeSpan $Inactivity -UsersOnly
foreach ($DisabledUser in $DisabledUsers){
if (-not (Get-ADUser $DisabledUser -Properties MemberOf).MemberOf -like “$GroupName“){
$DisabledUser|Disable-ADAccount
}
}
Disable inactive users without disabling those in AD group