You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
about_Pwsh / about_PowerShell.exe suggest use of a script block with the call operator inside command strings, even though that seems unnecessary #2750
To write a string that runs a PowerShell command, use the format: "& {<command>}"
where the quotation marks indicate a string and the invoke operator (&) causes the command to be executed.
However, there is no good reason to use & with a script block { ... } inside a string passed to -Command- it works fine - and more efficiently - without it; e.g., using the command from the example (which should be modified too)
So, clearly, the use of embedded & { ... } is not a general requirement.
If there are special circumstances where it is required, they should be mentioned.
Also: The formatting of the above code is currently broken in the about_powershell_exe documents (but not in about_Pwsh)
As an aside: I find the following confusing:
If the value of Command is a string, Command must be the last parameter in the command , because any characters typed after the command are interpreted as the command arguments.
Perhaps it should say something like:
"
If the value of Command is a string, Command must be the last parameter in the command, because all arguments following it are interpreted as part of the command to execute.
"