gpt4 book ai didi

iis - PowerShell:检索AppPool中的应用程序数量

转载 作者:行者123 更新时间:2023-12-03 02:10:05 25 4
gpt4 key购买 nike

如何通过 PowerShell 命令检索与特定 IIS AppPool 关联的应用程序数量?

我们可以使用以下命令手动查看关联的应用程序:

Get-Item IIS:\AppPools\AppPoolName

但是,如果我们想要手动选择Applications列,这是不可能的。此外,Applications 列未在 | 中列出。获取成员(member) *.

  1. 为什么该列未列出?
  2. 如何使用 PowerShell 查找与特定 IIS AppPool 关联的应用程序数量?

最佳答案

技巧是:PowerShell 建立了所谓的“ View 定义文件”,它告诉 PowerShell 如何格式化对象(例如,对象是否格式化为列表或表格、显示哪些列等)。这些文件可以在 C:\Windows\System32\WindowsPowerShell\v1.0 中找到,并且全部以 .format.ps1xml 结尾。

回答原来的问题:文件C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration\iisprovider.format.ps1xml包含AppPool的 View 定义 类型定义了一个计算列,如下所示:

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

这解释了为什么列本身不是 AppPool 类型的成员。现在可以很容易地回答第二个问题,从上面的“scriptlet”中提取必要的代码:

$applicationsInAppPoolCount = @(Get-WebConfigurationProperty `"/system.applicationHost/sites/site/application[@applicationPool=`'$appPool`'and @path!='/']"` "machine/webroot/apphost" -name path).Count

关于iis - PowerShell:检索AppPool中的应用程序数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20636916/

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