16

I have an Application pool that has a lot of applications been assigned to it, it won't let me rename.

Beside delete and creating a new application pool, is there anyway to get a new name for my application pool? I don't want to go and reassign every application in it.

AnonJr
  • 2,759
  • 1
  • 26
  • 39
J - C Sharper
  • 1,567
  • 7
  • 23
  • 36

5 Answers5

24

Assign applications to another pool, rename the one you wanted renamed. Re-assign applications back to your pool.

IIS doesn't support other options

evhen14
  • 1,839
  • 12
  • 16
5

This was the simplest way that I could work it out, although I can't believe this isn't easier.

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
Alexis Coles
  • 1,227
  • 14
  • 19
3

No, there isn't.

Either put up with the name, or create a new App Pool and assign the applications one-by-one.

If you need to repeat it on multiple servers, you can even automate it with ADSI and JavaScript or VBScript:

Stephen Jennings
  • 12,494
  • 5
  • 47
  • 66
Ben
  • 34,935
  • 6
  • 74
  • 113
3

I've created similar script to automate this job. It is a bit different from the other answer here:

  • It works for WebSites in addition to WebApplications;
  • It works for all pools: with and without assigned applications;

Powershell script:

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"
Anton Palyok
  • 1,249
  • 1
  • 16
  • 27
1

Yes, there is an option. Create a dummy app pool or make use of DefaultApppool. Associate the existing site to the defaultapppool . Now go to the original app pool, Stop the app pool and rename.

Associate back the url to the renamed appool.

Pramod Hm
  • 11
  • 1