简体   繁体   English

如何使用 PowerShell 获取目录和元数据的树列表

[英]How can you use PowerShell to get a tree list of directories and metadata

I'd like to generate a tree list of folders and sub-folders as well as the names and owners of the files within them.我想生成一个文件夹和子文件夹的树列表,以及其中文件的名称和所有者。 Eg:例如:

FOLDER

>File0.ppt - Owner0

>SUBFOLDER_1

    >File1.1.docx - Owner_A

    >File1.2.pdf - Owner_B

>SUBFOLDER_2

    >File2.1.xlsx - Owner A

Any ideas how I can get this?任何想法我怎么能得到这个? I know how to get one or the other, but not both.我知道如何获得其中之一,但不能同时获得。

Thanks!谢谢!

There is alternate ways to do it but I tried to respect the output as text.有其他方法可以做到这一点,但我试图将输出视为文本。 As object this would be a one-liner.作为对象,这将是一个单线。

Function Recurse($folder, $lvl) {

    Get-ChildItem -Path $folder -File | ForEach-Object {
        Write-Host "$("  "*$lvl)> $($_.Name) - $((Get-Acl -Path $_.FullName).Owner)"
    }

    Get-ChildItem -Path $folder -Directory | ForEach-Object {
        Write-Host "$("  "*$lvl)> $($_.Name)"
        Recurse -folder $_.FullName -lvl $($lvl+1)
    }
}

$root = Get-Item -Path $path
Recurse -folder $root.FullName -lvl 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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