【发布时间】:2017-06-29 02:28:40
【问题描述】:
我正在尝试获取每个文件夹及其其子文件夹的大小以及所有者、路径和上次修改日期 - 深度也最多为 5。我有除了文件夹大小之外的所有内容都已完成我正在尝试以 MB 为单位获取大小
这是我的代码:
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
我试图获得的结构
h:\demo\1st level
h:\demo\1st level\2nd level
h:\demo\1st level\2nd level\3rd level
h:\demo\1st level\2nd level\3rd level\4th level\
h:\demo\1st level\2nd level\3rd level\4th level\5th level
谢谢!
【问题讨论】:
-
我会避免重新发明轮子,只使用
du.exe。 -
@Bill_Stewart 谢谢,但是有什么办法可以解决这个问题吗?我正在尝试获取非常具体的参数。
-
对不起,我不明白你的问题。