I want to do a progress bar of my script but then I need a total amount of folders.
Is there a significant runtime difference between:
Get-ChildItem
Yes, there is a performance difference. foreach is faster than ForEach-Object, but requires more memory, because all items ($folders) must be in memory. ForEach-Object processes one item at a time as they're passed through the pipeline, so it has a smaller memory footprint, but isn't as fast as foreach.
See also.