Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell calling Powershell script

Tags:

powershell

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?

like image 535
Colonel Panic Avatar asked Jul 09 '12 11:07

Colonel Panic


1 Answers

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
like image 115
Joey Avatar answered Oct 12 '22 14:10

Joey