Invoke-PSUCommand -ScriptBlock should return PowerShell output, errors and exceptions to the caller

Invoke-PSUCommand -ScriptBlock should return PowerShell output, errors and exceptions to the caller

1 vote

avatar

Description
During testing of the PowerShell Universal Agent, we observed that Invoke-PSUCommand -ScriptBlock executes successfully on the target machine, but the output generated inside the script block is not returned to the caller.
Commands executed through -Command return data as expected, while -ScriptBlock appears to return only metadata information.

Current Behavior
Example:

PowerShell


Invoke-PSUCommand -Computer "SERVER01" -ScriptBlock {
"HELLO"
}
Expected:

Plain Text


HELLO
Actual:

Plain Text


<DateTime>
<ComputerName>
<ComputerName>
The same behavior occurs with:

PowerShell


Write-Output "HELLO"

PowerShell


return "HELLO"
and even:

PowerShell


throw "Test Error"
No output, warning, error record, or exception is returned to the caller.
Expected Behavior
Invoke-PSUCommand -ScriptBlock should return the PowerShell pipeline output in the same way users would expect from:

  • PowerShell Remoting (Invoke-Command)
  • PowerShell Jobs
  • Universal Automation Jobs
  • Local PowerShell execution

Examples:

PowerShell


Invoke-PSUCommand -ScriptBlock {
Get-Date
}
Returns:

PowerShell


Thursday, September 11, 2026 11:34:21

PowerShell


Invoke-PSUCommand -ScriptBlock {
[PSCustomObject]@{
Name = "Test"
Value = 123
}
}
Returns:

PowerShell


Name Value
---- -----
Test 123

PowerShell


Invoke-PSUCommand -ScriptBlock {
throw "Something failed"
}
Returns:

PowerShell


Something failed
or a serialized PowerShell error record.
Business Impact
Current behavior makes -ScriptBlock difficult to use for:

  • Remote administration
  • Inventory collection
  • Health checks
  • Troubleshooting
  • Automation workflows
  • Returning structured PowerShell objects

Without access to output and error streams, consumers cannot reliably determine:

  • what the script produced
  • whether the script succeeded
  • whether an exception occurred
  • what data was generated remotely


All Comments (0)