【问题标题】:IIS 7.5 Application Pools / IIS Manager GUI column: ApplicationsIIS 7.5 应用程序池/IIS 管理器 GUI 列:应用程序
【发布时间】:2012-05-19 08:52:36
【问题描述】:

在 IIS 7.5 管理器 > 应用程序池中查看时,最后一列列出了“应用程序”。此列显示与此 appPool 关联的应用程序池/网站的数量。

我正在尝试弄清楚如何使用 Powershell 查询此列/信息。这里的最终目标是拥有一个我可以运行的脚本,它会告诉我是否有任何应用程序池被用于超过 1 个网站或应用程序。

我在运行时找不到如何查询此信息:

get-itemproperty IIS:\AppPools\(AppPoolName) | format-list *

我没有看到这个属性。我不确定此列是否是一个属性,如果不是,是否有最好的方法来检查 AppPools 是否用于超过 1 个网站/应用程序?

【问题讨论】:

  • Also to Add... 在运行命令 get-itemproperty IIS:\AppPools(AppPoolName) 时,我再次看到了 Applicaitons 列,但我找不到如何查询这些信息。即使将信息保存到变量并通过管道传输到 get-member,我也看不到获取 Applications 列信息的属性。

标签: powershell iis-7.5 powershell-2.0 application-pool


【解决方案1】:

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指定你要查询的apppool名称即可。这是代码的简化版本:

$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" 共享 AppPool "webAppPool"。" } }}
【解决方案2】:

我选择了这个:

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
}

【讨论】:

    【解决方案3】:

    希望我早点看到你的帖子,这就是我最终想出的:

    $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". " 
    }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-26
      • 2023-03-12
      • 1970-01-01
      • 2011-03-10
      • 2011-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多