Solved

Removing old computer accounts across several domains

Posted on 2013-12-05
6
274 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
ID: 39697848
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
ID: 39698006
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
ID: 39698074
Thanks for the comments so far guys!  Yes footech, they are all in the same forest.
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
LVL 39

Expert Comment

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

Author Comment

by:johnp3472
ID: 39706011
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
ID: 39735584
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Resolve DNS query failed errors for Exchange
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

867 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

21 Experts available now in Live!

Get 1:1 Help Now