我有以下脚本从C:驱动器检索特定的文件类型,并将特定的文件属性输出到分隔的CSV文件.我希望能够检索文件所有者和作者.很感谢任何形式的帮助.
# PowerShell script to list the .xlsx files under the C Drive
$Dir = get-childitem "C:" -recurse -force
$List = $Dir | where {$_.extension -eq ".xlsx"}
$List |Select-Object fullname, LastAccessTime, LastWriteTime, CreationTime |Export-Csv -path C:\Scripts\xlsx.csv -NoTypeInformation
Run Code Online (Sandbox Code Playgroud)
我发布这个ia就能找到解决方案.我添加@{N='Owner';E={$_.GetAccessControl().Owner}}到select-object字符串.它现在看起来像这样:
@{N='Owner';E={$_.GetAccessControl().Owner}}
Chris Adkins 的答案适用于 PowerShell 5.1,但不适用于使用 PowerShell 7.1 的我。
@{N='Owner';E={$_.GetAccessControl().Owner}}
我发现这在 5.1 和 7.1 版本中都有效:
$List | Select Fullname, LastAccessTime, LastWriteTime, CreationTime, @{N="Owner";E={ (Get-Acl $_.FullName).Owner }}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12311 次 |
| 最近记录: |