# begin, process and end Blocks

*noun*

say it: **“bih-GIN, PROH-ses, and END blox”** **/bɪˈɡɪn ˈprɑsɛs ənd ˈɛnd blɑks/**

The three parts of a PowerShell function that takes pipeline input: one runs before the first item, one for each item, one after the last.

## What are the **begin, process and end blocks**?

A function that takes pipeline input can have three blocks. `begin` runs once, before anything arrives, to set things up. `process` runs once for every object that comes down the pipeline. `end` runs once after the last one, to report a total.

```powershell
function Measure-Drive {
    param([Parameter(ValueFromPipeline)] $Song)
    begin   { $total = 0 }
    process { $total += $Song.Minutes }
    end     { "$total minutes" }
}
```

## In a sentence

- “Limit-Playlist uses **begin, process and end blocks** to keep a running total.”
- “Sam set the total to 0 in begin, one of the **begin, process and end blocks**.”

Level: Freelancer · [More PowerShell terms at this level](https://www.ask-codey.com/glossary?category=powershell&level=4)

Updated: November 10, 2026

Source: https://www.ask-codey.com/glossary/begin-process-and-end-blocks
