PowerShell - execute script block in specific scope
问题 I am trying to implement RSpec/Jasmine like BDD framework in Powershell (or at least research the potential problems with making one). Currently I am having problems with implementing simple before/after functionality. Given $ErrorActionPreference = "Stop" function describe() { $aaaa = 0; before { $aaaa = 2; }; after { $aaaa; } } function before( [scriptblock]$sb ) { & $sb } function after( $sb ) { & $sb } describe the output is 0, but I would like it to be 2. Is there any way to achieve it