1
votes

I try to create application pool on the remote computer and if it exists already command fails:

Invoke-Command -ComputerName $ServerName -ScriptBlock {Import-Module WebAdministration;new-WebAppPool $($args[0]) -Force} -ArgumentList $proj

Filename: Error: Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'BIB ' + CategoryInfo : InvalidData: (:) [New-WebAppPool], COMException + FullyQualifiedErrorId : Filename: Error: Cannot add duplicate collection entry of type 'add' with unique key attribute 'name' set to 'BIB ' ,Microsoft.IIs.PowerShell.Provider.NewAppPoolCommand

So, how can I force creating pool if it exists already? Or how can I previously check if it exists?

1

1 Answers

3
votes

Test if the App Pool already exists, if yes, then remove it:

$AppPoolScriptBlock = {
    Import-Module WebAdministration
    if(Test-Path IIS:\AppPools\$($args[0]))
    {
        Remove-WebAppPool $args[0]
    }
    New-WebAppPool $($args[0]) -Force
}

Invoke-Command -ComputerName $ServerName -ScriptBlock $AppPoolScriptBlock -ArgumentList $proj