Skip to content

Instantly share code, notes, and snippets.

@dfbaskin
Last active January 4, 2024 15:28
Show Gist options
  • Save dfbaskin/8a2fdb01cb7a922e4e14c82d65cb478a to your computer and use it in GitHub Desktop.
Save dfbaskin/8a2fdb01cb7a922e4e14c82d65cb478a to your computer and use it in GitHub Desktop.
Set up Visual Studio command line shell in PowerShell (v7+)
param (
[string] $name = 'Visual Studio Enterprise 2022'
)
$VSInstance = Get-CimInstance MSFT_VSInstance -Namespace root/cimv2/vs |
Where-Object { $_.ElementName -eq $name }
if (-not $VSInstance) {
throw "Could not find Visual Studio installation details."
}
$devShell = Join-Path $VSInstance.InstallLocation 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll' -Resolve
$vsID = $VSInstance.IdentifyingNumber
Push-Location
Import-Module $devShell
Enter-VsDevShell $vsID
Pop-Location
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment