如何使用Powershell枚举IIS网站并为每个网站找到应用程序池? [英] How do I enumerate IIS websites using Powershell and find the app pool for each?

查看:128
本文介绍了如何使用Powershell枚举IIS网站并为每个网站找到应用程序池?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以使用以下方式搜索网站

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

如何将它们链接在一起以查找哪个应用程序池与哪个网站相关联?这是带有IIS 7.5的Windows Server 2008 R2服务器.

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.

推荐答案

尝试以下操作:

[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.

这篇关于如何使用Powershell枚举IIS网站并为每个网站找到应用程序池?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆