File tree Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Expand file tree Collapse file tree 1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -801,16 +801,17 @@ function Invoke-IsolatingEnvVars([scriptblock]$Block) {
801
801
foreach ($Var in (Get-ChildItem env:* ).GetEnumerator()) {
802
802
$OldVars.Add ($Var.Key , $Var.Value )
803
803
}
804
+ try {
805
+ & $Block
806
+ } finally {
807
+ Remove-Item env:*
808
+ foreach ($Var in $OldVars.GetEnumerator ()) {
809
+ New-Item - Path " env:\$ ( $Var.Key ) " - Value $Var.Value - ErrorAction Ignore | Out-Null
810
+ }
804
811
805
- & $Block
806
-
807
- Remove-Item env:*
808
- foreach ($Var in $OldVars.GetEnumerator ()) {
809
- New-Item - Path " env:\$ ( $Var.Key ) " - Value $Var.Value - ErrorAction Ignore | Out-Null
810
- }
811
-
812
- if ($ToBatch ) {
813
- Write-Output " endlocal"
812
+ if ($ToBatch ) {
813
+ Write-Output " endlocal"
814
+ }
814
815
}
815
816
}
816
817
You can’t perform that action at this time.
0 commit comments