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
dannytveria
Sep 02, 2021Brass Contributor
I found the problem the.
I saw that at the CSV file showing the computer accounts that in the OU that I didn't want to delete or disable.
There is a way that this computer account will not show in the disable or remove logs?
I saw that at the CSV file showing the computer accounts that in the OU that I didn't want to delete or disable.
There is a way that this computer account will not show in the disable or remove logs?
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,*")
- 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. - dannytveriaSep 03, 2021Brass ContributorI didn't understand how to do it
I don't want to see the ou that I exclude at the csv file