Link to home
Start Free TrialLog in
Avatar of Gonzalo Becerra
Gonzalo BecerraFlag for Argentina

asked on

List and Filter Folder Size from Multiples Computers

Guys,

I need help to adapt this script to:

 
$out = @()
$startfolder = "D:\Software\*"
$folders = get-childitem $startfolder | where{$_.PSiscontainer -eq "True"}
foreach ($fol in $Folders){
$colItems = (Get-ChildItem $fol.fullname -recurse | Measure-Object -property length -sum)
$size = "{0:N2}" -f ($colItems.sum / 1MB) + "," +" MB"
$out += "$($fol.fullname), $size"
}
$out | out-file FoldersSize.csv

Open in new window


1- Read from multiples computers specify in txt file
2- List Folders only with more than 50 Mb
3- In the Output add one sheet per Server

Thanks in advance,
ASKER CERTIFIED SOLUTION
Avatar of Moeter
Moeter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gonzalo Becerra

ASKER

If not possible with CSV how we can export to excel and make sheets? Because in VBscript we can do but here I don't know.

I have already this script to run in multiples computers:

$Computers = get-content "C:\Computers.txt"
$FolderSize = Invoke-Command -FilePath D:\Scripts\Scripts\Scripting\PowerShell\ListFolderSize.ps1 -ComputerName localhost
foreach ($Computer in $Computers){
$FolderSize #Code is executed here for each computer
#The main difference is the path
$Computer + "  Ready"
}#end foreach

And The Script of FolderSize is:
$ComputerName = (get-wmiobject win32_computersystem).Name
$out = @()
$startfolder = "D:\Software\*"
$folders = get-childitem $startfolder | where{$_.PSiscontainer -eq "True"}
foreach ($fol in $Folders){
$colItems = (Get-ChildItem $fol.fullname -recurse | Measure-Object -property length -sum)
$size = "{0:N2}" -f ($colItems.sum / 1MB) + "," +" MB"
$out += "$($fol.fullname), $size"
}
$out | out-file D:\Scripts\Scripts\Scripting\PowerShell\$ComputerName"-FoldersSize".csv

But I don't know wich is the property to filter by folders with more that 50 Mb.
Thanks a lot!!  Moeter :)


This is the final script:

 
$imtxt = Get-Content c:\computers.txt

foreach ($comp in $imtxt)
{
      $out = @()
      $startfolder = "\\" + $comp +"\D$\Software\*"
      $folders = get-childitem $startfolder | where{$_.PSiscontainer -eq "True"}
      foreach ($fol in $Folders)
      {
            if (Get-ChildItem $fol.fullname -recurse | Measure-Object -property length -sum | ? {$_.sum -gt 50000000})
            {
                  $colItems = (Get-ChildItem $fol.fullname -recurse | Measure-Object -property length -sum)
                  $size = "{0:N2}" -f ($colItems.sum / 1MB)# +" MB"
                  $out += $comp +";"+ $fol.fullname +";"+ $size
                  "Processing " + "Server: " + $comp + "  Folder: " + $fol.fullname
            }
      }
      
      $out | out-file $comp".csv"
      
}

Open in new window

When I run to other machines I have this error. Can you help me why?

Measure-Object : Property "length" cannot be found in any object(s) input.
At E:\a-gbecerra\Powershell\ListFolderSize.ps1:9 char:70
+             if (Get-ChildItem $fol.fullname -recurse | Measure-Object <<<<  -property length -sum | ? {$_.sum -gt 50000000})
    + CategoryInfo          : InvalidArgument: (:) [Measure-Object], PSArgumentException
    + FullyQualifiedErrorId : GenericMeasurePropertyNotFound,Microsoft.PowerShell.Commands.MeasureObjectCommand
Avatar of Moeter
Moeter

Hi,

do not get the failure, do your have enough rights to these folders with the account your running the script.

Regards
Yes I have permissions to all folders. I have Administrator Account.