Skip to content

Tag: PowerShell

PowerShell: foreach vs. .ForEach and ForEach-Object with IF vs. .Where

I do a lot of workshops with developers and administrators (or DevOps if you like to call them that way).
During one of the last workshops, one of the admins asked me a clever question: “Why do you pipe so much? Why don’t you use .ForEach and .Where instead? This should be faster!“.

So we took an existing function (One I use to clean up all my event log entries, and decided to refactor it. To see the difference, we also created a wrapper script that can handle all the measurement for us.