Created
June 14, 2016 15:50
-
-
Save davops/060db005e6fe7f9d5b25d16e527b4b0c to your computer and use it in GitHub Desktop.
Deleting sites and application pools from Microsoft IIS using PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Deleting Sites and app pools in IIS 7 with PowerShell | |
$appCmd = "C:\windows\system32\inetsrv\appcmd.exe" | |
#lists all the sites | |
& $appcmd list site | |
#deletes a specific site | |
& $appcmd delete site "Name of site" | |
#deletes a specific application pool | |
& $appcmd delete apppool "Name of app pool" | |
#delete any app pools that use a certain username (in the identity column of the GUI) | |
$account = "TheDomain\TheAccount" | |
$AppPools = & $appcmd list apppool /processModel.userName:$account | |
foreach ($pool in $AppPools){ | |
$pool = $pool.split(" ")[1] #get the name only | |
& $appcmd delete apppool $pool | |
} | |
#delete all app pools that use a certain username except for a given app pool name | |
$account = "TheDomain\TheAccount" | |
$AppPools = & $appcmd list apppool /processModel.userName:$account | |
foreach ($pool in $AppPools){ | |
$pool = $pool.split(" ")[1] #get the name only | |
if ($pool -ne "MyAppPool") | |
{ | |
& $appcmd delete apppool $pool | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
$pool.split(" ")[1] is a bad choice if you have spaces in app pool names. Also i had to remove leading and trailing quotes from $pool or -ne was not ok. Thanks for the script though.