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

 

**上一次修改主题:**2017-11-02

**摘要:**了解如何配置 Exchange 自动发现以查找用户的 SharePoint“我的网站”URL。

在 SharePoint Server 中,我的网站为用户提供了丰富的社交网络和协作功能,使他们可以使用内容共享、讨论和其他功能来完成作业。Exchange Server 2013 自动发现服务根据提供的用户名和密码在邮件客户端和移动设备上配置个人资料设置。还可通过配置自动发现服务为 Office 2016 客户端集成实现简单无缝的我的网站配置体验。例如,Office 2016 客户端和移动电话应用可以使用 Exchange 自动发现根据 Active Directory 域服务 (AD DS) 中存储的“我的网站”主机 URL 查找用户的我的网站。只需用户的电子邮件地址和密码,即可配置和预配客户端功能来执行以下操作,而不用标识和输入“我的网站”主机 URL:

  • 使用 OneDrive for Business 打开文档并将其保存到 OneDrive for Business 位置。

  • 访问设备上的新闻源。

  • 使用 Office 中心在 Windows Phone 上安装应用程序。

本文介绍了为 AD DS 更新 SharePoint Server 中的“我的网站”主机 URL 所需的步骤。本文还分别详细介绍了在需要查看当前值或替换当前值时检索或删除当前“我的网站”主机 URL 所需的步骤。

重要

必须已安装和配置 SharePoint Server 和 Exchange Server 2013 环境,才能继续阅读下一部分。此外,还需要在 SharePoint Server 中安装和配置My Sites。若要详细了解如何实现My Sites及如何检索“我的网站”主机 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 ""
    
  2. 打开 Exchange 命令行管理程序。

  3. 在 Exchange 命令行管理程序中,转到保存脚本的目录,然后运行包含指定的我的网站主机 URL 的脚本。例如,如果主机 URL 为 https://server/sites/contoso,此语法在 Exchange 命令行管理程序中可能如下所示:

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

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

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

    备注

    (可选)可以输入命令 [PS] C:> c:\SetMySiteHostURLInAD.ps1 -remove 删除我的网站主机 URL。

配置“我的网站”主机 URL 后,还可在 SharePoint 管理中心网站中验证此值。从“应用程序管理”依次转到“管理服务应用程序”、“User Profile Service 应用程序”(或 User Profile Service 应用程序的其他选定名称)、“我的网站设置”和“设置我的网站”。在“我的网站设置”页上,你会发现“Active Directory 中的我的网站主机 URL”字段已填充为你输入的内容。

My Site Host URL in Active Directory

备注

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

See also

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