Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xWebAppPool and xWebApplication cannot delete entities in use and do nothing #623

Open
i2um1 opened this issue Mar 23, 2023 · 1 comment

Comments

@i2um1
Copy link

i2um1 commented Mar 23, 2023

Problem description

Hi,

I have a self contained ASP.NET Core web application that I host on IIS. The app pool is configured to always running. So, I want to delete the web application using xWebAppPool and xWebApplication. In case, if a web application was in use a few seconds ago, xWebAppPool and xWebApplication does nothing.

Verbose logs

12:25:55       | Instance i-xxxx: Access is denied. The related file/directory is: C:\Site\MySite. The
12:25:55       | related file/directory is:  C:\Site\MySite.  The related ResourceID is [File]DeleteFolder.     +
12:25:55       | CategoryInfo          : PermissionDenied: (:) [], CimException     + FullyQualifiedErrorId : Windows System
12:25:55       | Error 5     + PSComputerName        : localhost   The SendConfigurationApply function did not succeed.     +
12:25:55       | CategoryInfo          : PermissionDenied: (root/Microsoft/...gurationManager:String) [], CimException     +
12:25:55       | FullyQualifiedErrorId : MI RESULT 2     + PSComputerName        : localhost

DSC configuration

Configuration DeleteWebApplication {
    Import-DscResource -Module PSDesiredStateConfiguration
    Import-DscResource -ModuleName xWebAdministration

    xWebApplication DeleteWebApplication {
        Name = $applicationName
        Ensure = 'Absent'
        Website = $webSiteName
        WebAppPool = $applicationName
        PhysicalPath = $applicationPath
    }

    xWebAppPool DeleteAppPool {
        Name = $applicationName
        Ensure = 'Absent'
    }

    File DeleteFolder {
        DestinationPath = $applicationPath
        Ensure = 'Absent'
        Type = 'Directory'
        Recurse = $true
        Force = $true
    }

}

DeleteWebApplication
Start-DscConfiguration -Path .\DeleteWebApplication\ -Wait -Force

Suggested solution

I think the easiest solution is to have any retry strategy because, usually, the second try deletes a web application and an app pool as expected.

Operating system the target node is running

OsName               : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version and build the target node is running

Name                           Value
----                           -----
PSVersion                      5.1.17763.134
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17763.134
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

WebAdministrationDsc version

Name               Version Path
----               ------- ----
xWebAdministration 3.3.0   C:\Program Files\WindowsPowerShell\Modules\xWebAdministration\3.3.0\xWebAdministration.psd1
@i2um1
Copy link
Author

i2um1 commented Apr 12, 2023

I used the following workaround before the script that is more stable:

Import-Module WebAdministration

if ((Get-WebAppPoolState $applicationName -ErrorAction SilentlyContinue) -ne $null) {

    if ((Get-WebAppPoolState $applicationName).Value -ne "Stopped") {
        Stop-WebAppPool $applicationName
    }

    while ((Get-WebAppPoolState $applicationName).Value -ne "Stopped") {
        Start-Sleep -Seconds 1
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant