Created
March 7, 2017 04:19
-
-
Save bradwilson/3fca203370d54304eff1cce21ffc32aa to your computer and use it in GitHub Desktop.
Invoke a CMD/BAT script and scrape the environment variable changes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)][string] $Script, | |
[Parameter(Position=1, Mandatory=$false)][string] $Parameters | |
) | |
$tempFile = [IO.Path]::GetTempFileName() | |
cmd /c " `"$script`" $parameters && set > `"$tempFile`" " | |
Get-Content $tempFile | %{ | |
if ($_ -match "^(.*?)=(.*)$") { | |
Set-Content "env:\$($matches[1])" $matches[2] | |
} | |
} | |
Remove-Item $tempFile |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment