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) {
801801 foreach ($Var in (Get-ChildItem env:* ).GetEnumerator()) {
802802 $OldVars.Add ($Var.Key , $Var.Value )
803803 }
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+ }
804811
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+ }
814815 }
815816}
816817
You can’t perform that action at this time.
0 commit comments