Iis PowerShell:检索应用程序池中的应用程序数
如何通过PowerShell命令检索与特定IIS应用程序池关联的应用程序数 我们可以使用以下方法手动查看关联的应用程序:Iis PowerShell:检索应用程序池中的应用程序数,iis,powershell,application-pool,Iis,Powershell,Application Pool,如何通过PowerShell命令检索与特定IIS应用程序池关联的应用程序数 我们可以使用以下方法手动查看关联的应用程序: Get-Item IIS:\AppPools\AppPoolName 但是,如果要手动选择应用程序列,则不可能。另外,应用程序列未列在| Get Member*中 为什么没有列出该列 如何使用PowerShell查找与特定IIS应用程序池关联的应用程序数 诀窍是:PowerShell建立了所谓的“视图定义文件”,告诉PowerShell如何格式化对象(例如,是否将对象格式化
Get-Item IIS:\AppPools\AppPoolName
但是,如果要手动选择应用程序
列,则不可能。另外,应用程序
列未列在| Get Member*
中
诀窍是:PowerShell建立了所谓的“视图定义文件”,告诉PowerShell如何格式化对象(例如,是否将对象格式化为列表或表格,显示哪些列等)。这些文件可以在
C:\Windows\System32\WindowsPowerShell\v1.0
中找到,并且都以.format.ps1xml
结尾
回答原始问题:文件C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration\iisprovider.format.ps1xml
包含AppPool
类型的视图定义,该类型定义了如下所示的计算列:
<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>
我花了好几个小时处理同一个问题,直到最终找到解决方案。D.R.的回答很有帮助,但对我不起作用。经过一些调整后,我找到了下面的代码,用于检索应用程序池中的应用程序数量 我注意到这部分代码
nd@path!='/'代码>取消计数
$appPool = "REPLACE ME with a value from your app pool"
@(Get-WebConfigurationProperty "/system.applicationHost/sites/site/application[@applicationPool=`'$appPool`']" "machine/webroot/apphost" -name path).Count
我最终得到了以下代码(与上面的代码基本相同,但格式不同)
这将提供您在数组中查看的内容
导入模块WebAdministration
获取子项IIS:\AppPools>>AppPoolDetails.txt
$appPoolDetails = Get-Content .\AppPoolDetails.txt;
$w = ($appPoolDetails |Select-String 'State').ToString().IndexOf("State");
$w = $w -1;
$res1 = $appPoolDetails | Foreach {
$i=0;
$c=0; `
while($i+$w -lt $_.length -and $c++ -lt 1) {
$_.Substring($i,$w);$i=$i+$w-1}}
Write-Host "First Column---";
$res1.Trim();
$j = $w + 1;
$w = ($appPoolDetails |Select-String 'Applications').ToString().IndexOf("Applications");
$w = $w -$j;
$res2 = $appPoolDetails | Foreach {
$i=$j;
$c=0; `
while($i+$w -lt $_.length -and $c++ -lt 1) {
$_.Substring($i,$w);$i=$i+$w-1}}
Write-Host "Second Column---";
$res2.Trim();
$lineLength=0
$appPoolDetails | Foreach {
if($lineLength -lt $_.TrimEnd().Length )
{
$lineLength = $_.TrimEnd().Length;
#Write-Host $lineLength;
}
}
$j = ($appPoolDetails | Select-String 'Applications').ToString().IndexOf("Applications");
$w = $lineLength;
$w = $w -$j;
#Write-Host $j $w;
$res3 = $appPoolDetails | Foreach {
$i=$j;
$c=0; `
while($i+$w -lt $_.length -and $c++ -lt 1) {
$_.Substring($i,$w);$i=$i+$w-1}}
Write-Host "Third Column---";
$res3;
我最近在寻找获取活动应用程序池的方法时遇到了这篇文章。上面提供的信息很好,但我一直在挖掘,看看是否有其他方法获得这些信息。我能够找到一种方法来实现这一点,我使用了以下方法:
Get-IISSite | Select-Object -ExpandProperty Applications | Select-Object Path,ApplicationPoolName
$appPoolInfo = Get-IISSite | Select-Object -ExpandProperty Applications | Select-Object Path,ApplicationPoolName
$appPoolInfo | Select-Object -Unique ApplicationPoolName
我在一台只有一个网站的服务器上测试了这一点,但是如果服务器上有多个网站,您还可以为Select添加virtualdirectory
我还需要获得正在使用的应用程序池的唯一列表,因此我执行了以下操作:
Get-IISSite | Select-Object -ExpandProperty Applications | Select-Object Path,ApplicationPoolName
$appPoolInfo = Get-IISSite | Select-Object -ExpandProperty Applications | Select-Object Path,ApplicationPoolName
$appPoolInfo | Select-Object -Unique ApplicationPoolName
你的回答不会给这个帖子增加任何内容。这应该是一个评论,但遗憾的是你还不能发布它们。。。感谢您指出上述文章存在格式问题。希望我能为解释提供额外的要点,这在许多其他场景中都很有价值。请注意,此答案使用了更新的IISAdministration模块,从IIS 10/Win2016开始提供,而其他答案使用的是现在的遗留WebAdministration模块。