PowerShell Switch statement Switch Statement with File Parameter


Example

The -file parameter allows the switch statement to receive input from a file. Each line of the file is evaluated by the switch statement.

Example file input.txt:

condition
test

Example switch statement:

switch -file input.txt
{ 
  'condition' {'First Action'}
  'test'      {'Second Action'} 
  'fail'      {'Third Action'}   
}

Output:

First Action
Second Action