Use PowerShell to find unmanaged computers

Posted by | · · · | PowerShell · SCCM | No Comments on Use PowerShell to find unmanaged computers

Greetings fellow IT geeks.  Today’s post is centered around PowerShell and a recent request we had from a client.

The Issue

So like many companies out there, there can be many computers in your SCCM database and Active Directory that are one or more of the following:

  • Stale AD Object
  • Non standard computer name (likely meaning it wasn’t built with your awesome automation)
  • Sitting on the Computers container in AD (also likely meaning it wasn’t built with your awesome automation)
  • Inactive or non-existent SCCM client

When looking through your SCCM database or reviewing AD Users and Computers it’s not readily apparent which computers are still legitimate and should be being managed by SCCM.  I have written PowerShell scripts in the past that review AD on a schedule and take action like moving an object into a “Stale” OU for future deletion, or simply emailing the list of stale machines to an Admin to take action.  Today’s script is a seek and report script only but could easily be modified to take any actions you wish once you find the machines that are not being managed.

A Solution

I created a PowerShell script that will look at both AD and SCCM to find machines we are deeming “unmanaged”, gather additional data about the computer, including trying to find out who the last logged on user is and if they are actively logged on, formatting the data and dumping it into 2 difference CSV files.  All objects are crossed referenced from AD and SCCM to gather as much data as we can.  Lastly it generates an HTML report with 2 tables containing said data, then emails this report along with the CSV attachments to the person or DL you wish to notify.

Note: This script was written to run on the SCCM Primary Site server however it could be run remotely using a PSSession, or on a machine that has the SCCM Admin console installed (not tested but should work).

The first thing you will need to do is create a new collection if you don’t already have one that contains all SCCM Computer objects that do not have a client.  Hopefully you already have one as you continue to strive for 100% client saturation, but if not, here’s a Collection query you can use:

The last line of that query is useful when you have non-Windows OS devices like Intune MDM objects. 🙂

Once you have your Collection you will need the Collection ID as a script parameter so make note of it.  You can simply go to the properties of the collection and its right there on the General tab.

Next, save the content at the bottom of this post as a PowerShell script then execute it with the required parameters using an account that has at least Read permissions to SCCM Computer objects, and local Admin permissions to the remote computers/servers.  * The admin permissions are used when trying to connect to the remote machine to find the last logged on user information.

Here’s what an example of the report looks like.  As mentioned above we have split the report in two.  One table/CSV for Stale unmanaged objects, and one for Recent unmanaged objects.  Basically just the two sides of the number of days you choose to look for.

The Stale table:

And underneath that the Recent table:

We have found this to be incredibly helpful in tracking down machines that should be managed and are not, and machines that need to be cleaned up in AD and/or SCCM.

As always you should run this script first in a lab environment before executing in production.  And as always, no warranty is granted for the outcome of this script.  Use at your own will. 🙂


Without further ado, here’s the PowerShell.  If you grab this script and make it better (there’s always a better way) then please drop me a line at Would love to see any evolutions!


No Comments

Comments are closed.