各メールボックス セットのプライマリ SMTP アドレスとエイリアス アドレスはすでに持っています。ただし、タスクは、エイリアス アドレスをプライマリ SMTP アドレスと交換することです。これを行う最良の方法は、PowerShell を使用することです。この記事では、PowerShell を使用して Exchange Server のエイリアス アドレスをプライマリ SMTP アドレスに変更する方法を説明します。
導入
Set-PrimaryAddress.ps1 PowerShell スクリプトは次の場合に機能します。
- オンプレミスで交換する
- 交換ハイブリッド
Exchange Online (Microsoft 365) 環境でも同じことを行う場合は、「PowerShell を使用して Microsoft 365 エイリアス アドレスをプライマリ SMTP アドレスに変更する」の記事をお読みください。
注記:エイリアス SMTP アドレスはプライマリ SMTP アドレスになり、プライマリ SMTP アドレスはエイリアス アドレスになります。したがって、プライマリ SMTP アドレスは削除されません。エイリアスの SMTP アドレスと交換されるだけです。
始める前に
すべてのメールボックスにエイリアス アドレスがまだ設定されていない場合はどうなりますか?最善の方法は、「PowerShell を使用してセカンダリ SMTP アドレスを一括追加する」の記事を読むことです。
すべてのメールボックスにエイリアス アドレスが設定されていることを確認したら、この記事の Set-PrimaryAddress.ps1 PowerShell スクリプトを実行して、エイリアス アドレスをプライマリ SMTP アドレスと交換します。
作業が完了し、現在エイリアス アドレスになっている古いプライマリ SMTP アドレスを削除したい場合は、「PowerShell を使用してセカンダリ SMTP アドレスを一括削除する」の記事を参照してください。
すべてが正しく設定されていることを確認するには、1 つのスクリプトですべてをすぐに実行するよりも、これを段階的に実行する方が常に優れています。
Set-PrimaryAddress.ps1 PowerShell スクリプトをダウンロードするか、以下のコードをコピーしてメモ帳に貼り付けます。名前を付けてくださいSet-PrimaryAddress.ps1そしてそれをC:スクリプトフォルダー。を作成しますスクリプトフォルダーがない場合は。
<#
.SYNOPSIS
Set-PrimaryAddress.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 Server and Exchange Hybrid. 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-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, 06/04/2024 - Initial version
V1.10, 09/03/2024 - Added parameters
#>
param (
[Parameter(Mandatory = $true)]
[string]$DomainName,
[switch]$WhatIf,
[switch]$Remote
)
# Output will be added to C:temp folder. Open the log with a text editor.
Start-Transcript -Path C:tempSet-Primary-SMTP-Address.log -Append
# Ensure the domain starts with '@'
$PrimarySMTPDomain = "@" + $DomainName
# Choose the appropriate cmdlets based on the switch
if ($Remote) {
$GetMailboxCmdlet = "Get-RemoteMailbox"
$SetMailboxCmdlet = "Set-RemoteMailbox"
}
else {
$GetMailboxCmdlet = "Get-Mailbox"
$SetMailboxCmdlet = "Set-Mailbox"
}
# Get all mailbox users
$users = Invoke-Expression "$GetMailboxCmdlet -ResultSize Unlimited"
foreach ($user in $users) {
$currentPrimarySMTP = $user.PrimarySmtpAddress.ToString()
$aliasAddresses = $user.EmailAddresses | Where-Object { $_ -clike "smtp*" -and $_ -clike "*$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:", ""
Write-Host "Updating primary SMTP for $($user.DisplayName) to $newPrimarySMTP" -ForegroundColor Green
# Set the new primary SMTP address
if ($WhatIf) {
Invoke-Expression "$SetMailboxCmdlet -Identity '$($user.Identity)' -PrimarySmtpAddress '$newPrimarySMTP' -EmailAddressPolicyEnabled `$false -WhatIf"
}
else {
Invoke-Expression "$SetMailboxCmdlet -Identity '$($user.Identity)' -PrimarySmtpAddress '$newPrimarySMTP' -EmailAddressPolicyEnabled `$false"
}
}
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-Transcriptプライマリ SMTP アドレスの一括設定 PowerShell スクリプト
このスクリプトは、Exchange オンプレミス環境と Exchange ハイブリッド環境で機能します。 Exchange 管理シェルを管理者として実行することが重要です。
スクリプト パスに移動し、Set-PrimaryAddress.ps1 スクリプトを実行します。スクリプトは、Exchange 組織内のすべてのメールボックスを通過します。
C:scripts.Set-PrimaryAddress.ps1 -DomainName "exoip.nl" -WhatIfExchange ハイブリッド環境のクラウド メールボックスを対象とする場合は、-リモートパラメータ。これは、すべてのクラウド メールボックスを取得するために Get-Mailbox から Get-RemoteMailbox に変更され、クラウド メールボックスに変更を適用するために Set-Mailbox が Set-RemoteMailbox に変更されます。
C:scripts.Set-PrimaryAddress.ps1 -DomainName "exoip.nl" -Remote -WhatIf注記:があります-もしも何も起こらないようにドライ ランのパラメーターを変更し、すべてが希望通りであるかどうかを PowerShell 出力で再確認できます。すべてが順調に見えたら、-もしもパラメータを変更してスクリプトを再実行します。
もっと詳しく知る:Exchange で PowerShell を使用してすべての SMTP (電子メール) アドレスを取得する
C:scripts.Set-PrimaryAddress.ps1 -DomainName "exoip.nl"メールボックスに複数のエイリアス アドレスが存在する場合、変更は適用されず、出力にはその情報が表示されるので、それを調べることができます。
この例では、ドメイン @exoip.nl を持つ既存のエイリアス アドレスがプライマリ SMTP アドレスとして一括設定されます。
Transcript started, output file is C:tempSet-Primary-SMTP-Address.log
Multiple alias addresses found for Alysia Maverick - Primary SMTP not updated
No alias address found for Boris Campbell - Primary SMTP not updated
Updating primary SMTP for Christopher Payne to [email protected]
No alias address found for Discovery Search Mailbox - Primary SMTP not updated
Updating primary SMTP for James Paterson to [email protected]
No alias address found for Fraser, Max - Primary SMTP not updated
Updating primary SMTP for Nicholas Murray to [email protected]
No alias address found for Richard Hunter - Primary SMTP not updated
No alias address found for sharedmailboxonprem - Primary SMTP not updated
Transcript stopped, output file is C:tempSet-Primary-SMTP-Address.log既存の smtp エイリアス アドレスが、すべてのユーザーのプライマリ SMTP アドレスになりました。
結論
PowerShell を使用してエイリアス アドレスをプライマリ SMTP アドレスとして一括設定する方法を学習しました。まず、Set-PrimaryAddress PowerShell スクリプトをダウンロードします。次に、メールボックスのエイリアス アドレスで検索するドメインをコマンドに追加します。最後にスクリプトを実行します。最初に -WhatIf パラメーターを使用してテストすることを忘れないでください。
この記事は気に入りましたか?同じエイリアスで共有メールボックスを作成することもおすすめです。ぜひフォローしてこの記事をシェアしてください。











![電話番号なしでWhatsAppを使用する方法[4つの方法]](https://elsefix.com/images/5/2024/10/1728030782_use-whatsapp-without-phone-number.jpg)

