I was trying to create a hash table,
$input = @{'G'=100;'E'=50;'D'=35;'A'=100}
and could not figure out for the life of me why it wouldn't display as usual with commands like write-host
, or simply $input
. write-host
returned System.Collections.ArrayList+ArrayListEnumeratorSimple
. $input
returned nothing. No error was thrown.
On a hunch I renamed the hash table, and boom, it appears as normal. Opening a new powershell tab in ISE, I observe that the variable $input
is filled in with intellisense even though I have not defined it in this environment.
Now I'm curious: what is this system variable $input for? I'm on version 4.
Input : 'Geeks for Geeks' Output : Hello Geeks for Geeks Input : 'PowerShell Beginner' Output : Hello PowerShell Beginner In Windows Powershell, the input and output are given through the Host. It uses ‘Write-Host’ to print and ‘Read-Host’ to get input from console. Function to get user input.
In Windows Powershell, the input and output are given through the Host. It uses ‘Write-Host’ to print and ‘Read-Host’ to get input from console. Example 2: Taking the User input through console Function to get user input. Input : 'Geeks for Geeks' Output : Hello Geeks for Geeks Input : 'PowerShell Beginner' Output : Hello PowerShell Beginner
Windows PowerShell is a command-line and scripting language designed for system administration. It helps IT professionals, to control and automate the administration of the Windows Operating System and Windows Server Environment. There are cmdlet for console input and output using PowerShell.
Often times your PowerShell code will need to evaluate some type of input. That input can be statically provided by you ahead of time. There are often use cases though where retrieving a dynamic input is desired. You can of course use the output of cmdlets for the input of your PowerShell functionality.
It's an automatic variable:
$INPUT
Contains an enumerator that enumerates all input that is passed to a function. The
$input
variable is available only to functions and script blocks (which are unnamed functions). In the Process block of a function, the$input
variable enumerates the object that is currently in the pipeline. When the Process block completes, there are no objects left in the pipeline, so the$input
variable enumerates an empty collection. If the function does not have a Process block, then in the End block, the$input
variable enumerates the collection of all input to the function.
This is also available in PowerShell:
Get-Help about_Automatic_Variables
I also have an open feature request for Set-StrictMode
to handle detection of this.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With