紀錄一下把 Microsoft 365 / Sharepoint 網站更改 domain name的方式。會需要做這件事情通常跟公司更換 brand name,或者成立新公司等狀況會發生,主要是為了使企業識別一致化。
參考資料
https://learn.microsoft.com/zh-tw/sharepoint/change-your-sharepoint-domain-name
操作就可以,但是人生總有遇到奇奇怪怪的事情的時候
前置作業
需要先從 Microsoft 365 Admin 裡頭先增加 NEW_DOMAIN, 並把 OLD_DOMAIN 改為備援,步驟可以參考前面兩個連結。
> Connect-SPOService -Url "https://OLD_DOMAIN-admin.sharepoint.com"
上面這個步驟會需要做帳號登入驗證,需要有sharepoint admin 權限(最好是整個 365 的 admin 權限)。
排程更改 domain name
> Start-SPOTenantRename -DomainName "NEW_DOMAIN" -ScheduledDateTime "YYYY-MM-DDThh:ii:ss"
我下command 的時候是 2025-07-19T23:xx:xx ,排程預定2025-07-20T12:32:00 執行
> Start-SPOTenantRename -DomainName "NEW_DOMAIN" -ScheduledDateTime "2025-07-20T12:32:00"
結果沒想到出現訊息如下
警告: 請確認您已認真閱讀 [SPO 租用戶重新命名] 並瞭解其對貴組織的影響 https://aka.ms/SPOTenantRename。
確認
確定要執行此動作?
Performing the operation "Start-SPOTenantRename."
[Y] 是(Y) [A] 全部皆是(A) [N] 否(N) [L] 全部皆否(L) [S] 暫停(S) [?] 說明 (預設值為 "Y"): y
CorrelationId: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Start-SPOTenantRename : Error Code: -772,排程日期/時間必須在未來24小時內。
位於 線路:1 字元:1
+ Start-SPOTenantRename -DomainName "NEW_DOMAIN" -ScheduledDateTime "2025 ...
+ \~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~\~
- CategoryInfo : InvalidOperation: (:) [Start-SPOTenantRename],Exception
- FullyQualifiedErrorId : Error Code: -772,排程日期/時間必須在未來24小時內。,Microsoft.Online.SharePoint.PowerShell
.StartSPOTenan tRename
嘗試修改多次時間之後依然會跳出 排程日期/時間必須在未來24小時內 訊息。
期間甚至還認為是不是時區問題,而嘗試將將排程時間做成變數。
> $scheduledTime = (Get-Date).AddHours(19)
> echo $scheduledTime
> Start-SPOTenantRename -DomainName "NEW_DOMAIN" -ScheduledDateTime $scheduledTime
解決方式
後來努力搜尋了網路加上配合詢問 grok.com 之後才得到答案。而且奇妙的是 grok.com 如果是用快速回覆,沒有深度搜尋的話結果一樣是錯的。
Specifies the date-time that the job will be started. This should be at least 24 hours in the future, but no more than 30 days.
所以顯然是power shell回應錯誤訊息的中文翻譯有問題,不應該為排程日期/時間必須在未來24小時內。
上述網址的中文版,翻譯其實也不太精確,仍然有機會被誤導。https://learn.microsoft.com/zh-tw/powershell/module/microsoft.online.sharepoint.powershell/start-spotenantrename?view=sharepoint-ps#-scheduleddatetime
最後把時間指定在 24 hrs 後就沒問題了。
> Start-SPOTenantRename -DomainName "NEW_DOMAIN" -ScheduledDateTime 2025-07-22T02:41:41
警告: 請確認您已認真閱讀 [SPO 租用戶重新命名] 並瞭解其對貴組織的影響 https://aka.ms/SPOTenantRename。
確認
確定要執行此動作?
Performing the operation "Start-SPOTenantRename."
[Y] 是(Y) [A] 全部皆是(A) [N] 否(N) [L] 全部皆否(L) [S] 暫停(S) [?] 說明 (預設值為 "Y"): y
成功
RenameJobID : oooooooo-oooo-oooo-oooo-oooooooooooo
事後可以用 Get-SPOTenantRenameStatus
去檢查更新 domain name 狀態
> Get-SPOTenantRenameStatus
RenameJobId : oooooooo-oooo-oooo-oooo-oooooooooooo
Status : Queued
Requested at : xxxxxxxxxxxxxxxxxxxxx (UTC)
Requested by : admin@OLD_DOMAIN
Scheduled at : xxxxxxxxxxxxxxxxxxxxx (UTC)
New domain name : NEW_DOMAIN
Total sites : 86
Please wait while we fetch the progress of the rename. This could take a few minutes.
In progress : 0
Renamed : 0
Attention required : 0
> Get-SPOTenantRenameStatus
RenameJobId : oooooooo-oooo-oooo-oooo-oooooooooooo
Status : Queued
Requested at : xxxxxxxxxxxxxxxxxxxxx (UTC)
Requested by : admin@OLD_DOMAIN
Scheduled at : xxxxxxxxxxxxxxxxxxxxx (UTC)
New domain name : NEW_DOMAIN
Total sites : 86
Please wait while we fetch the progress of the rename. This could take a few minutes.
In progress : 0
Renamed : 86
Attention required : 0
順利完成的話可以看到全部 site 都已經 Renamed。