Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Find duplicate hostnames in SCCM and send an e-mail notification
This script will monitor a collection and send an e-mail notification if there are any members
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 = "" # Enter your from e-mail address
To = "" # Enter your to e-mail address
SmtpServer = "mailserver" # Enter your mail server
if ($DuplicateHostNames.MemberCount -gt 0)
Send-MailMessage @params
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.