Jump to content

ADUC Computers OU Cleanup UDF


Airwolf
 Share

Recommended Posts

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
Link to comment
Share on other sites

  • 2 years later...

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)
Link to comment
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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...