为 Exchange 自动发现配置 SharePoint Server 中的“我的网站”主机 URL

适用于:yes-img-132013 yes-img-162016 yes-img-192019 yes-img-seSubscription Edition no-img-sopSharePoint in Microsoft 365

在 SharePoint Server 中,“我的网站”为用户提供了丰富的社交网络和协作功能,使内容共享、讨论和其他功能可供用户完成其工作。 Exchange Server 2013 自动发现服务根据提供的用户名和密码在邮件客户端和移动设备上配置配置文件设置。 还可以配置自动发现服务,以便为 Office 2016 的“我的网站”客户端集成提供更简单、无缝的配置体验。 例如,Office 2016 客户端和移动电话应用可以使用 Exchange 自动发现基于存储在 Active Directory 域服务 (AD DS) 的“我的网站主机 URL”来查找用户的“我的网站”。 配置和预配客户端功能的唯一要求是用户的电子邮件地址和密码,而不是标识和输入“我的网站宿主 URL”,

  • Microsoft OneDrive — 打开文档并将其保存到 OneDrive 位置。

  • 访问设备上的新闻源。

  • Office 中心 - 在 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 命令行管理程序编写脚本

为 Exchange 自动发现配置我的网站宿主 URL 的具体步骤

  1. 在 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 ""
  1. 打开“Exchange 命令行管理程序”。

  2. 在 Exchange 命令行管理程序中,导航到保存脚本的目录,并使用指定的“我的网站主机 URL”运行脚本。 例如,如果主机 URL 为 http://server/sites/contoso,则 Exchange 命令行管理程序中的语法可能如下所示:

[PS] C:\>  c:\SetMySiteHostURLInAD.ps1      http://server/sites/contoso
  1. 按 ENTER 运行脚本,并使用我的网站宿主 URL 更新 AD DS。

  2. 若要验证是否已更新为正确的 URL,请运行以下命令:

[PS] C:\>  c:\SetMySiteHostURLInAD.ps1      -get

(可选)可以输入以下命令删除我的网站宿主 URL:

[PS] C:\>  c:\SetMySiteHostURLInAD.ps1  -remove

配置“我的网站宿主 URL”后,还可以在 SharePoint 管理中心网站中验证值。 在 “应用程序管理”中,转到 “管理服务应用程序”,转到 “用户配置文件服务应用程序 (”或其他为“用户配置文件服务应用程序) ”选择的名称,转到 “我的网站设置”,最后转到 “设置我的网站”。 在 “我的网站设置” 页上,你将看到 Active Directory 字段中的“我的网站主机 URL ”填充了你的条目。

Active Directory 中我的网站宿主 URL

注意

Active Directory 中的我的网站主机 URL”字段无法通过管理中心进行填充,必须使用上述详细流程提供我的网站主机 URL 值。

另请参阅

概念

在 SharePoint Server 中配置“我的网站”