powershell-遍历System.Management.Automation.PSObject

时间:2019-11-01 20:15:32

标签: powershell

作为输出之一的一部分,我得到了以下对象类型。

  

System.Collections.ObjectModel.Collection`1 [System.Management.Automation.PSObject]

我尝试了以下操作,但是,它没有打印任何内容。

$out=$ScriptBlock.Invoke()
Write-Host "type == " $out.GetType()
$out[0].Properties | ForEach-Object {
 $_.Name
 $_.Value
}

1 个答案:

答案 0 :(得分:0)

$out[0]可能没有.Properties成员,或者它不是数组。

尝试让PowerShell描述您所拥有的内容:

# see what's in this 
PS> $out

# if it's an actual array
PS> $out[0] | Get-Member
相关问题