Author Posts

February 16, 2017 at 6:48 am

Hi,
I have a script by which I can get the folder size locally & from shared path.
When I give a single machine name to get the folder size, it is giving me the values. But if I loop through multiple servers, it is showing as 0.

Set-Location C:
$finalout = @()
$customers = @()

foreach ($server in $opsservers){
$servername = $server.column1
$customers += @(Get-ChildItem -Path \\$servername\c$\inetpub\wwwroot\ops | select -expand Name)
$customers = $customers -replace "`n|`r"
foreach ($client in $customers){
Write-Host "Working on $servername : $client..."
$folders = Get-ChildItem -Path \\$servername\c$\inetpub\wwwroot\ops\$client\$client -Recurse | Measure-Object -property length -sum

$sanfolders = Get-ChildItem -Path \\opsprdfs\ops\prd\CustomerFiles\$client -Recurse | Measure-Object -property length -sum
Write-Host "Working on $servername : $client...SAN"
$foldersize = "{0:N2}" -f ($folders.sum + $sanfolders.sum / 1MB)

It says: Some part of the path does not exists. If the sub folder is empty, it says read error as-well.
-Kalyan

February 16, 2017 at 7:34 am

Don posted a folder size function time ago. This might help you.
Get-FolderSize