Here’s a method I used during a new UC rollout to make a one-time pass in AD to clean-up inconsistent or missing SIP addresses. I found it useful later to ID and correct “broken” accounts.
#requires -Version 3 -Modules ActiveDirectory
# using AD mail property as email address (not always same as primary SMTP proxyaddress)
[bool]$useEmailDomain = $false #use email domain as sip domain
[string]$sipDomain = 'riverlive.com' #always use this domain for sip addresses (if not using email domain)
[bool]$useEmailUser = $true #Use email address user as sip user
#[string]$sipUserTemplate '\<GivenName\>\.\<Surname\>' #ADUser properties to use as template (if not using email)
[string]$userSearchRoot = 'OU=accounts,DC=riverlive,DC=com' #Start search here
[string]$userINcludeFilter = '' #mailbox, user
[string]$userEXcludeFilter = ''
[string]$ChangeLog = 'PS:\VAR\SIPAddressChanges.csv' #Valid path to record changes made
$outlist = @()
[string]$newSIP = $null
[string]$changeSip = $null
[string]$newEmail = $null
[string]$remSip = $null
$sipUserS = Get-ADUser -Filter {(ipphone -like '*') -and (ObjectClass -eq 'user') -and (Enabled -eq $true)} -SearchBase $userSearchRoot -Properties mail, ipphone
foreach ($sipUser in $sipUserS)
{
$outLine = New-Object -TypeName PSObject
[Microsoft.Exchange.Data.Directory.Management.Mailbox]$sipUserMB = Get-Mailbox -Identity $sipUser.SamAccountName
#Update SIP address
$newSIP = "SIP:$($sipUser.GivenName).$($sipUser.Surname)@$($sipDomain)"
if ($sipUserMB.EmailAddresses.ProxyAddressString.StartsWith('SIP') -contains $true)
{
$remSip = ($sipUserMB.EmailAddresses | Where-Object -FilterScript {$_.prefix.displayname -eq 'SIP'}).ProxyAddressString
Write-Output 'Remove:'$remSip
Set-Mailbox -Identity $sipUserMB -EmailAddresses @{
Remove = "$remSip"
}
if ($remSip.ToString() -ne $newSIP)
{
$changeSip = ($remSip).ToLower()
Write-Output 'Add Secondary:'$changeSip
Set-Mailbox -Identity $sipUserMB -EmailAddresses @{
Add = "$changeSip"
}
}
}
Write-Output 'Add Primary:'$newSIP
Set-Mailbox -Identity $sipUserMB -EmailAddresses @{
Add = "$newSIP"
}
#Update AD mail address
$newEmail = "$($sipUser.GivenName).$($sipUser.Surname)@$($sipDomain)"
if ($sipUser.mail -ne $newEmail)
{
Write-Output 'Change EMail:'$newEmail
Set-ADUser -Identity $sipUser -EmailAddress $newEmail
}
$outLine | Add-Member -MemberType NoteProperty -Name OLD_SIP -Value $remSip
$outLine | Add-Member -MemberType NoteProperty -Name UPDATED_SIP -Value $changeSip
$outLine | Add-Member -MemberType NoteProperty -Name NEW_SIP -Value $newSIP
$outLine | Add-Member -MemberType NoteProperty -Name OLD_ADMAIL -Value $($sipUser.mail)
$outLine | Add-Member -MemberType NoteProperty -Name NEW_ADMAIL -Value $newEmail
$outLine | Add-Member -MemberType NoteProperty -Name TIMESTAMP -Value (Get-Date).ToString()
$outlist += $outLine
}
$outlist | Export-Csv $ChangeLog -NoTypeInformation -Force -Append