Skip to content

Category: PowerShell

About 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.

Copy AD group memberships from a given Source User to a Target User

I while ago I publish some PowerShell tooling to copy the Active Directory group memberships between users. The tooling also able to sync the group memberships; if the Target User belongs to a group whom the Source User doesn’t, the tooling can remove these groups. That is perfect for cloning or during the movement of users between divisions.