Powershell – List SCCM Duplicates

This is a simple script to list all the SCCM objects that have duplicate names

$Devices = get-cmdevice -fast 

#Find all devices where there is more than one of the same name
$DeviceDuplicates = $Devices |Group-Object -property name |Where-Object  {$_.count -gt 1}

#Take that list and then re-process
#Im sure there is a better way to do this , but it works for me
foreach ($item in $DeviceDuplicates)
    {
    $results= get-cmdevice -fast -Name $item.name 
#doing the Get-CMDevice again will return two or more objects that you can then step through 
     foreach ($item in $results)
         {
           Write-output "$($item.name),$($item.Resourceid),$($item.IsClient),$($item.CNLastOnlineTime)  "  
         }
     }

Now that you have the duplicates, how do you decide what to do with them?

Well first you could decide if any object does not have a client you could delete it?

That’s why I am reporting back $($item.IsClient)

You could also compare the ResourceID as ResourceIDs are never reused, they are always incremented so the one with the highest number is the newest one.

Leave a comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.