Powershell calling Powershell script

powershell

Solution

You get another PowerShell process in the former case and the script cannot read variables defined in your current session:

PS> $foo = 'bar'
PS> 'Write-Host $foo'|Set-Content x.ps1
PS> & powershell .\x.ps1

PS> & .\x.ps1
bar

Problem

How does the behaviour differ between `& powershell .\other.ps1` and `& .\other.ps1`? Edit: In particular, how do they differ if there's an error in `other.ps1`?

Original source