Do Get-Content + Invoke-Expression Execute Statements Separately, or Together?


Get-Content .\zipper.ps1 | Invoke-Expression

Assume zipper.ps1 is a script containing multiple lines of executable code.

Will the above statement execute each line in zipper.ps1 as an individual command?

Or, will the entire script get executed as just one big concatenated string?

My question pertains to character limits for powershell statements-- if each code-line is within the powershell character-limit, but the entire script would exceed the character limit, will the above command exceed the character limit?


Get-Content returns a collection of String objects, one for each line of the file being read. Each String is sent down the pipeline individually, and would call Invoke-Expression once per line.

It’d be fairly straightforward to test different scenarios, if you wanted to, and see the results.