以编程方式更新SharePoint默认备用访问映射

时间:2011-02-19 00:02:01

标签: sharepoint api powershell alternate-access-mappings

我在我安装了SharePoint Services 3.0的IIS服务器上启用了HTTPS,并且我想以编程方式更新单个Web应用程序和我的中央管理实例(两者都在同一台计算机上)的默认备用访问映射。这是我到目前为止的代码(Powershell),它为HTTPS添加了一个映射,但在尝试删除原始代码时出现错误。

这是我的代码:

[void][system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")

$SPWebServiceCollection = new-object Microsoft.SharePoint.Administration.SPWebServiceCollection ([Microsoft.SharePoint.Administration.SPFarm]::Local)

    foreach ($SPWebService in $SPWebServiceCollection) {

        foreach ($webApplication in $SPWebService.WebApplications) {

            Write-Host ('Updating {0}' -f $webApplication.Name)

            foreach ($alternateUrl in $webApplication.AlternateUrls) {

                $incomingUrl = [System.URI] $alternateUrl.IncomingUrl

                $newURL = 'https://{0}{1}' -f  $incomingUrl.Authority, $incomingUrl.PathAndQuery

                $newAltURL = New-Object Microsoft.SharePoint.Administration.SPAlternateUrl ($newURL, $alternateUrl.UrlZone)

                $webApplication.AlternateUrls.Add($newAltURL)

                $webApplication.AlternateUrls.Update($true)

                $webApplication.AlternateUrls.Remove($alternateUrl) #Throws Exception

                $webApplication.AlternateUrls.Update($true)
           }
        }
    }

以下是我尝试删除原始文件时出现的错误:

  

使用“1”参数调用“Remove”的异常:“SharePoint管理框架中的对象,”SPAlternateUrlCollection Name = SharePoint - 1000 Parent = SPFarm Name = SharePoint_Config_8ddd3701-a332-4e79-98e4-fa11c1b6c17c“,can不能删除,因为其他对象依赖于它。更新所有这些依赖项以指向null或不同的对象并重试此操作。依赖对象如下:

     

SPWebApplication Name = SharePoint - 1000 Parent = SPWebService

但是,我不知道怎么做异常所暗示的。

2 个答案:

答案 0 :(得分:0)

啊......看起来您正在尝试删除Web服务正在使用的URL ...

答案 1 :(得分:0)

事实证明,我忽略了退出默认条​​目的另一种方法:

$webApplication.AlternateUrls.SetResponseUrl($newAltURL)


[void][system.reflection.assembly]::LoadWithPartialName("Microsoft.Sharepoint")

$SPWebServiceCollection = new-object Microsoft.SharePoint.Administration.SPWebServiceCollection ([Microsoft.SharePoint.Administration.SPFarm]::Local)

foreach ($SPWebService in $SPWebServiceCollection) {

    foreach ($webApplication in $SPWebService.WebApplications) {

        Write-Host ('Updating {0}' -f $webApplication.Name)

        foreach ($alternateUrl in $webApplication.AlternateUrls) {

            $incomingUrl = [System.URI] $alternateUrl.IncomingUrl

            $newURL = 'https://{0}{1}' -f  $incomingUrl.Authority, $incomingUrl.PathAndQuery

            $newAltURL = New-Object Microsoft.SharePoint.Administration.SPAlternateUrl ($newURL, $alternateUrl.UrlZone)

            $webApplication.AlternateUrls.SetResponseUrl($newAltURL)

            $webApplication.AlternateUrls.Update($true)
       }
    }
}