相关疑难解决方法(0)

并非显示所有属性

当我们尝试通过管道将数据导出到其他函数时,我们在PowerShell中观察到一些奇怪的行为.

示例代码:

$Array = @()

$Obj1 = [PSCustomObject]@{
    Member1   = 'First'
    Member2   = 'Second'
}

$Obj2 = [PSCustomObject]@{
    Member1   = 'First'
    Member2   = 'Second'
    Member3   = 'Third'
}

$Array = $Obj1, $Obj2
$Array | Out-GridView -Title 'Not showing Member3'

$Array = $Obj2, $Obj1
$Array | Out-GridView -Title 'All members correctly displayed'
Run Code Online (Sandbox Code Playgroud)

在上面的示例中,您可以看到当第一个对象仅包含2时properties,Out-GridViewCmdLet(和其他)仅显示2 properties,即使第二个对象具有3 properties.但是,当数组中的第一个对象有3时,properties它会正确地显示它们.

有没有解决的办法?因为不可能预先properties确定一个物体上有多少物体,并且物体中最多的物体properties将是第一个物体array.

arrays powershell properties

6
推荐指数
1
解决办法
618
查看次数

标签 统计

arrays ×1

powershell ×1

properties ×1