我會嘗試使用Get-ChildItem
列出文件和Measure-Object
數大小
$servers = @("server1", "server2")
$sizes = @()
foreach($server in $servers) {
write-host "Server: $server"
$serverSizes = @(gwmi -class Win32_Share -ComputerName $server -filter "Type = 0" |
% {
write-host " share: $($_.Name)"
$s = gci \\$server\$($_.Name) -recurse -force | Measure-Object -Property length -Sum
New-Object PSObject -property @{Name=$_.Name; Server=$server; TotalSize=$s.Sum }
})
if ($serverSizes) {
$totalServerSize = $serverSizes | Measure-Object -Property TotalSize -Sum
$serverSizes += New-Object PSObject -property @{Name="__Total__"; Server=$server; TotalSize=$totalServerSize.Sum }
$sizes += $serverSizes
}
}
然後你可以如請選擇類似的總尺寸:
$sizes |
? { $_.Name -eq '__Total__' } |
Select-Object Server,@{L='Size in MB'; E={$_.TotalSize/1mb}},@{L='Size in GB'; E={$_.TotalSize/1gb}}
你想要的總尺寸是多少?記住你可以很容易地重複計算(例如共享文件夾的子文件夾本身是共享的)。 – Richard 2012-04-30 17:04:49