Consider this statement:
Get-Content .\zipper.ps1 | Invoke-Expression
Here's a variation documented in Technet.
Invoke-Expression (Get-Content '.\zipper.ps1' -Raw)
Both statements work just fine, although the 2nd one executes much faster. Assume zipper.ps1 is a script containing multiple lines of executable Powershell 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?
PowerShell may have a 260-character limit (not sure). These pages mention character limits in Powershell:
https://support.microsoft.com/en-us/kb/830473
Details:
Technet states:
"Get-Content cmdlet gets the content of the item at the location specified by the path, such as the text in a file."
and
"Invoke-Expression cmdlet evaluates or runs a specified string as a command and returns the results of the expression or command."
So far so good-- that explains pretty clearly how and why my statement above works. But it does not tell me if the statements are executed as individual statements, or as one big concatenated string. The fact that the 2nd variation runs faster may be a clue.
Maybe I need to add a For..Each
.
The technet doc says Get-Content returns a collection, while this Technet article says it returns an array. That's conflicting info, but not sure array vs collection matters re my question here.
thx