#requires -version 3.0
###############################################################################
# Copyright (c) 201x-2018 leedesmond.com
# All Rights Reserved. Use at your own risk and responsibility.
# Version 1.00
#
# Get a list of mismatched mail(box) enabled user email and SIP addresses
# without SkypeforBusiness or Exchange Server PowerShell modules
#
###############################################################################
#
#
$VerbosePreferenceOld = $VerbosePreference
$VerbosePreference = "Continue"
#
$dtStart = Get-Date
$dtStart
#
$root = [ADSI]''
$searcher = New-Object System.DirectoryServices.DirectorySearcher($root)
$searcher.PageSize = 5000
$users = $searcher.FindAll()
#$users.count #!
#$usersCnt = ( $users | Measure ).count #!
#$i = 1
#
$missMatches = @()
$users | % {
#$pcc = $i/$usersCnt*100
#$pc = "{0:N2}%" -f $($pcc)
#$now = [datetime]::now-$dtStart
#Write-Progress -Activity "Processing record '$($_.samaccountname) $($_.displayname)' $i/$usersCnt" `
#-Status "Percentage completed $pc (start: $dtStart runtime: $now)" `
#-PercentComplete $pcc
#$i++
#
if (
$_.Properties.'msrtcsip-userenabled' -eq "True" -and
(
$_.Properties.'msexchrecipienttypedetails' -eq 1 -or #mailbox user
$_.Properties.'msexchrecipienttypedetails' -eq 128 #mail-enabled User
)
)
{
if ($_.Properties.mail -ne $null)
{
$sipAddr1 = $mail = ""
$mail = $_.Properties.mail
#
$sipAddr = $_.Properties.'msrtcsip-primaryuseraddress'
if ($_.Properties.'msrtcsip-primaryuseraddress' -ne $null)
#if ($sipAddr -ne $null)
{
$sipAddr1 = $($_.Properties.'msrtcsip-primaryuseraddress').
SubString($($_.Properties.'msrtcsip-primaryuseraddress').
ToString().IndexOf(":")+1
)
}
#
if ($sipAddr1 -ne $mail)
{
Write-Verbose "$($sipAddr1)`t$($mail)"
#
$missMatches += [pscustomobject]@{
samaccountname =
$_.Properties.samaccountname
displayname =
$_.Properties.displayname
msexchrecipienttypedetails =
$_.Properties.msexchrecipienttypedetails
msrtcsipprimaryhomeserver =
$_.Properties.'msrtcsip-primaryhomeserver'
sipAddr = $sipAddr1
mail= $mail
}
}
}
}
}
#
$missMatches | ogv -Title "missMatches $($missMatches.count)"
$missMatches | Out-File -Encoding utf8 -FilePath missMatches.txt
#
$dtEnd = Get-Date
$dtEnd
$dtEnd - $dtStart
#
$VerbosePreference = $VerbosePreferenceOld
REFERENCE
From which AD attributes we can identify the user is mail-enabled user or mailbox user ?