PowerShell ile Microsoft 365 takma ad adresini birincil SMTP adresine değiştirin
Kuruluş yeni bir birincil SMTP adresi kullanacak. Bu yeni adresi zaten tüm posta kutuları için takma ad adresi olarak ayarladılar. Şimdi bunu birincil SMTP adresiyle değiştirmek istiyorlar. Başka takma ad adresleri varsa bunlara dokunulmaması gerekir. Bu makalede, PowerShell ile Microsoft 365'te takma ad adresini birincil SMTP adresine nasıl değiştireceğinizi öğreneceksiniz.
giriiş
Set-M365PrimaryAddress.ps1 PowerShell betiği Exchange Online (Microsoft 365) için çalışır. Aynısını şirket içi Exchange veya Exchange Karma ortamı için yapmak istiyorsanız PowerShell ile takma ad adresini birincil SMTP adresine değiştirme makalesini okuyun.
Not: Takma ad smtp adresi birincil SMTP adresi olur ve birincil SMTP adresi bir takma ad adresi olur. Dolayısıyla birincil SMTP adresi kaldırılmayacaktır; sadece takma ad smtp adresiyle değiştirilir.
Başlamadan önce
Her posta kutusu için önceden ayarlanmış bir takma ad adresi yoksa ne olur? En iyisi PowerShell ile toplu ikincil SMTP adresi ekleme makalesini incelemektir.
Tüm posta kutuları için takma ad adresinin ayarlandığını doğruladıktan sonra, takma ad adresini birincil SMTP adresiyle değiştirmek için bu makaledeki Set-M365PrimaryAddress.ps1 PowerShell betiğini çalıştırın.
İşinizi tamamladığınızı ve artık bir takma ad adresi olan eski birincil SMTP adresini kaldırmak istediğinizi varsayalım. PowerShell ile ikincil SMTP adresini toplu kaldırma makalesini inceleyebilirsiniz.
Her şeyi anında yapan tek bir komut dosyası yerine, bunu aşamalı olarak yapmak her zaman daha iyidir, böylece her şeyin doğru ayarlandığından emin olursunuz.
Microsoft 365 Birincil SMTP adresini ayarlama PowerShell betiğini hazırlayın
Set-M365PrimaryAddress.ps1 PowerShell betiğini indirin veya aşağıdaki kodu kopyalayıp Not Defteri'ne yapıştırın. Ona Set-M365PrimaryAddress.ps1 adını verin ve C:\scripts klasörüne yerleştirin. Eğer yoksa bir Komut Dosyaları klasörünüz oluşturun.
<#
.SYNOPSIS
Set-M365PrimaryAddress.ps1
.DESCRIPTION
Get the secondary (alias) address from a specified domain and set it as the primary SMTP address
for all mailbox users in Exchange Online (Microsoft 365). If there is no alias address set with
the specified domain, it will skip the user and display a message. The primary SMTP address will
become an alias address and all the secondary email address will remain.
.LINK
www.alitajran.com/change-microsoft-365-alias-address-to-primary-smtp-address/
.NOTES
Written by: ALI TAJRAN
Website: alitajran.com
X: x.com/alitajran
LinkedIn: linkedin.com/in/alitajran
.CHANGELOG
V1.00, 09/01/2024 - Initial version
#>
param (
[Parameter(Mandatory = $true)]
[string]$DomainName,
[switch]$WhatIf
)
# Output will be added to C:\temp folder. Open the log with a text editor.
Start-Transcript -Path C:\temp\Set-M365Primary-SMTP-Address.log -Append
# Specify the domain to set as primary SMTP
$primarySMTPDomain = "@" + $DomainName
# Get all mailbox users
$users = Get-Mailbox -ResultSize Unlimited
foreach ($user in $users) {
$currentPrimarySMTP = $user.PrimarySmtpAddress.ToString()
$allEmailAddresses = $user.EmailAddresses
$aliasAddresses = $allEmailAddresses | Where-Object { $_ -clike "smtp:*$primarySMTPDomain" }
# Check if the current primary SMTP address ends with the specified domain
if ($currentPrimarySMTP -like "*$primarySMTPDomain") {
Write-Host "Skipping $($user.DisplayName) - Primary SMTP already ends with $primarySMTPDomain" -ForegroundColor Yellow
}
elseif ($aliasAddresses.Count -eq 1) {
$newPrimarySMTP = $aliasAddresses -replace "smtp:", "SMTP:"
Write-Host "Updating primary SMTP for $($user.DisplayName) to $newPrimarySMTP" -ForegroundColor Green
# Combine new primary with other addresses (keeping all existing addresses)
$updatedAddresses = @($newPrimarySMTP) + ($allEmailAddresses -replace "SMTP:", "smtp:" | Where-Object { $_ -ne $newPrimarySMTP })
# Set the new primary SMTP address
if ($WhatIf) {
Set-Mailbox -Identity $user -EmailAddresses $updatedAddresses -WhatIf
}
else {
Set-Mailbox -Identity $user -EmailAddresses $updatedAddresses
}
}
elseif ($aliasAddresses.Count -eq 0) {
Write-Host "No alias address found for $($user.DisplayName) - Primary SMTP not updated" -ForegroundColor Cyan
}
else {
Write-Host "Multiple alias addresses found for $($user.DisplayName) - Primary SMTP not updated" -ForegroundColor Red
}
}
Stop-TranscriptMicrosoft 365 Birincil SMTP adresini toplu ayarlama PowerShell betiği
Betik, Microsoft 365 ortamında Exchange Online için çalışır. PowerShell'i yönetici olarak çalıştırın ve Exchange Online PowerShell'e bağlanın.
Connect-ExchangeOnlineBetik yoluna gidin ve Set-M365PrimaryAddress.ps1 betiğini çalıştırın. Komut dosyası, Exchange Online organizasyonundaki tüm posta kutularından geçecektir.
Not: Hiçbir şeyin olmamasını sağlamak amacıyla deneme için bir -WhatIf parametresi vardır ve her şeyin istediğiniz gibi görünüp görünmediğini PowerShell çıkışını bir kez daha kontrol edebilirsiniz. Her şey yolunda göründüğünde -WhatIf parametresini kaldırın ve komut dosyasını yeniden çalıştırın.
C:\scripts\.\Set-M365PrimaryAddress.ps1 -DomainName "exoip.nl" -WhatIfKomut dosyasını -WhatIf parametresi olmadan çalıştırın.
C:\scripts\.\Set-M365PrimaryAddress.ps1 -DomainName "exoip.nl"Bir posta kutusu için birden fazla takma ad adresi mevcutsa, herhangi bir değişiklik uygulanmaz ve inceleyebilmeniz için çıktı bu bilgiyi gösterir.
Bu örnekte, @exoip.nl etki alanına sahip mevcut takma ad adresi, birincil SMTP adresi olarak toplu olarak ayarlanacaktır.
Transcript started, output file is C:\temp\Set-M365Primary-SMTP-Address.log
Multiple alias addresses found for Adam Clark - Primary SMTP not updated
No alias address found for ALI TAJRAN - Primary SMTP not updated
Updating primary SMTP for Alison Bell to SMTP:Alison.Bell@exoip.nl
No alias address found for Grace Rees - Primary SMTP not updated
Skipping Jeff Baker - Primary SMTP already ends with @tajran.com
No alias address found for John Maverick - Primary SMTP not updated
No alias address found for Joshua Hunter - Primary SMTP not updated
Updating primary SMTP for Zoë Roberts to SMTP:Zoe.Roberts@exoip.nl
Transcript stopped, output file is C:\temp\Set-M365Primary-SMTP-Address.logİşte bu!
Devamını oku: PowerShell ile e-posta adreslerini bulun »
Çözüm
PowerShell ile Microsoft 365'te takma ad adresini birincil SMTP adresi olarak toplu olarak nasıl ayarlayacağınızı öğrendiniz. Öncelikle Set-M365PrimaryAddress PowerShell betiğini indirin. Ardından alan adını, posta kutusu takma ad adreslerinde aramasını istediğiniz komuta ekleyin. Son olarak betiği çalıştırın. İlk önce -WhatIf parametresiyle test etmeyi unutmayın.
Bu makaleyi beğendiniz mi? Microsoft Outlook mobil uygulamasından (iOS ve Android) Takma Ad Olarak Gönder seçeneğini de beğenebilirsiniz. Bizi takip etmeyi ve bu makaleyi paylaşmayı unutmayın.