How do I enumerate IIS websites using Powershell and find the app pool for each? How do I enumerate IIS websites using Powershell and find the app pool for each? powershell powershell

How do I enumerate IIS websites using Powershell and find the app pool for each?


Use the webadministration module:

Import-Module WebAdministrationdir IIS:\Sites # Lists all sitesdir IIS:\AppPools # Lists all app pools and applications# List all sites, applications and appPoolsdir IIS:\Sites | ForEach-Object {    # Web site name    $_.Name    # Site's app pool    $_.applicationPool    # Any web applications on the site + their app pools    Get-WebApplication -Site $_.Name}


Try the following:

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")$sm = New-Object Microsoft.Web.Administration.ServerManagerforeach($site in $sm.Sites) {    foreach ($app in $site.Applications) {        [PSCustomObject]@{            Application = $site.Name + $app.Path            Pool = $app.ApplicationPoolName        }    }}

The script above lists every site on the server and prints the root application pool name for each site.


Here's another option if you do not want to use the IIS:\ path.

$site = Get-IISSite -Name 'my-site'$appPool = Get-IISAppPool -Name $site.Applications[0].ApplicationPoolName