Quantcast
Viewing all articles
Browse latest Browse all 21975

foreach problem

hello,

i have a ps1 that reads the temp folder of remote computer en displays a list of the size of the folder. to be able to read the temp folder i must have the UNC path to the temp folder of the remote computer and also per users. the script below is almost working but with one problem it finds the UNC c$\Users\user\ but it will fill in every profile's. voor exampel:

C:\Users\test1 test2 test3 test4. instead of C:\Users\test1

how can i fix this?

foreach ($serverName in (get-content c:\servers.txt))

{
    $objProfile = Get-ChildItem "C:\Users\" -Name
  
       $path = “\\$serverName\c$\users\$objProfile AppData\Local\Temp"
   
       $dirSize = Get-ChildItem $path  -recurse -force | select Length  |Measure-Object -Sum ength

       $dirSize.sum = $dirSize.sum/1MB

       $finalResult = “{0:N2} MB” -f $result.sum

       $dataObject = New-Object PSObject

       Add-Member -inputObject $dataObject -memberType NoteProperty -name “ServerName” -value                 $serverName

       Add-Member -inputObject $dataObject -memberType NoteProperty -name “Dir_Size” -value                   $finalResult

       $dataColl += $dataObject 

       $dataObject

}

$dataColl | Out-GridView -Title “Remote Directory Scan Results”

$dataColl | Export-Csv -noTypeInformation -path c:\temp.csv


Viewing all articles
Browse latest Browse all 21975

Trending Articles