Skip to content

Instantly share code, notes, and snippets.

@uriellberdeja
Created July 19, 2024 18:25
Show Gist options
  • Save uriellberdeja/86018a017a33daef6b079b521b65b91e to your computer and use it in GitHub Desktop.
Save uriellberdeja/86018a017a33daef6b079b521b65b91e to your computer and use it in GitHub Desktop.
Initialize Visual Studio Developer Powershell from a regular Powershell 7 and Powershell 5.1 session
$paths = @(
"C:\Program Files\Microsoft Visual Studio\2022\Community",
"C:\Program Files\Microsoft Visual Studio\2022\BuildTools",
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community",
"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools"
)
$VsInstallPath = $null
foreach ($basePath in $paths) {
if (Test-Path $basePath) {
$VsInstallPath = $basePath
break
}
}
if (-not $VsInstallPath) {
Write-Host "No valid Visual Studio installation path found."
exit
}
$DevShellPath = Join-Path $VsInstallPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll'
Import-Module $DevShellPath
$instances = Get-ChildItem -Path "C:/ProgramData/Microsoft/VisualStudio/Packages/_Instances/" -Name
if ($instances.Count -eq 0) {
Write-Host "No Visual Studio instances found."
exit
}
Enter-VsDevShell -VsInstallPath $VsInstallPath -DevCmdArguments '-arch=x64'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment