Sign in to follow this  
Followers 0
Airwolf

ADUC Computers OU Cleanup UDF

3 posts in this topic

#1 ·  Posted (edited)

I created this UDF based on a script I wrote to automatically remove stale entries from Active Directory, specifically in the Computers OU. I'd love to add more functions and increase the use of this UDF so if anybody has anything they'd like me to add please speak up and I'll work on it. :P

Just to give you an idea of what this UDF does, here are the function headers:

#cs

===================================================================================

_findComputers($daysold, $dc, $domain, $suffix, $arraymax = 100000)

$daysold - the function will find machines that have not connected in over this many days

$dc - name of domain controller

$domain - name of domain but not the domain suffix

$suffix - the domain suffix (i.e. com, org, net, loc)

$arraymax - the maximum number of machines able to fit into the array, default is 100,000

The function returns an array of machine names based on the number of days it has been since

the machines last authenticated to a domain controller. For Example:

$oldmachines = _findComputers(70,"dc1","company","com")

The $oldmachines variable is the returned array from the _findComputers() function.

===================================================================================

#ce

#cs

===================================================================================

_deleteComputers($array, $dc, $domain, $suffix)

$array - the function will delete machine names within this array

$dc - name of domain controller

$domain - name of domain but not the domain suffix

$suffix - the domain suffix (i.e. com, org, net, loc)

The function deletes machine accounts for computers within $array. For Example:

_deleteComputers($oldmachines,"dc1","company","com")

===================================================================================

#ce

You can use this against multiple domain controllers as well and just compare the arrays. This would allow you to only remove machines that haven't authenticated to any domain controller within the specified time frame. I made the find and delete functions separate so that you can dump the array to a file to check its validity if you so desire before toasting half of your Computers OU. :)

LDAP_Computer_Cleanup_UDF.au3

Edited by Airwolf123

Certifications: A+, Network+, Security+, Linux+, LPIC-1, MCSA | Languages: AutoIt, C, SQL, .NETBooks: AutoIt v3: Your Quick Guide - $7.99 - O'Reilly Media - September 2007-------->[u]AutoIt v3 Development - newbie to g33k[/u] - Coming Soon - Fate Publishing - Spring 2013UDF Libraries: SkypeCOM UDF Library | ADUC Computers OU Cleanup | Find PixelChecksumExamples: Skype COM Examples - Skype4COMLib Examples converted from VBS to AutoIt

Share this post


Link to post
Share on other sites



It'd be nice to have it scan all the OU's and output the OU to a spreadsheet.

I have this, but it'd be cool if there was a way to use all the OU's.

#include <LDAP_Computer_Cleanup_UDF.au3>
#include <Excel.au3>

$daysold = InputBox("Age of stale computers","In days, how far back to you want to search AD?")
$dc = InputBox("Domain Controller","Please enter Domain Controller name.")
$cdomain = InputBox("Domain","Please enter the child domain.")

$oldComp = _FindComputers($daysold,$dc,$cdomain,"tcaps","net",2500)

$nExcel = _ExcelBookNew()
$exArray1 = _ExcelWriteArray($nExcel,1,1,$oldComp,1)

Share this post


Link to post
Share on other sites

I created this UDF based on a script I wrote to automatically remove stale entries from Active Directory, specifically in the Computers OU. I'd love to add more functions ...

Hi Airwolf,

Just wanted to let you know that there is a UDF available for a lot of Active Directory functions. For download please see my signature.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0