As part of the general maintenance and upkeep of SCCM we have a “Duplicate Host Names” collection in SCCM.
This collection finds duplicate host names but unfortunately does not notify us when one is found. The script below will send an e-mail when the collection membership is greater than 0. We have it set up as a scheduled task that runs daily.
These are the most common duplicate objects. Most likely this occurs due to OSD or conflicting discovery cycles. We basically end up with two computer objects, with the same name/hardware/MAC but different SMSBIOSGUID. It causes much confusion for ConfigMgr because it often doesn’t know how to process the inventory for the phantom object.
https://blogs.technet.microsoft.com/configmgrdogs/2011/12/18/how-to-find-sccm-duplicate-computer-objects/

<# .SYNOPSIS Find duplicate hostnames in SCCM and send an e-mail notification .DESCRIPTION This script will monitor a collection and send an e-mail notification if there are any members .NOTES Author: Josiah Pewterbaugh #> # Load the Configuration Manager module for PowerShell # Enter your site code $SiteCode = "" # Enter your SMS Provider machine name (normally your primary site server) $ProviderMachineName = "" # Customizations $initParams = @{} # Import the ConfigurationManager.psd1 module if((Get-Module ConfigurationManager) -eq $null) { Import-Module "$($ENV:SMS_ADMIN_UI_PATH)\..\ConfigurationManager.psd1" @initParams } # Connect to the site's drive if it is not already present if((Get-PSDrive -Name $SiteCode -PSProvider CMSite -ErrorAction SilentlyContinue) -eq $null) { New-PSDrive -Name $SiteCode -PSProvider CMSite -Root $ProviderMachineName @initParams } # Set the current location to be the site code. Set-Location "$($SiteCode):\" @initParams # Specify the name of your duplicate host names collection $DuplicateHostNames = Get-CmDeviceCollection -Name "" # Determine how many duplicates there are to delete $Math = $DuplicateHostNames.MemberCount / 2 # Build the body of the e-mail $body = "<h2>Found Duplicate Host Names in SCCM</h2>" $body += "<ul><li>There are <b>$Math</b> computer objects to delete.</li></ul>" $body += "In SCCM navigate to the Duplicate Host Names collection, right-click and click show members. Please <b>delete</b> the computer objects that <b>do not have</b> the client installed.<br /><br />" $body += "The Duplicate Host Names collection is located in <b>Device Collections / Folder</b>." # Change the location to suite your needs #Specify e-mail parameters $params = @{ Body = $body BodyAsHtml = $true Subject = "Found Duplicate Host Names in SCCM" From = "from@from.com" # Enter your from e-mail address To = "to@to.com" # Enter your to e-mail address SmtpServer = "mailserver" # Enter your mail server } if ($DuplicateHostNames.MemberCount -gt 0) { Send-MailMessage @params }
If you do not have a “Duplicate Host Names” collection you can create it by adding this query rule to a collection:
select R.ResourceID,R.ResourceType,R.Name,R.SMSUniqueIdentifier, R.ResourceDomainORWorkgroup,R.Client from SMS_R_System as r full join SMS_R_System as s1 on s1.ResourceId = r.ResourceId full join SMS_R_System as s2 on s2.Name = s1.Name where s1.Name = s2.Name and s1.ResourceId != s2.ResourceId
Alternatively you can run this PowerShell command to create the collection for you:
$CollectionName = "Duplicate Host Names" New-CMDeviceCollection -Name "$CollectionName" -LimitingCollectionName "All Systems" -RefreshType Continuous Add-CMDeviceCollectionQueryMembershipRule -CollectionName "$CollectionName" -QueryExpression "select R.ResourceID,R.ResourceType,R.Name,R.SMSUniqueIdentifier, R.ResourceDomainORWorkgroup,R.Client from SMS_R_System as r full join SMS_R_System as s1 on s1.ResourceId = r.ResourceId full join SMS_R_System as s2 on s2.Name = s1.Name where s1.Name = s2.Name and s1.ResourceId != s2.ResourceId" -RuleName "Duplicate Host Names"