Avatar of johnp3472
johnp3472
 asked on

Removing old computer accounts across several domains

Hello all,

I need to either find a tool (such as ADtidy or oldcomp) or write a powershell script that will allow me to identify and then delete (as required) computer accounts that have not logged into the domain over a given time period.  The real challenge is I need to be able to check across several domains.

I'm using the following powershell script as a basis but this only references one domain:
(Thanks Matt Vogt)

$time = Read-host
$time = get-date ($time) $date = get-date ($time) -UFormat %d.%m.%y
Get-ADComputer -Filter {LastLogonTimeStamp -lt $time} -Properties LastLogonTimeStamp
select-object Name,@{Name="Stamp"; Expression={[DateTime]::FromFileTime($_.lastLogonTimestamp)}} | export-csv .all_old_computers_timestamps

My scripting skills are very rusty so need some help!

Good luck!
Microsoft Legacy OSPowershellActive Directory

Avatar of undefined
Last Comment
johnp3472

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Felix Leven

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
footech

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
johnp3472

ASKER
Thanks for the comments so far guys!  Yes footech, they are all in the same forest.
footech

Did that give you the info you needed or are you still facing issues?
johnp3472

ASKER
Footech,  I still need to set up a clone of one of our DC's.  Until I've done that, I wont be able to test the script.  Occured to me though that I will need some way to authenticate across the domains!  I think I have the required commands.....  Thanks for checking back!  And now it seems my mobo does not support 64bit architecture.  Now waiting for a new 64bit desktop to arrive!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
johnp3472

ASKER
Got everything up and running.  Many thanks to you both MrGraves and Footech.  I am going to go split the points as both were helpful!  Have a great christmas guys!