Loop not working properly

Tagged: 

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Olaf Soyk Olaf Soyk 5 months, 1 week ago.

  • Author
    Posts
  • #64330
    Profile photo of Venkata Kalyan
    Venkata Kalyan
    Participant

    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

  • #64336
    Profile photo of Olaf Soyk
    Olaf Soyk
    Participant

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

You must be logged in to reply to this topic.