如何重命名已分配应用程序的应用程序池?

问题描述 投票:11回答:5

我有一个应用程序池,它已经分配了很多应用程序,它不会让我重命名。

除了删除和创建新的应用程序池之外,还有为我的应用程序池获取新名称吗?我不想去重新分配其中的每个应用程序。

iis application-pool
5个回答
12
投票

将应用程序分配给另一个池,重命名您想要重命名的池。将应用程序重新分配回池中。

IIS不支持其他选项


3
投票

不,没有。

要么使用名称,要么创建新的应用程序池并逐个分配应用程序。

如果您需要在多个服务器上重复它,您甚至可以使用ADSI和JavaScript或VBScript自动执行它:


3
投票

这是我能够解决的最简单的方法,虽然我不相信这不容易。

Import-Module WebAdministration

$oldName = "OldAppPool";
$newName = "NewAppPool";

if(-not (Test-Path IIS:\AppPools\TempPool)){
    New-WebAppPool TempPool
}
$tempAppPool = Get-Item IIS:\AppPools\TempPool

foreach($site in Get-ChildItem IIS:\Sites){
    $apps = $site | Get-ChildItem | Where-Object { $_.ApplicationPool -eq $oldName }

    foreach($app in $apps){
        $path = ("IIS:\Sites\{0}\{1}" -f $site.name, $app.name)
        $path
        Set-ItemProperty $path applicationPool TempPool
    }
}

Set-ItemProperty "IIS:\AppPools\$oldName" -Name name -Value $newName

foreach($site in Get-ChildItem IIS:\Sites){
    $apps = $site | Get-ChildItem | Where-Object { $_.ApplicationPool -eq "TempPool" }

    foreach($app in $apps){
        $path = ("IIS:\Sites\{0}\{1}" -f $site.name, $app.name)
        $path
        Set-ItemProperty $path applicationPool $newName
    }
}

Remove-WebAppPool TempPool

2
投票

我创建了类似的脚本来自动完成这项工作。这与其他答案有点不同:

  • 除Web应用程序外,它适用于WebSites;
  • 它适用于所有池:有和没有分配的应用程序;

Powershell脚本:

Import-Module WebAdministration

Function Rename-AppPool([String]$oldName="", [String]$newName="") {
    if ($oldName -eq "") {
        Write-Warning "Parameter 'oldName' was not provided."
        return
    }

    if ($newName -eq "") {
        Write-Warning "Parameter 'newName' was not provided."
        return
    }

    if(-not (Test-Path "IIS:\AppPools\$oldName")){
        Write-Warning "There is no pool with name '$oldName' to rename. Operation stopped."
        return
    }

    if(Test-Path "IIS:\AppPools\$newName"){
        Write-Warning "Pool with name '$newName' already exists. Operation stopped."
        return
    }

    Write-Output "Renaming app pool '$oldName' to '$newName'"

    $pathsOfPools = New-Object System.Collections.ArrayList

    $listOfSites = Get-ChildItem "IIS:\Sites"

    foreach ($site in $listOfSites) {
        if ($site.applicationPool -eq $oldName) {
            $path = ("IIS:\Sites\{0}" -f $site.name)
            $pathsOfPools.Add($path) | Out-Null
        }

        $apps = $site | Get-ChildItem
        foreach ($app in $apps) {
            if ($app.applicationPool -eq $oldName) {                
                $path = ("IIS:\Sites\{0}\{1}" -f $site.name, $app.name)
                $pathsOfPools.Add($path) | Out-Null
            }
        }
    }

    $tempGuid = [Guid]::NewGuid()
    $tempName = $tempGuid.Guid

    if ($pathsOfPools.Count -gt 0) {

        $pathsOfPools   

        New-WebAppPool $tempName | Out-Null
        Write-Output "Temp app pool '$tempName' has been created"

        Write-Output "Changing apps to Temp pool"
        foreach ($path in $pathsOfPools) {
            Set-ItemProperty $path applicationPool $tempName        
        }
    }

    Set-ItemProperty "IIS:\AppPools\$oldName" -Name name -Value $newName
    Write-Output "Application pool name has been changed"

    if ($pathsOfPools.Count -gt 0) {
        Write-Output "Changing apps to New pool"
        foreach ($path in $pathsOfPools) {
            Set-ItemProperty $path applicationPool $newName     
        }   

        Remove-WebAppPool $tempName 
        Write-Output "Temp pool has been removed"
    }
}

Rename-AppPool "OldName" "NewBetterName"

0
投票

是的,有一个选择。创建虚拟应用程序池或使用DefaultApppool。将现有站点与defaultapppool关联。现在转到原始应用程序池,停止应用程序池并重命名。

将网址关联回重命名的appool。

© www.soinside.com 2019 - 2024. All rights reserved.