简体   繁体   English

gci 和 gci -recurse 有不同类型的输出

[英]gci and gci -recurse have different kind of outputs

I'm trying to make a filesystem inventory.我正在尝试制作文件系统清单。

This works, it gives me the ower and ACL of each entry这有效,它给了我每个条目的 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}}

But using -Recurse gives me empty Owner and 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}}

Why does gci is sending something different alon the pipe ?为什么gci在管道上发送不同的东西? How can i fix this ?我该如何解决这个问题? (I don't want to make an array because that would not fit into memory) (我不想创建一个数组,因为它不适合内存)

They are different because one array contains a list of files, but in recurse it is an array of directory objects and each of the directory object contains a list of files.它们是不同的,因为一个数组包含一个文件列表,但在递归中它是一个目录对象数组,每个目录对象都包含一个文件列表。 The code below will do what you wanted.下面的代码会做你想要的。 Please note that path needs to be in quotes if it contains spaces.请注意,如果路径包含空格,则路径需要用引号引起来。

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}}

Expanding on @Edjs-perkums answer , this calls Get-Acl once and expands two of its properties in a second Select-Object in the pipe.扩展 @Edjs-perkums answer ,这会调用一次Get-Acl并在管道中的第二个Select-Object中扩展它的两个属性。 (Also reformatted into multiple lines for clarity, but it's a single pipeline.) (为了清楚起见,也重新格式化为多行,但它是一个单一的管道。)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM