3 ms·
I answered an interesting SO question on that recently, which asked how to save and restore the environment in PowerShell. Turns out, the environment being in a
by ygra 11y ago
I answered an interesting SO question on that recently, which asked how to save and restore the environment in PowerShell. Turns out, the environment being in a PSDrive helps very much with that because you can treat the variables just like you treat files:
# Save environment
$savedState = Get-ChildItem Env:
# Restore environment
Remove-Item Env:*
$savedState | ForEach-Object { Set-Content Env:$($_.Name) $_.Value }