In Powershell, what is $input for? -


this question has answer here:

i trying create hash table,

$input = @{'g'=100;'e'=50;'d'=35;'a'=100} 

and not figure out life of me why wouldn't display usual commands write-host, or $input. write-host returned system.collections.arraylist+arraylistenumeratorsimple. $input returned nothing. no error thrown.

on hunch renamed hash table, , boom, appears normal. opening new powershell tab in ise, observe variable $input filled in intellisense though have not defined in environment.

now i'm curious: system variable $input for? i'm on version 4.

it's automatic variable:

$input

contains enumerator enumerates input passed function. $input variable available functions , script blocks (which unnamed functions). in process block of function, $input variable enumerates object in pipeline. when process block completes, there no objects left in pipeline, $input variable enumerates empty collection. if function not have process block, in end block, $input variable enumerates collection of input function.

this available in powershell:

get-help about_automatic_variables 

i have open feature request set-strictmode handle detection of this.


Comments