79451888

Date: 2025-02-19 15:24:07
Score: 0.5
Natty:
Report link

The short answer is no—you cannot use a variable (or function) in place of a literal string for the -File parameter when launching PowerShell.exe. The -File switch is handled by the PowerShell executable itself before any of your inline script code (and thus any variable assignments) is executed.

Because -File is processed before the session starts, it cannot resolve any variables defined in the command string. If you need dynamic behavior, compute the file path first (outside of the PowerShell call) or use -Command where variable expansion is available.

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: Shoaib Nigam