Created
October 6, 2021 20:25
-
-
Save scaryrawr/d2ccacc8b744d1139658a85de4ed2f34 to your computer and use it in GitHub Desktop.
Load an environment in PowerShell such as visual studio's developer command prompt.
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(Mandatory = $true)] | |
[string] | |
$EnvironmentScript | |
) | |
cmd /c "`"$EnvironmentScript`"&set" | ForEach-Object { | |
if ($_ -match '=') { | |
$vars = $_.split('=') | |
Set-Item -Force -Path "env:$($vars[0])" -Value "$($vars[1])" | |
} | |
else { | |
# Log information so user knows what environment they were set up with | |
Write-Output $_ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can create a shortcut (or Windows Terminal Profile) with something like:
pwsh.exe -NoExit -c "%USERPROFILE%\OneDrive\LoadEnvironment.ps1 -EnvironmentScript 'C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\Tools\VsDevCmd.bat'"
The default Developer Profile using Windows PowerShell instead of PowerShell-Core.