17

I can search for websites using:

Get-WmiObject -Namespace "root\WebAdministration" -Class Site -Authentication PacketPrivacy -ComputerName $servers

And I can list the app pools using:

Get-WmiObject -computer $servers -Namespace root\MicrosoftIISv2 -Class IIsApplicationPoolSetting -Impersonation Impersonate -Authentication PacketPrivacy

How can I link these together to find which app pool is associated to which website? It's a Windows Server 2008 R2 server with IIS 7.5.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Chris Reeve
  • 229
  • 1
  • 2
  • 8

3 Answers3

29

Use the webadministration module:

Import-Module WebAdministration

dir IIS:\Sites # Lists all sites
dir IIS:\AppPools # Lists all app pools and applications


# List all sites, applications and appPools

dir 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
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Avner
  • 4,286
  • 2
  • 35
  • 42
  • The topic starter is asking for remote connection with variable $servers. Your solution does not seem to provide the remote connection option. – meir Jun 24 '18 at 07:52
5

Try the following:

[Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
$sm = New-Object Microsoft.Web.Administration.ServerManager
foreach($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.

JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
Kev
  • 118,037
  • 53
  • 300
  • 385
5

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

Import-Module IISAdministration

$site = Get-IISSite -Name 'my-site'
$appPool = Get-IISAppPool -Name $site.Applications[0].ApplicationPoolName
KyleMit
  • 30,350
  • 66
  • 462
  • 664