我的脚本递归地获取目录名称,LastAccessTime,LastWriteTime和大小等目录信息。 我想知道是否可以获取文件夹所有者名称? 这是我的剧本:
function Get-DirSize {
param([Parameter(Mandatory = $true, ValueFromPipeline = $true)][string]$path)
BEGIN {}
PROCESS{
$size = 0
$folders = @()
foreach ($file in ((Get-ChildItem $path -Force -ea SilentlyContinue))) {
if ($file.PSIsContainer) {
$subfolders = @(Get-DirSize $file.FullName)
$size += $subfolders[-1].Size
$folders += $subfolders
} else {
$size += $file.Length
}
}
$object = New-Object -TypeName PSObject
$object | Add-Member -MemberType NoteProperty -Name Folder `
-Value (Get-Item $path).FullName
$object | Add-Member -MemberType NoteProperty -Name LastAccessTime `
-Value (Get-Item $path).LastAccessTime
$object | Add-Member -MemberType NoteProperty -Name LastWriteTime `
-Value (Get-Item $path).LastWriteTime
$object | Add-Member -MemberType NoteProperty -Name Size -Value $size
$folders += $object
Write-Output $folders
}
END {}
}
答案 0 :(得分:1)
对于每个文件夹,您可以检索AccessControl,然后您拥有所有者:
$acl = $file.GetAccessControl()
$acl.Owner