2

我想知道如何在没有在 powershell 中确认的情况下删除中央管理 Web 应用程序?我正在使用的脚本(现在所有 Web 应用程序都在未经确认的情况下被删除,只有中央管理 Web 应用程序会请求它)。提前致谢。

function RemoveWebApplications()
{
    WriteFuncInfo "Removing all web applications..."

    $applications = Get-SPWebApplication -IncludeCentralAdministration
    if($applications -eq $null)
    {
        WriteFuncInfo "No web applications found."
        return
    }
    WriteFuncInfo "Removing web applications $($applications.Count):"

    foreach($application in $applications)
    {
        WriteFuncInfo "$($application.Name) with database and iis site"
        Remove-SPWebApplication $application -DeleteIISSite -RemoveContentDatabases -Confirm:$false  
    }   
}    
4

1 回答 1

3

我找到了解决方案,下面是我现在使用的方法:

function RemoveCentralAdministration()
{
    WriteFuncInfo "Removing central administrations:"
    $applications = Get-SPWebApplication -IncludeCentralAdministration | where-object {$_.IsAdministrationWebApplication -eq $true }
    if($applications -eq $null)
    {
        WriteFuncInfo "No central administrations found."
        return
    }
    foreach($application in $applications)
    {
        WriteFuncInfo "$($application.Url)"

        # for central administration web application Remove-SPWebApplication cmdlet requests confiramtion
        # even if parameter '-Confirm:$false' is used

        # Remove-SPWebApplication $application -DeleteIISSite -RemoveContentDatabases -Confirm:$false 
        WriteFuncInfo "`t removing iis site"
        $application.UnprovisionGlobally($true);

        WriteFuncInfo "`t removing databases"
        foreach ($contentDb in $application.ContentDatabases)
        {
            $contentDb.Unprovision();
        }

        $application.Delete();
     }    
}

此解决方案基于“Remove-SPWebApplication”cmdlet 的原始代码。它可以在Microsoft.SharePoint.PowerShell.dll SPCmdletRemoveSPWebApplication中创建。

于 2012-08-02T05:41:05.357 回答