n8n - 💡(How to fix) Fix Execute Command node on Windows when using PowerShell multiline commands

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

Describe the problem/error/question

What is the error message (if any)?

No error is returned.

  • error: all

Code Example

{
  "exitCode": 0,
  "stderr": "",
  "stdout": ""
}

---

powershell -Command "$src='{{$json.SourcePath}}/{{$json.DocFilename}}';$base='{{$json.DocJson.parseJson().DocNum}}';$destFolder='{{$json.DestinationPath}}';$dest=Join-Path $destFolder ($base + '.pdf');$i=0;while(Test-Path $dest){$i++;$dest=Join-Path $destFolder ($base + '-' + $i + '.pdf')};Copy-Item $src $dest -Force;Write-Output $dest"

---

powershell -Command "
$src = '{{$json.SourcePath}}/{{$json.DocFilename}}';
$base = '{{$json.DocJson.parseJson().DocNum}}';
$destFolder = '{{$json.DestinationPath}}';

$dest = Join-Path $destFolder ($base + '.pdf');

$i = 0;
while (Test-Path $dest) {
    $i++;
    $dest = Join-Path $destFolder ($base + '-' + $i + '.pdf');
}

Copy-Item $src $dest -Force;
Write-Output $dest;
"

---

{
  "exitCode": 0,
  "stderr": "",
  "stdout": "\\\\DAG-WMSAP1.dag.local\\b1desktop\\SSP\\54101.pdf"
}

---

{
  "exitCode": 0,
  "stderr": "",
  "stdout": ""
}
RAW_BUFFERClick to expand / collapse

Describe the problem/error/question

I may have found an issue with the Execute Command node on Windows when using PowerShell multiline commands.

A PowerShell script passed through powershell -Command behaves differently depending on whether it is written on a single line or on multiple lines.

The exact same script works correctly when written on a single line, but when formatted as a multiline command, the node completes successfully (exitCode = 0) while returning an empty stdout and apparently not executing all statements as expected.

This appears to be related to how multiline commands are passed to PowerShell by the Execute Command node on Windows.


What is the error message (if any)?

No error is returned.

The node reports:

{
  "exitCode": 0,
  "stderr": "",
  "stdout": ""
}

Please share your workflow/screenshots/recording

Working command (single line)

powershell -Command "$src='{{$json.SourcePath}}/{{$json.DocFilename}}';$base='{{$json.DocJson.parseJson().DocNum}}';$destFolder='{{$json.DestinationPath}}';$dest=Join-Path $destFolder ($base + '.pdf');$i=0;while(Test-Path $dest){$i++;$dest=Join-Path $destFolder ($base + '-' + $i + '.pdf')};Copy-Item $src $dest -Force;Write-Output $dest"

Failing command (multiline)

powershell -Command "
$src = '{{$json.SourcePath}}/{{$json.DocFilename}}';
$base = '{{$json.DocJson.parseJson().DocNum}}';
$destFolder = '{{$json.DestinationPath}}';

$dest = Join-Path $destFolder ($base + '.pdf');

$i = 0;
while (Test-Path $dest) {
    $i++;
    $dest = Join-Path $destFolder ($base + '-' + $i + '.pdf');
}

Copy-Item $src $dest -Force;
Write-Output $dest;
"

Both commands are functionally identical.

The first one works correctly.

The second one returns no output.


Share the output returned by the last node

Working version:

{
  "exitCode": 0,
  "stderr": "",
  "stdout": "\\\\DAG-WMSAP1.dag.local\\b1desktop\\SSP\\54101.pdf"
}

Multiline version:

{
  "exitCode": 0,
  "stderr": "",
  "stdout": ""
}

Additional observations

  • Platform: Windows
  • PowerShell executes the multiline version correctly when run directly outside n8n.
  • The issue only appears when the command is executed through the Execute Command node.
  • It may be related to newline handling, command escaping, or expression rendering before execution.

It would be useful to know whether multiline PowerShell commands are officially supported inside Execute Command on Windows and whether newline characters are modified before being passed to PowerShell.

Debug info

core

  • n8nVersion: 2.22.4
  • platform: npm
  • nodeJsVersion: 22.17.1
  • nodeEnv: undefined
  • database: sqlite
  • executionMode: regular
  • concurrency: -1
  • license: community

storage

  • success: all
  • error: all
  • progress: false
  • manual: true
  • binaryMode: filesystem

pruning

  • enabled: true
  • maxAge: 336 hours
  • maxCount: 10000 executions

client

  • userAgent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/147.0.0.0 safari/537.36 edg/147.0.0.0
  • isTouchDevice: false

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING