PowerShell – Return a list Active Computers for a Department/OU

I needed a script that would return a list active computers for a supplied department or OU (basically the same thing in my use case). This is my solution to that. When supplied a list of Dept abbreviation (OU Name), this function will query AD for all enabled user accounts in the Departments OU.  Then it will run the list of users accounts through the Get-CompByUser function.  The list of computers is then run through Get-CompByActivity to return only active computers.  The actual targetted out will simply be a combination of $Dept and $OUBase parameters:  "OU=$Dept,$OUBase".  I’ve populated the PowerShell Comment Doc, so check out the Examples supplied in there for usage.

Clearly, you could modify this script to target a specific OU and get rid of the $Dept parameter.  Feel free to tweak it to suit your needs, and post back!

Hope it helps others out there. Just add the function to your PowerShell Profile or as a Functions in a script to make it available!

Leave a Reply

Your email address will not be published. Required fields are marked *