Search code examples
powershellcommand-line-interfacewindows-subsystem-for-linux

On WSL2 how do I get a powershell command's output to print to stdout


In WSL2 I want to run a powershell command and get the output of the command to print to stdout on my WSL2.

I have tried many variants but it seems I always just get the command given back and not its output:

$ pwsh.exe -Command {Get-Date}
Get-Date

$ pwsh.exe -Command '{Write-Output "hello"}'
Write-Output "hello"

Solution

  • You should not use curly braces here :

    pwsh.exe -Command 'Get-Date'