IIS 7.5 应用程序池 / IIS 管理器 GUI 列:应用程序

4
在查看IIS 7.5管理器中的应用程序池时,最后一列列出了“应用程序”。该列显示与此appPool相关联的应用程序池/网站的数量。
我试图弄清楚如何使用PowerShell查询此列/信息。最终目标是拥有一个脚本,我可以运行该脚本告诉我是否有任何应用程序池用于超过1个网站或应用程序。
当运行以下命令时,我无法找到如何查询此信息:
get-itemproperty IIS:\AppPools\(AppPoolName) | format-list *

我没有看到这个属性。如果不是属性,有没有更好的方法来检查AppPools是否被用于多个网站/应用程序?


另外要补充的是...在运行以下命令时:get-itemproperty IIS:\AppPools\(AppPoolName)我再次看到了Applications列,但我找不到如何查询该信息的方法。即使将信息保存到变量中并将其传递到get-member,我也找不到获取Applications列信息的属性。 - colo_joe
3个回答

4

Applications属性是在格式文件中定义的,其代码位于iisprovider.format.ps1xml文件中(位于webadmin模块文件夹内)。

        <TableColumnItem>
          <ScriptBlock>
            $pn = $_.Name
            $sites = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool=`'$pn`'and @path='/']/parent::*" machine/webroot/apphost -name name
            $apps = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool=`'$pn`'and @path!='/']" machine/webroot/apphost -name path
            $arr = @()
            if ($sites -ne $null) {$arr += $sites}
            if ($apps -ne $null) {$arr += $apps}
            if ($arr.Length -gt 0) {
              $out = ""
              foreach ($s in $arr) {$out += $s.Value + "`n"}
              $out.Substring(0, $out.Length - 1)
            }
          </ScriptBlock>
        </TableColumnItem>

你可以把代码提取出来,以外部文件形式使用。只需将$pn指定为要查询的应用程序池名称即可。以下是简化版本的代码:
$pn = 'pool1'
$sites = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool='$pn' and @path='/']/parent::*" machine/webroot/apphost -name name
$apps = get-webconfigurationproperty "/system.applicationHost/sites/site/application[@applicationPool='$pn' and @path!='/']" machine/webroot/apphost -name path
$sites,$apps | foreach {$_.value}

希望早点看到你的帖子,以下是我最终得出的结果:(对于格式有限,抱歉)$SiteApps = get-item IIS:\Sites* $arraySize = ($SiteApps.count -1) $i = 0 $t = 0 for ($i=0; $i -le $arraySize; $i ++) #从数组开头开始{ for ($t=($i+1); $t -le $arraySize; $t++) {if ($siteApps[$i].applicationpool -eq $siteApps[$t].applicationpool) {$web1 = $siteApps[$i].name $webappPool = $siteApps[$i].applicationpool $web2 = $siteApps[$t].name $answer = $answer + "网站"$web1"正在与"$web2"共享应用程序池"$webAppPool"。 " }}} - colo_joe

1
我选择了这个:
Import-Module WebAdministration

function Get-WebAppPoolApplications($webAppPoolName) {
    $result = @()

    $webAppPool = Get-Item ( Join-Path 'IIS:\AppPools' $webAppPoolName )
    if ( $webAppPool -ne $null ) {
        $webSites = Get-ChildItem 'IIS:\Sites'
        $webSites | % {
            $webApplications = Get-ChildItem ( Join-Path 'IIS:\Sites' $_.Name ) |
                where { $_.NodeType -eq 'application' }

            $result += $webApplications |
                where { $_.applicationPool -eq $webAppPoolName }
        }
    }

    $result
}

0
希望我早点看到你的帖子,这就是我最终想出来的:
$SiteApps = get-item IIS:\Sites* $arraySize = ($SiteApps.count -1) 
$i = 0 
$t = 0 
for ($i=0; $i -le $arraySize; $i ++) # start at the beg of the array
{ 
for ($t=($i+1); $t -le $arraySize; $t++) 
{
if ($siteApps[$i].applicationpool -eq $siteApps[$t].applicationpool) 
{
$web1 = $siteApps[$i].name 
$webappPool = $siteApps[$i].applicationpool 
$web2 = $siteApps[$t].name $answer = $answer + "The website "$web1" is sharing the AppPool "webAppPool" with website "$web2". " 
}
}
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接