The $CurrentVersion before your () is wrong. And you don't need the (). Try this for line 1 insde of the Foreach: $CurrentVersionLargest32 = Get-ChildItem $CurrentVersion -recurse | Sort-Object length -descending | select-object -first 32 | measure-object -property length –sum
Of course, you can also do: [int]$CurrentVersionLargest32 = (Get-ChildItem $CurrentVersion -recurse | Sort-Object length -descending | select-object -first 32 | measure-object -property length –sum).sum / 1GB This forces it to round to nearest GB. :) Good luck! Thanks, Devin Rich Systems Administrator On Thu, Jul 20, 2017 at 9:04 PM, Kurt Buff <kurt.b...@gmail.com> wrote: > I have a large directory, with multiple (80+) subdirectories, each of > which has its own subdirectory for which I'm trying to find the > largest 32 items, and sum them. I'm using this article: > https://blogs.technet.microsoft.com/askds/2011/07/13/how-to-determine-the- > minimum-staging-area-dfsr-needs-for-a-replicated-folder/ > to determine the optimum cache size for DFRS for the > sub-sub-directories that will be replicated. > > This works just fine for a single directory: > $CurrentVersion = "K:\Engineering\x1\y1\CurrentVersions" > $CurrentVersionLargest32 = Get-ChildItem $CurrentVersion -recurse | > Sort-Object length -descending | select-object -first 32 | > measure-object -property length –sum > > This fails: > > $CurrentVersions = Get-ChildItem K:\Engineering -directory -filter > CurrentVersions -recurse | select -expand fullname > $CurrentVersionsOut = @() > foreach ($CurrentVersion in $CurrentVersions) > { > $CurrentVersionLargest32 = $CurrentVersion.(Get-ChildItem > $CurrentVersion -recurse | Sort-Object length -descending | > select-object -first 32 | measure-object -property length –sum) > $CurrentVersionCacheSize = > [math]::Round($CurrentVersionLargest32.sum /1gb) > $CurrentVersionsOut += [pscustomobject]@{SourceContentPath = > $CurrentVersion; SourceConflictAndDeletedQuotaInMB = > $CurrentVersionCacheSize } > } > $CurrentVersionsOut | export-csv -notype c:\temp\CacheSizes.csv > > Output looks like this: > "SourceContentPath","SourceConflictAndDeletedQuotaInMB" > "K:\Engineering\x1\y1\CurrentVersions","0" > "K:\Engineering\x2\y2\CurrentVersions","0" > > So, to me, after much testing, it looks like I've got something wrong > with the first line inside the foreach loop, but I've banged my head > against that for several hours, and just can't seem to figure it out. > > Pointer in the correct direction would be much appreciated. > > Kurt > > > > > -- The information contained in this message is privileged, confidential, and protected from disclosure. If you are not the intended recipient, you are hereby notified that any review, printing, dissemination, distribution, copying or other use of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer.