Windows 如何将IIS应用程序池的应用程序放入阵列中?

Windows 如何将IIS应用程序池的应用程序放入阵列中?,windows,powershell,iis,Windows,Powershell,Iis,要查看IIS:\AppPools\中的所有池及其状态和应用程序,我在PowerShell中使用以下命令: Get-ChildItem –Path IIS:\AppPools\ 该命令的输出按“名称”、“状态”和“应用程序”三列进行排序;它将类似于以下示例: Name State Applications ---- ----- ------------ DefaultAppPool

要查看
IIS:\AppPools\
中的所有池及其状态和应用程序,我在PowerShell中使用以下命令:

Get-ChildItem –Path IIS:\AppPools\
该命令的输出按“名称”、“状态”和“应用程序”三列进行排序;它将类似于以下示例:

Name State Applications ---- ----- ------------ DefaultAppPool Started item AnotherAppPool Started /item/item AnotherAppPool2 Started /item AppPool XYZ Started item 1 item 2 item 3 ... 这很有效-我可以通过此方案获取值
$MY_数组[0…9]。名称
或通过
$MY_数组[0…9]获取状态。状态
。但是我通过获取“应用程序”列来获取空值:
$MY_ARRAY[0…9]。应用程序总是空的


那么,有人知道如何从列“Applications”中获取值吗?

Applications
始终为空的原因是,这实际上不是要返回的对象的属性。此数据是由webadministration模块中的在控制台输出中创建的

如果通过管道将应用程序池对象传送到
Get Member
,则可以查看可用的属性。您会注意到,
应用程序
不作为成员存在。如果从
Get Member

Microsoft.IIs.PowerShell.Framework.ConfigurationElement#system.applicationHost/applicationPools#add
您可以直接转到webadministration模块来仔细查看。通常,您可以在
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\WebAdministration

在模块内部,您将找到一个名为
iisprovider.format.ps1xml
的文件,该文件处理输出格式。如果弹出该窗口并搜索类型名称,您将找到正在运行的代码,以生成您在
Applications
列中看到的输出。表列没有命名,因此您只需数到第三列就可以找到它。看起来像这样

<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>
然后,从技术上讲,您可以将其与
Select Object
一起使用,以创建一个具有计算属性的内联自定义对象,该属性的外观将符合您的要求。差不多


Get ChildItem IIS:\AppPools\|选择名称、状态,@{n='Applications';e={GetAppsInPool-pn$\.Name}

你是想通过
$MY_数组[0…9]访问你的数组吗。Apps
而不是
$MY_数组[0…9]。App
?@HeedfulCrayon:不,这不是我要求的<代码>$MY_数组[0…9]。应用程序只是一个输入错误。您是否执行了路径IIS:\AppPools\并试图从“应用程序”列中获取值?一旦拥有了此数组,您打算对其执行什么操作?我询问的原因是,最好将所有应用程序保存到一个变量中,如so
$iisApps=Get ChildItem-Path IIS:\AppPools
,然后您可以使用其他WebAdministration命令来完成其余的操作,如
Get WebApplication
Get Website
,等等。
<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>
function GetAppsInPool($pn) {
    $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)
    }
}