Powershell beginner here.
While having a look at this question: Powershell - Search directories - Find specific extension and total files for each directory I came across some PS on another website that goes a little part of the way towards answering the question posed. A little part of this Powershell is below:
Write-Host "Total Size of *.$Extension files: $('{0:N2}' -f (($Files | Measure-Object length -Sum).Sum / 1mb))MB`n`n"
In running the PS from the other webpage (in total. ie not just the quoted line above) I get the desired results indicating a total size for all extensions queried. That's fine, but I need help understanding the line quoted above. I can see that this is what is doing the adding up of file sizes, but...
- What does ('{0:N2}' this mean?
- What function does the second "sum" (.Sum) have?
Thanks in advance.
CodePudding user response:
What does ('{0:N2}' this mean?
It's normal PS formatting, see details per this link.
https://devblogs.microsoft.com/scripting/powertip-formatting-numeric-output-using-powershell
https://devblogs.microsoft.com/scripting/use-powershell-and-conditional-formatting-to-format-numbers
What function does the second "sum" (.Sum) have?
The final value to be returned. It's called using dot parameter method and is used to get a specific property value.
Simple example:
(Get-ChildItem).FullName
See also:
So, not unique to what you've posted. These is all normal basic/intermediate PS function call with formatted output.
All of this is shown by example in the PS help files on your system and on the MS docs site.
CodePudding user response:
@postanote has answered this well. I'm happy. Cheers :-)