Solved

Removing old computer accounts across several domains

Posted on 2013-12-05
6
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 40

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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 40

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

A hard and fast method for reducing Active Directory Administrators members.
Let's recap what we learned from yesterday's Skyport Systems webinar.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlleā€¦
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

626 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