Skip to content

Instantly share code, notes, and snippets.

@scaryrawr
Created October 6, 2021 20:25
Show Gist options
  • Save scaryrawr/d2ccacc8b744d1139658a85de4ed2f34 to your computer and use it in GitHub Desktop.
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.
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 $_
}
}
@scaryrawr
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment