gpt4 book ai didi

powershell - 寻求对 Powershell ExpandProperty 行为的解释

转载 作者:行者123 更新时间:2023-12-03 09:36:02 26 4
gpt4 key购买 nike

我只是很好奇,正在寻找对 expandProperty 行为的解释。转变。

有时:

some-command | select-object property1, property2 -expand property3

会给:
Property1 Property2 property3
aaaaaaa bbbbbb c
aaaaaaa bbbbbb d

但是,有时您会得到:
Property3
c
d

说明上述内容的真实示例:
Get-Acl | select PSChildname, owner -ExpandProperty Access


Get-Acl | select PSChildname, owner -ExpandProperty AccessToString

所以我相信区别在于,在第一个示例中它返回一个对象,而在第二个示例中它只是一组值。我不明白的是为什么这会对输出产生影响?

最佳答案

必须引用 Select-Object 上的文档

Specifies a property to select, and indicates that an attempt should be made to expand that property. Wildcards are permitted in the property name.

For example, if the specified property is an array, each value of the array is included in the output. If the property contains an object, the properties of that object are displayed in the output.


参数的行为取决于指定的属性 类型 .
在您的第一个示例中,您展开 access这是 System.Security.AccessControl.FileSystemAccessRule 的数组符合以下描述:

If the property contains an object, the properties of that object are displayed in the output.


在你的第二个例子中 AccessToString是单个字符串或标量。虽然我找不到任何明确的信息,但 PowerShell 似乎取代了对 -Property 的任何引用。 .

这在 blogs.msdn.microsoft.com 上有一些介绍以及。

If you apply ExpandProperty to a property which is not a collection, it gives you just the values not the object with properties.


所以这与我们在使用 -Expand 时所看到的一致,而不是关于其他指定属性的存在。在非集合属性上。

关于powershell - 寻求对 Powershell ExpandProperty 行为的解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47812439/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com