Created
November 4, 2025 19:33
-
-
Save sweenish/4a32ba005d247227ed4845c1bc9713f1 to your computer and use it in GitHub Desktop.
Make every PowerShell instance a developer instance
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
| # NOTE: Place at the top | |
| # --- Visual Studio Developer PowerShell bootstrap --------------------------- | |
| # Automatically enter the Visual Studio Developer PowerShell environment | |
| # in any new PowerShell session. Skips if already initialized (VSCMD_VER). | |
| try { | |
| if ($IsWindows -and -not $env:VSCMD_VER) { | |
| $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' | |
| if (Test-Path $vswhere) { | |
| # Get latest (including prerelease) VS instance info | |
| $vsInstallPath = & $vswhere -latest -prerelease -property installationPath 2>$null | |
| $vsInstanceId = & $vswhere -latest -prerelease -property instanceId 2>$null | |
| if ($vsInstallPath -and $vsInstanceId) { | |
| $devShellModule = Join-Path $vsInstallPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll' | |
| if (Test-Path $devShellModule) { | |
| Import-Module $devShellModule -ErrorAction Stop | |
| # Choose architecture that matches your shell; change to 'x86' if you want 32-bit tools. | |
| $arch = if ([Environment]::Is64BitProcess) { 'x64' } else { 'x86' } | |
| # Typical args: -arch, -host_arch, and -no_logo. You can add -vcvars_ver, -winsdk, etc. | |
| $args = "-arch=$arch -host_arch=$arch -no_logo" | |
| Enter-VsDevShell -VsInstanceId $vsInstanceId -SkipAutomaticLocation -DevCmdArguments $args | |
| Write-Verbose "Developer PowerShell initialized from: $vsInstallPath ($arch)" | |
| } | |
| } | |
| } | |
| } | |
| } catch { | |
| Write-Warning "Developer PowerShell init failed: $($_.Exception.Message)" | |
| } | |
| # --------------------------------------------------------------------------- |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This works on Windows 11 (64-bit, but I don't recall if you can get 32-bit Windows 11), with VS 2022 installed.