You are correct! Adding the "-file" parameter killed the errors.
I'll pay attention to Webster's input next. Thanks ever so much for your help. Kurt On Fri, Jul 21, 2017 at 11:28 AM, Devin Rich <dr...@firstelectronic.com> wrote: > Update: I think you are actually just seeing the effect of trying to get the > Length property for directories. Change your Get-ChildItem $CurrentVersion > -recurse to Get-ChildItem $CurrentVersion -recurse -File > > I think you do that and you'll be golden. > > Regarding arrays, yes, its faster to use a Powershell arrayList because you > can just .add() and it doesn't create a whole new variable to hold the > entire contents of your old array. Can be worth looking into. > > > > Original text: > You shouldn't have an error from getting the first 32 of a dir that has less > than 32... > > I just ran ls | Select -First 10000000 on a folder with some files and had > no issues. > > Even running the ls | Select -First 10000 -Expand Length in an empty folder > works fine for me. > > And piping that all to measure-object -sum ).Sum just returns 0. > > > Thanks, > Devin Rich > Systems Administrator > > On Fri, Jul 21, 2017 at 12:03 PM, Kurt Buff <kurt.b...@gmail.com> wrote: >> >> I've restructured this a bit. It now looks like this, but I've run >> into a problem, and I know what it is, but not how to solve it. >> >> The script: >> $CurrentVersions = Get-ChildItem K:\Engdrops -directory -filter >> CurrentVersions -recurse | select -expand fullname >> $CurrentVersionsOut = @() >> foreach ($CurrentVersion in $CurrentVersions) >> { >> $CurrentVersionLargest32 = [math]::Round((Get-ChildItem >> $CurrentVersion -recurse ` >> | Sort-Object length -descending ` >> | select-object -first 32 -expand length | measure-object >> –sum).sum / 1mb) >> $CurrentVersionsOut += [pscustomobject]@{SourceContentPath = ` >> $CurrentVersion; SourceConflictAndDeletedQuotaInMB = >> $CurrentVersionLargest32 } >> } >> $CurrentVersionsOut | export-csv -notype c:\temp\CacheSizes.csv >> >> It works great, unless there are fewer than 32 items in the directory, >> at which point the script emits the following error. >> >> select-object : Property "length" cannot be found. >> At line:3 char:123 >> + ... -descending | select-object -first 32 -expand length | >> measure-object –sum).sum ... >> + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> + CategoryInfo : InvalidArgument: >> (601-1273V4.01c:PSObject) [Select-Object], PSArgumentException >> + FullyQualifiedErrorId : >> ExpandPropertyNotFound,Microsoft.PowerShell.Commands.SelectObjectCommand >> >> >> So, it looks like I need to do some error trapping, and I'd like to >> set a 4096mb default for small or empty directories. >> >> Thoughts? >> >> Kurt >> >> On Thu, Jul 20, 2017 at 8:47 PM, Devin Rich <dr...@firstelectronic.com> >> wrote: >> > Ooops, didn't see you were using -Property from measure-object. >> > >> > Why does spaces in your input object cause it to fail... that's a weird >> > one. >> > ... >> > >> > Thanks, >> > Devin Rich >> > Systems Administrator >> > >> > On Thu, Jul 20, 2017 at 9:44 PM, Devin Rich <dr...@firstelectronic.com> >> > wrote: >> >> >> >> Ok, couple other things :) >> >> >> >> ... select-object -first 32 | measure-object -property length –sum .. >> >> Should be: >> >> ... select-object -first 32 -expand Length | measure-object -property >> >> length –sum ... >> >> >> >> >> >> Next, a lesson on objects. If you have a FileInfo object (like what you >> >> get from Get-ChildItem), you can access its properties (such as length, >> >> fullname, psparentpath, others all shown via Get-Member, etc.). If you >> >> run >> >> your Get-ChildItem | Select -Expand FullName, you no longer have an >> >> object. >> >> You have an array of strings. They no longer have properties to be >> >> accessed. >> >> You can only use $CurrentVersion which is the full path from earlier. >> >> I'd >> >> say keep the Select -Expand FullName from your first line and then get >> >> rid >> >> of the .FullName from accessing the output. >> >> >> >> >> >> >> >> Thanks, >> >> Devin Rich >> >> Systems Administrator >> >> >> >> On Thu, Jul 20, 2017 at 9:30 PM, Devin Rich <dr...@firstelectronic.com> >> >> wrote: >> >>> >> >>> 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. >> >> >> >> >> > >> > >> > 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. >> >> >> >> > > > 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.