I have a SaaS based website that creates a subdomain for each client (so it creates a website and a pool for each subdomain) and it is hosted on IIS.
I used these two scripts scripts to remove some unused websites & pools (there was +100 subdomain or so).
at first everything seemed fine but after few hrs a lot of websites started not responding although they had nothing to do with the removed sites and they didn't work again unless the pool & website are removed then added again (recycles didn't work).
Why did these scripts cause a problem??
-------------------------------------------------------
Import-Module WebAdministration
Get-Website |
Where-Object {
$_.Name -match '(?i)^.+\.siteName.*$' -and
\# Exclusions (case-insensitive via (?i))
$\_.Name -notmatch '(?i)^firstSubdomain' -and
$\_.Name -notmatch '(?i)^secondSubdomain' -and
$\_.Name -notmatch '(?i)^siteName$'
} |
ForEach-Object {
Write-Host "Removing site: $($\_.Name)"
Remove-Website -Name $\_.Name
}
-------------------------------------------------------
Import-Module WebAdministration
Get-ChildItem IIS:\AppPools |
Where-Object {
$_.Name -match '(?i)^.+\.siteName.*$' -and
\# Exclusions (case-insensitive)
$\_.Name -notmatch '(?i)^firstSubdomain' -and
$\_.Name -notmatch '(?i)^secondSubdomain' -and
$\_.Name -notmatch '(?i)^siteName$'
} |
ForEach-Object {
Write-Host "Removing App Pool: $($\_.Name)"
Remove-WebAppPool -Name $\_.Name
}