我正在尝试获取每个文件夹及其子文件夹的大小以及所有者、路径和上次修改日期 - 深度最多为 5。除了文件夹的大小之外,我已经完成了所有内容,我正在尝试获取大小(以 MB 为单位)。我正在使用 PowerShell 4。我试图获取的结构:
The structure I am trying to obtain:
Date Modified Owner FullName Size
------------- ----- -------- ------
06/26/2017 /Users/demo/main/1slevel 12.0MB
06/26/2017 /Users/demo/main/1slevel/2nlvel 8.0MB
06/26/2017 /Users/demo/main/1slevel/2nlvel/3rdlvel 5.0MB
06/26/2017 /Users/demo/main/1slevel/2nlvel/3rdlvel/4thlev
06/26/2017 /Users/demo/main/1slevel/2nlvel/3rdlvel/4thlev/5thlevl
06/26/2017 /Users/demo/main/uns
06/26/2017 /Users/demo/main/uns/swan
06/26/2017 /Users/demo/main/uns/swan/drins
06/26/2017 /Users/demo/main/uns/swan/drins/furth
06/26/2017 /Users/demo/main/uns/swan/drins/furth/firf
我目前拥有的代码:
Function Get-Depth {
Param(
[String]$Path = '/Users/demo/main',
[String]$Filter = "*",
[Int]$ToDepth = 4,
[Int]$CurrentDepth = 0
)
#incrimintation
$CurrentDepth++
#obtains the path and passes the filter values. KEEP in mind that level 1 is 0.
Get-ChildItem $Path | %{
$_ | ?{ $_.Name -Like $Filter }
#if thier is a folder, use the depth and run function until to depth value is 4
If ($_.PsIsContainer) {
If ($CurrentDepth -le $ToDepth) {
# Call to function
#adds the filter values and depth to the path..
Get-Depth -Path $_.FullName -Filter $Filter `
-ToDepth $ToDepth -CurrentDepth $CurrentDepth
}
}
}
}
#just calling the function and and adding what we want!
Get-Depth|? {$_.PsIsContainer}| select @{Name='Date Modified';
Expression={$_.LastWriteTime.ToString('MM/dd/yyyy')}},
@{Name='Owner'; E={(($_.GetAccessControl().Owner.Split('\'))[1])}}, Fullname
提前谢谢您!