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

This topic contains 1 reply, has 2 voices, and was last updated by  Don Jones 1 year, 8 months ago.

  • Author
  • #54797

    Johny Why


    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?


  • #55067

    Don Jones

    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.

You must be logged in to reply to this topic.