Search code examples
command-linepowershell-coreps1

Running pwsh.exe with -File never returns


I created simple Test.ps1 script like this:

echo $org = Get-VBOOrganization -Name "OrgName.onmicrosoft.com" >> Test.ps1
echo $org.Id.ToString() >> Test.ps1

Then I run this script with pwsh:

pwsh -File Test.ps1

Script executes, writes output (some guid), but then it never returns back to cmdline

Important note: When I use powershell.exe instead of pwsh.exe then I am correctly returned to cmdline. So this works:

powershell -File Test.ps1

But, I need to use pwsh to use PS7.

I tried to play with -MTA & -NonInteractive parameters, nothing helped. Would anyone know what else to try?

Thanks a lot!


Solution

  • Problem solved by calling Exit in the end of the script:

    [System.Environment]::Exit(0)