r/PowerShell • u/Defiant_Wafer5282 • Apr 04 '26
Powershell Noob
Hey all
I’m a slight newbie and landed a JR infrastructure engineer role that includes looking after cloud environments, patching software and machines.
Is there any advice where I could get into learning more powershell scripting or and decent YouTube courses I could follow
Any help is appreciated
20
Upvotes
View all comments
Show parent comment
1
u/TofuBug40 Apr 06 '26
That just shows you don't understand your tools
Where-Objectand.Where{}/.Where()are for completely different problems and when you use either in the wrong place you're going to have a bad time. If you have ALL of the items already in memory.Where{},.Where(),.ForEach{}, and.ForEach()are ALL going to be faster because they are applied in one shot to the entire collection.If however you CAN NOT hold all the items in memory then those start to fall apart and you reach a point where Where() starts to lag behind even Where-Object.
You can literally show this to yourself.
Take something like
Simple little test runner
Now mind you every system is going to be a little different and the differences in my run are minimal but consistent. Code blocks for each will be in the comments for every test its using Get-ChildItem to recursively get ALL the files from the root of C and filter it down to just .txt files simple enough
You can see while close on all metrix the average, the min and max Where() starts to fall behind because it has to wait for ALL the data to collect in memory before it can act. Since Where-Object is working one item at a time as it comes down the pipeline even if it has to wait for some its already passing it on down the line to even the next cmdlet in the pipeline its not blocking the rest of them from doing what they can.