Alex M
Alex M

Reputation: 2548

Octopus script module wrongly goes into IF

I have a script module in Octopus Deploy, which would create a new web application in IIS. As part of that it also creates an IIS pool, if one doesn't exists already.

function Create-WebApplication($webSite, $alias, $physicalPath, $poolName)
{
    $pool = "IIS:\AppPools\$poolName"
    if (Test-Path $pool)
    {
        Write-Host "IIS pool already exists: $poolName"
    }
    else
    {
        #--Always gets into this else condition, no matter exists or not--
        Write-Host "Creating IIS pool: $poolName"
        New-WebAppPool -Name $poolName
        Set-ItemProperty $pool -Name "managedRuntimeVersion" -Value "v4.0" 
    }
    Write-Host "Creating website: $webSite\$alias"
    New-WebApplication -Name $alias -Site $webSite -PhysicalPath $physicalPath -ApplicationPool $poolName -Force

    Write-Host "Setting the application pool: $poolName"
    Set-ItemProperty IIS:\Sites\$webSite\$alias -name applicationPool -value $poolName -Force
}

The problem is, it always does get into the else condition, where it tries to create the app pool. Same script working fine in PowerShell ISE.

Am I missing something obvious?

Upvotes: 0

Views: 209

Answers (1)

srbrills
srbrills

Reputation: 1557

You will need to import the WebAdministration module to work against the IIS drive, otherwise Test-Path will always fail when checking against it.

Upvotes: 2

Related Questions