Hello everyone!

As you know, when the time comes, your manager may want you to generate a report based on local administrators of each computer in your domain and since we are too lazy to do a ‘Right-click > Manage’ for each computer via ADUC, we will do this in my may and it is nothing but PowerShell.

Actually, back in 2013 we prepared a script for querying local administrators of each computer. What it did was connecting to each computer and generate a list of local administrators and save it as text. Yuuuuck! Text files! Not our type of thing anymore! OK, a couple of days ago, when we were browsing threads and profile, we noticed the noobish script which we had it uploaded back in 2013, has been downloaded 10,000 times! Wow, that was amazing!

So we said if there are so many guys out there who want to have a list of local administrators, why not ease up the process for them? To sum up, we decided to edit my script and add some glowing and fun stuff to that in order to make it super easy to run and handy dandy for your reports.

Anyways, for today, we are going to learn how we can have a list of local administrators of a selected PC, or selected PCs or all PC’s out there in your domain. Basically everything related to local admins and PC’s. Let’s jump in!

Ok! What we want to is to download the script we wrote from this link and make sure to vote it up. Believe me, if you do not vote, it will not work and your local admin reports will be empty! :D

Once you have this script downloaded, copy that to a folder on your DC, or even your PC with RSAT enabled.

Then you should do something which is called dot sourcing. It is not a complex thing to do, just navigate to the folder containing the script and type the name along with extension (Hit Tab key if you are as lazy as me) and place a simple dot and space at the beginning of name and tap Enter. Sounds a bit strange? Look at the picture below:

Now we are ready to run the script. If you want to have a list of local admins for all computers in your domain, the only thing you want to do is to run this script in a simple mode with no parameters. But let’s say that you want to run this query against an OU which contains 100 computers. In that case, we have to use –Path parameter and specify the DN of that OU. In order to get DN of the OU, you can proceed like this:

Now you have the DN in the clipboard, go ahead and fire the script with –path parameter and paste the DN in front of it and hit Enter. Don’t forget to quote the DN.

Once you hit Enter, you can see that query is in running mode and you can verify it by the progress bar at top. Also, it will keep you informed by showing the computer which it is currently working on. If the computer is in red color, it means there is something wrong with that computer (Offline, Firewall, Network…), but if it is green, you are having a wonderful life!

The script is done and our report is generated. Navigate to the folder again and you will see that the report is ready in a folder. The folder name is a combination of date and time, so it should be fairly easy to find that.

If you open the report folder, you will face two files. One which is called Report and is in CSV format and the second is called ErrorLog. The error log is basically a TXT file which contains the computer accounts with failed attempt. So you can reuse that file later.

It is finished! If you are a stylish guys like us, feel free to change the theme of that CSV file to impress your manager.

Have fun querying!

P.S : Sorry if images are blurred, we had to run the query in a production environment to have best result!