在 SharePoint Server 中使用我的網站主機 URL 設定 Exchange 自動探索
**適用版本:**SharePoint Server 2013, SharePoint Server 2016
**上次修改主題的時間:**2017-11-02
**摘要:**了解如何設定 Exchange 自動探索,以找出使用者的 SharePoint 我的網站 URL。
在 SharePoint Server 中,我的網站 會提供使用者豐富的社交網路和共同作業功能,讓使用者可透過內容共用、討論及其他功能來執行工作。Exchange Server 2013 自動探索服務會依據提供的使用者名稱和密碼,來設定郵件用戶端和行動裝置上的設定檔設定。您也可以針對 Office 2016 用戶端整合,將自動探索服務設定為更簡單流暢的 我的網站 體驗。例如,Office 2016 用戶端和行動電話應用程式可以根據儲存在 Active Directory Domain Services (AD DS) 中的我的網站主機 URL,使用 Exchange 自動探索來尋找使用者的 我的網站。而不是找出並輸入我的網站主機 URL,使用者的電子郵件地址和密碼是針對下列項目進行設定和佈建的唯一需求:
商務用 OneDrive — 開啟文件並儲存至您的 商務用 OneDrive 位置。
存取裝置上的新聞摘要。
Office Hub — 在 Windows Phone 上設定應用程式。
本文將提供在 SharePoint Server 中使用我的網站主機 URL 來更新 AD DS 的必要步驟。如果您需要分別查看目前的值或取代該值,本文也詳述了擷取或移除目前我的網站主機 URL 的必要步驟。
重要
繼續進行下一節之前,您必須已具備 SharePoint Server,以及已安裝和設定好 Exchange Server 2013 環境。此外,您必須在 SharePoint Server 中安裝和設定 我的網站。如需有關如何實作 我的網站 並擷取我的網站主機 URL 的詳細資訊,請參閱 在 SharePoint Server 中設定「我的網站」。
使用我的網站主機 URL 設定 Exchange 自動探索
若要使用我的網站主機 URL 更新 AD DS,您必須使用 Exchange 管理命令介面在 Exchange Server 電腦上執行指令碼。此程序可協助您建立 PowerShell 指令碼,然後執行指令碼以更新具有指定 URL 值的 AD DS。如有需要,此程序也提供驗證及移除我的網站主機 URL 項目的選擇性步驟。如需如何執行指令碼的詳細資訊,請參閱 Exchange Server 2013 技術文件庫中的<使用 Exchange 管理命令介面撰寫指令碼>。
使用我的網站主機 URL 設定 Exchange 自動探索
在 Exchange Server 2013 電腦上,將下列指令碼的內容複製到記事本。將此檔案儲存到任何位置,並使用 .ps1 副檔名來將其指定為 PowerShell 指令碼。最後,請將檔案重新命名為 SetMySiteHostURLInAD.ps1。
function PrintUsage { @" NAME: SetMySiteHostURLInAD.ps1 SYNOPSIS: The purpose of this script is to set My Site Host URL in Active Directory. This URL will be returned through Exchange Autodiscover. MySiteHostURL - URL of My Site Host to set in Active Directory. Or use -get to get My Site Host URL from Active Directory. Or use -remove to remove My Site Host URL from Active Directory. SYNTAX: SetMySiteHostURLInAD.ps1 "MySiteHostURL" | -get | -remove EXAMPLES: SetMySiteHostURLInAD.ps1 "http://my" SetMySiteHostURLInAD.ps1 -get SetMySiteHostURLInAD.ps1 -remove "@ } function GetConfigurationNamingContextPath { return GetEntryProperty "LDAP://RootDSE" "configurationNamingContext" } function GetExchangePath { param([string]$configurationNamingContextPath) return "LDAP://CN=Microsoft Exchange,CN=Services," + $configurationNamingContextPath } function GetOrganizationContainerPath { param([string]$exchangePath) [string]$organizationContainerPath = "" ([ADSI] $exchangePath).Children | foreach { if (!$organizationContainerPath -and $_.SchemaClassName -eq "msExchOrganizationContainer") { $organizationContainerPath = $_.Path } } return $organizationContainerPath } function GetEntryProperty { param([string]$entryPath, [string]$propertyName) $entry = [ADSI] $entryPath [string]$value = "" trap { continue } $value = $entry.Get($propertyName) return $value } function SetEntryProperty { param([string]$entryPath, [string]$propertyName, [string]$propertyValue) $entry = [ADSI] $entryPath if (!$propertyValue) { $entry.PutEx(1, $propertyName, $null) } else { $entry.Put($propertyName, $propertyValue) } trap { Write-Host "`nError setting property" -ForegroundColor Red continue } $entry.SetInfo() } function AddOrReplaceOrRemoveMySiteHostURL { param([string]$old, [string]$url) [string]$separator = ";" [string]$label = "SPMySiteHostURL" + $separator if (!$old) { if (!$url) { return "" } else { return $label + $url } } [int]$labelPosition = $old.IndexOf($label) if ($labelPosition -eq -1) { if (!$url) { return $old } else { if ($old[$old.Length - 1] -eq $separator) { return $old + $label + $url } else { return $old + $separator + $label + $url } } } [int]$valuePosition = $labelPosition + $label.Length [int]$nextLabelPosition = $old.IndexOf($separator, $valuePosition) if ($nextLabelPosition -eq -1) { if (!$url) { if ($labelPosition -eq 0) { return "" } else { return $old.Substring(0, $labelPosition - 1) } } else { return $old.Substring(0, $valuePosition) + $url } } if (!$url) { return $old.Substring(0, $labelPosition) + $old.Substring($nextLabelPosition + 1) } else { return $old.Substring(0, $valuePosition) + $url + $old.Substring($nextLabelPosition) } } if ($args.Count -ne 1) { Write-Host "`nError: Required argument missing or too many arguments" -ForegroundColor Red PrintUsage exit } if ($args[0] -eq "-?" -or $args[0] -eq "-h" -or $args[0] -eq "-help") { PrintUsage exit } [string]$url = "" if ($args[0] -ne "-r" -and $args[0] -ne "-remove") { $url = $args[0] } Write-Host "`nSetting My Site Host URL in Active Directory..." [string]$configurationNamingContextPath = GetConfigurationNamingContextPath Write-Host "`nConfiguration Naming Context path: $configurationNamingContextPath" [string]$exchangePath = GetExchangePath $configurationNamingContextPath Write-Host "`nExchange path: $exchangePath" [string]$organizationContainerPath = GetOrganizationContainerPath $exchangePath Write-Host "`nOrganization Container path: $organizationContainerPath" [string]$propertyName = "msExchServiceEndPointURL" Write-Host "`nProperty name: $propertyName" [string]$old = GetEntryProperty $organizationContainerPath $propertyName Write-Host "`nOld value: $old" if (!$url) { Write-Host "`nRemoving value" } elseif ($url -eq "-g" -or $url -eq "-get") { Write-Host "" exit } else { Write-Host "`nAdding or replacing value: $url" } [string]$new = AddOrReplaceOrRemoveMySiteHostURL $old $url Write-Host "`nNew value: $new" SetEntryProperty $organizationContainerPath $propertyName $new Write-Host ""
開啟 [Exchange 管理命令介面]。
在 Exchange 管理命令介面中,瀏覽至您儲存指令碼的目錄,並搭配指定的「我的網站主機 URL」來執行指令碼。比方說,如果您的主機 URL 是 https://server/sites/contoso,則 Exchange 管理命令介面中的語法看起來可能像下面這樣:
[PS] C:\> c:\SetMySiteHostURLInAD.ps1 https://server/sites/contoso
請按 ENTER 來執行指令碼,然後使用我的網站主機 URL 更新 AD DS。
若要確認正確的 URL 已更新,請執行下列命令:
[PS] C:\> c:\SetMySiteHostURLInAD.ps1 -get
注意
或者,您可以輸入 [PS] C:> c:\SetMySiteHostURLInAD.ps1 -remove 命令,來移除我的網站主機 URL。
一旦設定了我的網站主機 URL,您也可以在 SharePoint 管理中心網站中的確認該值。在 [應用程式管理] 中,前往 [管理服務應用程式]、[使用者設定檔服務應用程式](或其他可選的使用者設定檔服務應用程式名稱)、[我的網站設定],最後前往 [設定我的網站]。在 [我的網站設定] 頁面上,您會看到 [Active Directory 中的我的網站主機 URL] 欄位已填入您的項目。
注意
[Active Directory 中的我的網站主機 URL] 欄位無法透過管理中心填入,且必須使用前面詳細敘述的程序來提供我的網站主機 URL 的值。