gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 01:28:15 25 4
gpt4 key购买 nike

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

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

运行时,我无法找到如何查询此信息:

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

我没有看到这个属性。我不确定此列是否是一个属性,如果不是,是否有最好的方法来检查 AppPools 是否用于超过 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}

关于powershell - IIS 7.5 应用程序池/IIS 管理器 GUI 列 : Applications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10539833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com