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

前端 未结 3 2167
死守一世寂寞
死守一世寂寞 2021-02-19 20:02

I can search for websites using:

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

3条回答
  •  隐瞒了意图╮
    2021-02-19 20:50

    Try the following:

    [Void][Reflection.Assembly]::LoadWithPartialName("Microsoft.Web.Administration")
    
    $sm = New-Object Microsoft.Web.Administration.ServerManager
    
    foreach($site in $sm.Sites)
    {
        $root = $site.Applications | where { $_.Path -eq "/" }
        Write-Output ("Site: " + $site.Name + " | Pool: " + $root.ApplicationPoolName)
    }
    

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

提交回复
热议问题