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/xXFl1ppyXx Apr 07 '26
Different use cases
Usually you'd use the method (.where{} and .foreach{}) with collections that are already in vars tallied up.
Foreach-Object and Where-Object are used in cases where you don't know how much data you're getting.
For example read a txt file of variable size;
Get-Content (or Stream readers for that matter) | Where-Object is ideal for handling via pipeline because every line or every character read from the file is checked against the where object statement while it's being read from the file
$Content = Get-Content
$Content.Where{}
Works but you'll waste time/performance rolling / unrolling your objects unnecessarily
Also .ForEach doesn't work on lists