Loop not working properly

Welcome Forums General PowerShell Q&A Loop not working properly

This topic contains 1 reply, has 2 voices, and was last updated by

2 years ago.

  • Author
  • #64330

    Points: 11
    Rank: Member

    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.

  • #64336

    Points: 660
    Helping Hand
    Rank: Major Contributor

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

The topic ‘Loop not working properly’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort