0

我正在开发以下 powershell 来报告我的磁盘使用情况,并让我知道哪些文件夹的大小正在发生变化等。

Get-ChildItem -Path "C:\" | 
Select-Object Name,
    @{ 
        Name="Size";
        Expression=
            { 
                [Math]::Round(
                    ((($_ | Get-ChildItem -Recurse | Measure-Object -Sum Length).Sum + 0) / 1GB)
                    , 2)
            }
    }

这个脚本真的很慢......为什么?

Measure-object 每次查看文件夹时都会评估大小吗?

有什么更好的方法来做到这一点?

谢谢

4

1 回答 1

0

You are listing each file system object on C drive and measuring its size, that can take very long time to complete. Two alternatives (there are more):

(Get-PSDrive c).Used/1gb

- and -

$cDrive = (New-Object -ComObject Scripting.FileSystemObject).GetDrive('C')
$used = ($cDrive.TotalSize-$cDrive.FreeSpace)/1gb
$used.ToString('N2')
于 2013-04-17T08:35:30.717 回答