Hello,
I have a Problem with my Script. It does not work like I want it to do. I need to write a script which is executed every 7 days. It should deactivate all users (they all start with abc_) in a specific group. They get activated if they are needed and usually they are all deactivated. I want to have a txt file with the DisplayName of all Users which got deactivated if possible. Can someone pls help me?
$SearchBase = 'OU=A,DC=D,DC=F' $SevenDaysBefore = ((Get-Date).Date).AddDays(-7) $ADUserList = Get-ADUser -Filter "enabled -eq '$true' -and DisplayName -like 'abc_*'" -SearchBase $SearchBase -Properties whenChanged, DisplayName foreach ($ADUser in $ADUserList) { if ($ADUser.whenChanged -lt $SevenDaysBefore) { Disable-ADAccount -Identity $ADUser.SamAccountName } }