$_ and $PSItem

noun

say it: “DOL-er UN-der-skor” /ˈdɑlər ˈʌndərskɔr/ or “DOL-er PEE-ESS EYE-tum” /ˈdɑlər ˌpiˈɛs ˈaɪtəm/

In PowerShell, the variable that holds the object being worked on right now inside a pipeline command's code.

What are $_ and $PSItem?

$_ (read "this item") holds the object being worked on right now inside a script block, such as Where-Object's test or ForEach-Object's code. Each object that comes down the pipeline takes its turn as $_. $PSItem is a longer name for the same thing.

Get-ChildItem -Recurse -File | Where-Object { $_.Length -gt 1MB -and $_.Extension -eq '.mp4' }

In a sentence

  • “Inside Where-Object's braces, $_ is the file being tested right now.”
  • “Sam wrote $PSItem instead of $_, because the longer name reads more clearly.”

Level: Apprentice · More PowerShell terms at this level

Updated