Solved

Removing old computer accounts across several domains

Posted on 2013-12-05
6
273 Views
Last Modified: 2013-12-23
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!
0
Comment
Question by:johnp3472
  • 3
  • 2
6 Comments
 
LVL 13

Accepted Solution

by:
Felix Leven earned 250 total points
Comment Utility
I still prefer to do this with the Quest AD cmdlets:

Import the Module:
Add-PSSnapin Quest.ActiveRoles.ADManagement

Open in new window


the cmdlet Get-QADComputer can search for inactive or password not chaged accounts.

Get-QADComputer -Inactive

Open in new window

and
Get-QADComputer -PasswordNotChangedFor

Open in new window


you can connect to different domaints as well:

connect-QADService -Service 'server.domian.local:389'

Open in new window

0
 
LVL 39

Assisted Solution

by:footech
footech earned 250 total points
Comment Utility
I'm assuming you mean all domains are in the same forest.  So really you just need to direct your queries to a DC in each domain using the -server parameter (depending on what you want to do, sometimes you can use a single global catalog instead).  You may also want to look at using the Search-ADAccount cmdlet as it has a -AccountInactive parameter.
$srvs = (Get-ADForest).domains | ForEach { (Get-ADDomain $_).PDCEmulator }
foreach ($srv in $srvs)
{
   #code here
}

Open in new window

0
 

Author Comment

by:johnp3472
Comment Utility
Thanks for the comments so far guys!  Yes footech, they are all in the same forest.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 39

Expert Comment

by:footech
Comment Utility
Did that give you the info you needed or are you still facing issues?
0
 

Author Comment

by:johnp3472
Comment Utility
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!
0
 

Author Comment

by:johnp3472
Comment Utility
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!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Failed 2008r2 6 80
View Security Group Permisssions 6 18
lync 2013 7 30
Exchange server 2010 public folders 1 28
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Synchronize a new Active Directory domain with an existing Office 365 tenant
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now