Skip to content

Instantly share code, notes, and snippets.

@davops
Created June 14, 2016 15:50
Show Gist options
  • Save davops/060db005e6fe7f9d5b25d16e527b4b0c to your computer and use it in GitHub Desktop.
Save davops/060db005e6fe7f9d5b25d16e527b4b0c to your computer and use it in GitHub Desktop.

Revisions

  1. davops created this gist Jun 14, 2016.
    26 changes: 26 additions & 0 deletions delete_from_IIS.ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #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
    }
    }