Forum Discussion
dannytveria
Aug 26, 2021Brass Contributor
Disable and removal of Computer accounts
Hi, I made a script to disable old computer accounts. My Sysadmin asked me to disable after 180 days and remove them after a year. My goal is to disable computer accounts after 180 days and export...
- Sep 13, 2021
farismalaeb
Sep 03, 2021Iron Contributor
Simply add the OU to the exception list, so you can add extra -or condition
-or ($_.distinguishedname -notlike "*,OU=AnotherOUtoExclude,*")
-or ($_.distinguishedname -notlike "*,OU=AnotherOUtoExclude,*")
dannytveria
Sep 03, 2021Brass Contributor
I didn't understand how to do it
I don't want to see the ou that I exclude at the csv file
I don't want to see the ou that I exclude at the csv file
- dannytveriaSep 05, 2021Brass ContributorYes, the ou matches the filter -notlike.
but I don't want to see their computer accounts - dannytveriaSep 04, 2021Brass ContributorI want script will check in all the domain but not in ou's that I exclude up.
Also I don't want to see the computer accounts in that ou on the csv file - farismalaebSep 04, 2021Iron ContributorThe Question is did the OU match any of the filter
$Computers_For_Action = Search-ADAccount -AccountInactive -DateTime $InactiveDate -ComputersOnly -SearchBase "DC=Test ,DC=local" | Where-Object {($_.distinguishedname -notlike "*,OU=Servers,*") -or ($_.distinguishedname -notlike "*,OU=Test,*") -or ($_.distinguishedname -notlike "*,OU=IT,*") -or ($_.distinguishedname -notlike "*,OU=Laptops,*") -or ($_.distinguishedname -notlike "*,CN=Computers,*")}
Try to run this line alone and then call the $Computers_For_Action variable.