Gonzalo Becerra
asked on
List and Filter Folder Size from Multiples Computers
Guys,
I need help to adapt this script to:
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,
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot!! Moeter :)
This is the final script:
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"
}
ASKER
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\L istFolderS ize.ps1:9 char:70
+ if (Get-ChildItem $fol.fullname -recurse | Measure-Object <<<< -property length -sum | ? {$_.sum -gt 50000000})
+ CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException
+ FullyQualifiedErrorId : GenericMeasurePropertyNotF ound,Micro soft.Power Shell.Comm ands.Measu reObjectCo mmand
Measure-Object : Property "length" cannot be found in any object(s) input.
At E:\a-gbecerra\Powershell\L
+ if (Get-ChildItem $fol.fullname -recurse | Measure-Object <<<< -property length -sum | ? {$_.sum -gt 50000000})
+ CategoryInfo : InvalidArgument: (:) [Measure-Object], PSArgumentException
+ FullyQualifiedErrorId : GenericMeasurePropertyNotF
Hi,
do not get the failure, do your have enough rights to these folders with the account your running the script.
Regards
do not get the failure, do your have enough rights to these folders with the account your running the script.
Regards
ASKER
Yes I have permissions to all folders. I have Administrator Account.
ASKER
I have already this script to run in multiples computers:
$Computers = get-content "C:\Computers.txt"
$FolderSize = Invoke-Command -FilePath D:\Scripts\Scripts\Scripti
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\Scripti
But I don't know wich is the property to filter by folders with more that 50 Mb.