Search code examples
windowspowershell

Powershell: unexpected token when compose path from env variable


I am trying to run powershell command. I have set up 2 variables:

$env:P7_TESTING_INSTALLATION_PATH = "D:\Logos_block_gitlab_runner\pSeven-v2024.05"
$env:CI_PROJECT_DIR = "D:\Logos_block_gitlab_runner\GitLab-Runner\builds\vDLVWCgmH\0\aero\logos_userblock"

Then I am trying to run command using these variables:

Invoke-Command -ScriptBlock {$env:P7_TESTING_INSTALLATION_PATH\client\p7batch.exe --log-level=error --run $env:CI_PROJECT_DIR\autotest\jobs\_clear.py}

But I have got unexpected token error with "\client\p7batch.exe"...


Solution

  • No matter what, you need the call operator to run something partially in a variable. Invoke-command isn't needed. Environment variables aren't needed.

    & $P7_TESTING_INSTALLATION_PATH\client\p7batch.exe --log-level=error `
      --run $CI_PROJECT_DIR\autotest\jobs\_clear.py