我正在计算在许多不同服务器上计算所有共享文件夹(管理员共享除外)的总大小(将所有访问的文件合并到NAS盒中以便于备份/恢复)但是我在查找时遇到了一些麻烦解决方案。
我确定这可以在powershell中完成,但我找不到合适的信息让我离开,我现在可以吐出服务器上所有共享的列表,但我不知道从这里去哪里:
$servers =@(
"server1",
"server2")
foreach($server in $servers)
{
get-WmiObject Win32_Share -computerName $server -filter "Type = 0"
}
答案 0 :(得分:1)
我会尝试使用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}}