I'm trying to make a filesystem inventory.
This works, it gives me the ower and ACL of each entry
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
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 ? 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. (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}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.