[英]gci and gci -recurse have different kind of outputs
我正在尝试制作文件系统清单。
这有效,它给了我每个条目的 ower 和 ACL
Get-ChildItem \\Server\Share\* | Select-Object @{n='Path';e={ (Get-Item $_.PSPath).FullName }}, PSIsContainer, @{n='Owner';e={ (Get-Acl $_).Owner}}, @{n='Accesstostring';e={ (Get-Acl $_).Accesstostring}}
但是使用-Recurse
给了我空的 Owner 和 Accesstostring
Get-ChildItem \\Server\Share\ -Recurse | Select-Object @{n='Path';e={ (Get-Item $_.PSPath).FullName }}, PSIsContainer, @{n='Owner';e={ (Get-Acl $_).Owner}}, @{n='Accesstostring';e={ (Get-Acl $_).Accesstostring}}
为什么gci
在管道上发送不同的东西? 我该如何解决这个问题? (我不想创建一个数组,因为它不适合内存)
它们是不同的,因为一个数组包含一个文件列表,但在递归中它是一个目录对象数组,每个目录对象都包含一个文件列表。 下面的代码会做你想要的。 请注意,如果路径包含空格,则路径需要用引号引起来。
Get-ChildItem \\Server\Share\ -Recurse | Select-Object @{n='Path';e={ $_.FullName }}, PSIsContainer, @{n='Owner';e={ (Get-Acl $_.FullName).Owner}}, @{n='Accesstostring';e={ (Get-Acl $_.FullName).Accesstostring}}
扩展 @Edjs-perkums answer ,这会调用一次Get-Acl
并在管道中的第二个Select-Object
中扩展它的两个属性。 (为了清楚起见,也重新格式化为多行,但它是一个单一的管道。)
Get-ChildItem \\Server\Share\ -Recurse `
| Select-Object @{n='Path';e={ $_.FullName }},
@{n='ACL';e={ (Get-Acl $_.Fullname) }},
PSIsContainer `
| Select-Object Path, PSIsContainer,
@{n='Owner';e={ $_.ACL.Owner}},
@{n='Accesstostring';e={ $_.ACL.Accesstostring}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.