Powershell Get-ChildItem Progress Question

So, I have a set of directories 00-99 in a folder. Each of these directories has 100 subdirectories, 00-99. Each of these subdirectories has thousands of images.

What I'm trying to do is basically get a progress report when calculating the average file size, but I can't get it to work. Here is my current request:

get-childitem <MyPath> -recurse -filter *.jpeg | Where-Object { Write-Progress "Examining File $($_.Fullname)" true } | measure-object -Property length -Average 

This shows me a panel that updates as each of the files is processed, but in the end I don't get any average file size data. It's clear that I'm doing something wrong because I'm trying to hack a Where-Object to print a progress statement, probably a bad idea (tm).

Since there are millions and millions of images, this query obviously requires a VERY LONG time to work. get-childitem will pretty much be the main part of the request time, if I understand correctly. Any pointers to get what I want? AKA, my result ideally:

 Starting... Examining File: \00\00\Sample.jpeg Examining File: \00\00\Sample2.jpeg Examining File: \00\00\Sample3.jpeg Examining File: \00\00\Sample4.jpeg ... Examining File: \99\99\Sample9999.jpg Average File Size: 12345678.244567 

Edit: I can make a simple option:

 get-childitem <MyPath> -recurse -filter *.jpeg | measure-object -Property length -Average 

And then just walk away from my workstation for a day and a half or something like that, but it seems a little ineffective = /

+7
source share
2 answers

Something like that?

 get-childitem -recurse -filter *.exe | %{Write-Host Examining file: $_.fullname; $_} | measure-object -Property length -Average 
+9
source

A bit more detailed progress:

  $ images = get-childitem -recurse -filter * .jpeg

 $ images |  % -begin {$ i = 0} `
 -process {write-progress -activity "Computing average ..." -status "Examining File: $ image.fullpath ($ i of $ ($ images.count))" -percentcomplete ($ i / $ images.count * 100 );  $ i + = 1} `
 -end {write-output "Average file size is: $ ($ images | measure-object -Property length -Average)"}
+3
source

All Articles