Okay, here are PowerShell scripts and explanations for modifying the SIP address (Session Initiation Protocol address, often used by Lync/Skype for Business/Teams) for users in different Exchange environments.
The SIP address is stored in the proxyAddresses attribute in Active Directory (for on-premises/hybrid) and synchronized/managed as EmailAddresses in Exchange Online. It typically has the format sip:[EMAIL_ADDRESS].
Choose the script based on your environment:
- Exchange Online (Microsoft 365): For cloud-only users or managing attributes directly in the cloud (if not synced).
- Exchange On-Premises / Hybrid (Synced Users): For users managed in your local Active Directory, where changes sync to the cloud via Azure AD Connect.
1. Script for Exchange Online (Using ExchangeOnlineManagement Module)
This script connects to Exchange Online PowerShell and modifies the EmailAddresses property of a mailbox.
<#
.SYNOPSIS
Modifies the SIP address for a user in Exchange Online.
.DESCRIPTION
Connects to Exchange Online, finds the specified user, removes any existing SIP address,
and adds the new specified SIP address to the EmailAddresses (proxyAddresses) attribute.
.PARAMETER UserPrincipalName
The User Principal Name (UPN) or email address of the user to modify.
.PARAMETER NewSipAddress
The new SIP address to set (e.g., [EMAIL_ADDRESS]). The 'sip:' prefix will be added automatically.
.EXAMPLE
.\Set-EXOSipAddress.ps1 -UserPrincipalName "[EMAIL_ADDRESS]" -NewSipAddress "[EMAIL_ADDRESS]"
.NOTES
Requires the ExchangeOnlineManagement PowerShell module (version 3.0.0 or later recommended).
Run PowerShell as an administrator.
You will be prompted to log in to Exchange Online.
Ensure you have the necessary permissions (e.g., Recipient Management role).
This script replaces *any* existing sip: address.
#>
param(
[Parameter(Mandatory=$true)]
[string]$UserPrincipalName,
[Parameter(Mandatory=$true)]
[string]$NewSipAddress
)
# Check if connected, attempt to connect if not
try {
Write-Host "Checking Exchange Online connection..."
Get-EXOMailbox -ResultSize 1 | Out-Null
Write-Host "Already connected to Exchange Online." -ForegroundColor Green
}
catch {
Write-Host "Not connected. Attempting to connect to Exchange Online..."
try {
Connect-ExchangeOnline -ErrorAction Stop
Write-Host "Successfully connected to Exchange Online." -ForegroundColor Green
}
catch {
Write-Error "Failed to connect to Exchange Online. Please ensure the ExchangeOnlineManagement module is installed and you have internet connectivity. Error: $($_.Exception.Message)"
return # Exit the script if connection fails
}
}
# Construct the full new SIP address with the prefix
$FormattedNewSipAddress = "sip:$($NewSipAddress.ToLower())" # Ensure lowercase and add prefix
Write-Host "Processing user: $UserPrincipalName"
try {
# Get the user's current mailbox object and email addresses
$Mailbox = Get-EXOMailbox -Identity $UserPrincipalName -ErrorAction Stop
$CurrentAddresses = $Mailbox.EmailAddresses
# Filter out any existing SIP addresses
$NewAddressList = $CurrentAddresses | Where-Object { $_ -notlike 'sip:*' }
# Add the new SIP address
$NewAddressList += $FormattedNewSipAddress
# Update the mailbox
Write-Host "Setting new SIP address '$FormattedNewSipAddress' for $UserPrincipalName..."
Set-Mailbox -Identity $UserPrincipalName -EmailAddresses $NewAddressList -ErrorAction Stop
Write-Host "Successfully updated SIP address for $UserPrincipalName." -ForegroundColor Green
# Optional: Verify the change
# Write-Host "Verifying update..."
# (Get-EXOMailbox -Identity $UserPrincipalName).EmailAddresses | Where-Object { $_ -like 'sip:*' }
}
catch [System.Management.Automation.CommandNotFoundException] {
Write-Error "Could not find Exchange Online cmdlets (e.g., Get-EXOMailbox). Is the ExchangeOnlineManagement module installed and imported?"
}
catch {
Write-Error "An error occurred while processing $UserPrincipalName. Error: $($_.Exception.Message)"
# You might want to add more specific error handling here
}
# Consider adding Disconnect-ExchangeOnline if you run this as part of a larger automated script
# Disconnect-ExchangeOnline -Confirm:$false
How to Use (Exchange Online):
- Install Module: If you don't have it, open PowerShell as Administrator and run:
Install-Module ExchangeOnlineManagement
- Save: Save the script code above as a
.ps1 file (e.g., Set-EXOSipAddress.ps1).
- Run: Open PowerShell and execute the script, providing the parameters:
.\Set-EXOSipAddress.ps1 -UserPrincipalName "[EMAIL_ADDRESS]" -NewSipAddress "[EMAIL_ADDRESS]"
- Login: You'll likely be prompted to log in with an account that has sufficient permissions in Exchange Online (like Recipient Management or Global Admin).
2. Script for Exchange On-Premises / Hybrid (Synced Users)
For users whose source of authority is your local Active Directory, you must make the change there. This script uses the Active Directory PowerShell module.
<#
.SYNOPSIS
Modifies the SIP address for an Active Directory user.
.DESCRIPTION
Finds the specified user in Active Directory, removes any existing SIP address from the
proxyAddresses attribute, and adds the new specified SIP address.
This is typically used for Exchange On-Premises or Hybrid environments where users are synced from AD.
.PARAMETER UserIdentity
The SamAccountName, DistinguishedName, SID, or UserPrincipalName of the AD user to modify.
.PARAMETER NewSipAddress
The new SIP address to set (e.g., [EMAIL_ADDRESS]). The 'sip:' prefix will be added automatically.
.EXAMPLE
.\Set-ADSipAddress.ps1 -UserIdentity "UserSamAccountName" -NewSipAddress "[EMAIL_ADDRESS]"
.\Set-ADSipAddress.ps1 -UserIdentity "[EMAIL_ADDRESS]" -NewSipAddress "[EMAIL_ADDRESS]"
.NOTES
Requires the Active Directory PowerShell module (usually installed via RSAT or on a Domain Controller).
Run PowerShell with permissions to modify AD user objects (e.g., Account Operators, Domain Admins, or delegated rights).
This script replaces *any* existing sip: address.
Changes may take time to sync to Exchange Online via Azure AD Connect in a hybrid setup.
#>
param(
[Parameter(Mandatory=$true)]
[string]$UserIdentity,
[Parameter(Mandatory=$true)]
[string]$NewSipAddress
)
# Import the Active Directory module if not already loaded
if (-not (Get-Module ActiveDirectory)) {
try {
Import-Module ActiveDirectory -ErrorAction Stop
Write-Host "Active Directory module imported successfully." -ForegroundColor Green
}
catch {
Write-Error "Failed to import Active Directory module. Please ensure RSAT with AD tools is installed or run this on a Domain Controller. Error: $($_.Exception.Message)"
return # Exit script if module cannot be loaded
}
}
# Construct the full new SIP address with the prefix
$FormattedNewSipAddress = "sip:$($NewSipAddress.ToLower())" # Ensure lowercase and add prefix
Write-Host "Processing user: $UserIdentity"
try {
# Get the user object and their current proxy addresses
$ADUser = Get-ADUser -Identity $UserIdentity -Properties proxyAddresses -ErrorAction Stop
if ($null -eq $ADUser) {
Write-Error "User '$UserIdentity' not found in Active Directory."
return
}
$CurrentAddresses = $ADUser.proxyAddresses
# Filter out any existing SIP addresses
# Note: Using -is [array] check because proxyAddresses might be $null or single value
$NewAddressList = @() # Initialize empty array
if ($CurrentAddresses -is [array]) {
$NewAddressList = $CurrentAddresses | Where-Object { $_ -notlike 'sip:*' }
} elseif ($null -ne $CurrentAddresses -and $CurrentAddresses -notlike 'sip:*') {
# Handle case where proxyAddresses is a single, non-SIP string
$NewAddressList = @($CurrentAddresses)
}
# If $CurrentAddresses was null or a single SIP address, $NewAddressList remains empty, which is correct
# Add the new SIP address
$NewAddressList += $FormattedNewSipAddress
# Update the user object in Active Directory
# Using -Replace is generally safer for multi-valued attributes like proxyAddresses
Write-Host "Setting new SIP address '$FormattedNewSipAddress' for '$($ADUser.SamAccountName)'..."
Set-ADUser -Identity $ADUser -Replace @{proxyAddresses = $NewAddressList} -ErrorAction Stop
Write-Host "Successfully updated SIP address for '$($ADUser.SamAccountName)' in Active Directory." -ForegroundColor Green
Write-Host "Allow time for Azure AD Connect to synchronize the change if in a hybrid environment." -ForegroundColor Yellow
}
catch [Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException] {
Write-Error "User '$UserIdentity' not found in Active Directory."
}
catch {
Write-Error "An error occurred while processing $UserIdentity. Error: $($_.Exception.Message)"
# Consider more specific error handling
}
How to Use (On-Premises / Hybrid):
- Requirements: Run this on a machine with the Active Directory PowerShell module installed (like a Domain Controller or a workstation with Remote Server Administration Tools (RSAT) for AD DS installed). You need permissions to modify AD user objects.
- Save: Save the script code above as a
.ps1 file (e.g., Set-ADSipAddress.ps1).
- Run: Open PowerShell (potentially as Administrator depending on your AD permissions setup) and execute the script:
.\Set-ADSipAddress.ps1 -UserIdentity "TheirSamAccountName" -NewSipAddress "[EMAIL_ADDRESS]"
# Or use UPN
.\Set-ADSipAddress.ps1 -UserIdentity "[EMAIL_ADDRESS]" -NewSipAddress "[EMAIL_ADDRESS]"
- Synchronization (Hybrid): If you are in a hybrid environment, wait for the next Azure AD Connect synchronization cycle for the change to appear in Exchange Online/Microsoft 365. You can force a delta sync if needed (
Start-ADSyncSyncCycle -PolicyType Delta).
Important Considerations:
- Permissions: Ensure the account running the script has the necessary permissions (Recipient Management in EXO, AD modification rights on-prem).
sip: Prefix: The scripts automatically add the sip: prefix. Ensure the $NewSipAddress parameter you provide is just the address part (e.g., [EMAIL_ADDRESS]`).
- Testing: ALWAYS test these scripts on a non-production/test user first before running them on important accounts or in bulk.
- Bulk Changes: To modify multiple users, you can wrap these scripts in a loop that reads from a CSV file. The CSV would typically contain columns like
UserIdentity and NewSipAddress.
- Error Handling: The provided scripts have basic
try/catch blocks. You might want to enhance this for production use (e.g., logging errors to a file).
- Hybrid Authority: Double-check where your user objects are mastered. Modifying a synced object directly in Exchange Online using
Set-Mailbox for EmailAddresses often results in the change being overwritten during the next sync from AD. Always change synced objects in the source AD.