Hello everyone, Chris Vetter Customer Engineer at Microsoft back again to discuss an all-too-common problem and that is Duplicate Device Hostnames in Microsoft Endpoint Manager Configuration Manager (MEMCM). This commonly tends to happen when performing an OSD Image on a known device (known meaning the device already exists inside your database) without deleting the object out of Active Directory. What we get is duplicate device objects which can cause conflicts when updating policy or collecting inventory and the device record you want updated is not because the action was performed on the duplicate that is not actually associated with the client.
There is no automatic or supported way to detect and remove these duplicate objects but there is a workaround that you can use and even automate depending on how large of an issue this is in your environment. We are going to create a Device Collection of the duplicate device hostnames then use a PowerShell script to remove all the objects from the collection (and the Database) this way the correct object can be added back through discovery.
Step 1: Create Device Collection of Duplicate Hostnames
I am going to assume you know how to create a device collection and if you do not there are many great articles and documents on the web that can show you how, so in this step I will provide the WQL query you can use to populate the collection with the duplicate hostnames.
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 and R.Client is null
Step 2: Run the PowerShell to remove the objects
This is an easy one liner you can run after you connect to the PS Drive of your MEMCM Site which you should be able to do from any machine where you have the MEMCM Admin Console installed.
Get-CMCollectionMember -CollectionName "<Collection Name Here>" | Remove-CMDevice -Force
Depending on how many objects are on your collection will determine how long it will take for the script to complete.
Step 3: Automate
If this is a continuous problem in your environment, I would recommend running this script on a schedule. You can download the complete script here that will connect to the MEMCM PS Drive and run the PowerShell line to remove the objects. How often you need to run it would depend on how quickly the collection you created repopulates. We really should get in the practice of tuning our discovery methods and removing the device from AD to minimize this issue.
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.
All processes and directions are of my own opinion and not of Microsoft and are from my years of experience with the configuration manager product in multiple customer environments.