# Doing Something to Each: ForEach-Object

ForEach-Object runs a script block once for every object the pipeline hands it, with $\_ as this item, so one line can rename 200 photos, and -WhatIf goes inside the braces, on the command that makes the change, so you can rehearse first.

![Cheat sheet for the lesson Doing Something to Each: ForEach-Object: ForEach-Object runs a script block once for every object the pipeline hands it, with $\_ as this item, so one line can rename 200 photos, and -WhatIf goes inside the braces, on the command that makes the change, so you can rehearse…](https://fsdtrainingmedia.blob.core.windows.net/public/images/2026/11/37cc74210f6f4af484ca3f0724e235ab.webp)

- Category: PowerShell
- Level: Apprentice
- Tags: and-psitem, foreach-object, operating-system, powershell, script-block, whatif-and-confirm
- Updated: November 10, 2026

Source: https://www.ask-codey.com/cheat-sheets/powershell-foreach-object-cheat-sheet
