Powershell Group Array

时间:2012-06-26 16:10:46

标签: arrays powershell

我有一个自定义数组

$myresults = @() 
$w3svcID = $result.ReturnValue -replace "IISWebServer=", "" 
$w3svcID = $w3svcID -replace "'", "" 
$vdirName = $w3svcID = "/ROOT"; 
$vdirs = gwmi -namespace "root\MicrosoftIISv2" -class "IISWebVirtualDirSetting" 
foreach($vdir in $vdirs) 
{ 
 $vPool = $vdir.Apppoolid 
 $vName = $vdir.Name 

 $robj = New-Object System.Object  
 $robj | Add-Member -type NoteProperty -name Path -value $vName  
 $robj | Add-Member -type NoteProperty -name Pool -value $vPool  
 $myresults += $robj 
} 
$myresults | group-object Pool

我希望能够以列表的形式对数据进行分组,其中组值(Path)在group-by值(Pool)之下;像这样:

DefaultAppPool
   W3SVC\
   W3VSC\1\ROOT\
MyAppPool
   W3SVC\1\ROOT\MyVirtual\

1 个答案:

答案 0 :(得分:1)

尝试一下:

Get-WmiObject IISWebVirtualDirSetting -Namespace root\MicrosoftIISv2  |
Group-Object AppPoolId | Foreach-Object{
    $_.Name
    $_.Group | Foreach-Object { "`t$($_.Name)" }
}