Finding the Developer PowerShell launch script can be difficult as the location for it has change across the different Visual Studio versions (e.g., 2019, 2022), editions (e.g., Community, Professional, Enterprise), and installation location.
Visual Studio 2022 and newer install the ‘Developer PowerShell for VS 2022’ as a Windows Terminal profile. This is the easiest way to access it. However, if you want to access it from a PowerShell ps1
script it is more complicated. Accessing via script is done typically if you have to run the script on another system where you don’t know which Visual Studio version/edition/location installed.
Alternatively, there is also the ‘Visual Studio Developer Command Prompt’ but we will be focusing on the ‘Visual Studio Developer PowerShell’ instead as it is more modern and powerful than the command prompt. Both shells have the same environment variables set. The PowerShell Developer shell has been available since Visual Studio 2019.
We will go through two methods: one with PowerShell and one with ripgrep. PowerShell can be pretty slow 🐢 but is available on all Windows systems without any extra setup.
The name of the Developer PowerShell script is Launch-VsDevShell.ps1
. I will assume that either Visual Studio 2019 or Visual Studio 2022 or newer is installed on the system.
Visual Studio 2022 location for Developer PowerShell for VS 2022
Visual Studio 2022 Community PowerShell is found:
$env:ProgramFiles\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1
# or for example,
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1
Visual Studio 2022 Professional PowerShell is found:
$env:ProgramFiles\Microsoft Visual Studio\2022\Professional\Common7\Tools\Launch-VsDevShell.ps1
# or for example,
C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\Launch-VsDevShell.ps1
Visual Studio 2019 location for Developer PowerShell for VS 2019
Visual Studio 2019 Community:
${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Community\Common7\Tools\Launch-VsDevShell.ps1
# or for example,
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Launch-VsDevShell.ps1
Visual Studio 2019 Professional:
${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Professional\Common7\Tools\Launch-VsDevShell.ps1
# or for example,
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\Tools\Launch-VsDevShell.ps1
Find Developer PowerShell Launch-VsDevShell.ps1
with PowerShell
If we want to search and find the developer PowerShell we can do the following. We will use PowerShell to search file names for Launch-VsDevShell.ps1
:
If we don’t know which version of Visual Studio is installed, we can search the entire drive, assuming it was installed on this drive. This method is exhaustive but can be slow:
Get-ChildItem -Path 'C:\' -Filter 'Launch-VsDevShell.ps1' -Recurse -ErrorAction SilentlyContinue -Force
If we know Visual Studio 2022 or newer is installed then:
Get-ChildItem -Path 'C:\Program Files\' -Filter 'Launch-VsDevShell.ps1' -Recurse -ErrorAction SilentlyContinue -Force
Output:
Directory: C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a--- 8/19/2024 9:28 PM 23914 Launch-VsDevShell.ps1
If we know Visual Studio 2019 is installed then:
Get-ChildItem -Path 'C:\Program Files (x86)\' -Filter 'Launch-VsDevShell.ps1' -Recurse -ErrorAction SilentlyContinue -Force
Bonus: Find first Developer PowerShell Launch-VsDevShell.ps1
and launch it
Search C:\Program Files\Microsoft Visual Studio
for the Launch-VsDevShell.ps1
, if only one found, then launch it.
Warning ⚠️: Only use this in a trusted environment, as any user written script can match Launch-VsDevShell.ps1
.
Written as a one liner:
$files = Get-ChildItem -Path 'C:\Program Files\Microsoft Visual Studio' -Filter 'Launch-VsDevShell.ps1' -Recurse -ErrorAction SilentlyContinue -Force; if ( $files.Count -eq 1 ) { Write-Host 'Found Developer PowerShell!'; & $files.FullName } else { Write-Host 'More than one developer shell found' }
Expanded out:
$files = Get-ChildItem -Path 'C:\Program Files\Microsoft Visual Studio' -Filter 'Launch-VsDevShell.ps1' -Recurse -ErrorAction SilentlyContinue -Force
if ( $files.Count -eq 1 )
{
Write-Host 'Found Developer PowerShell!'
& $files.FullName
}
else
{
Write-Host 'More than one developer shell found'
}
Output:
Found Developer PowerShell!
**********************************************************************
** Visual Studio 2022 Developer PowerShell v17.11.2
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
PS C:\>
Find Files Fast with ripgrep
Let’s do the same exercise but with ripgrep which is fast 🐇! We will use ripgrep to search file names for Launch-VsDevShell.ps1
:
cd C:\
rg . --glob 'Launch-VsDevShell.ps1' --files-with-matches --no-messages
# more simply:
rg . -g 'Launch-VsDevShell.ps1' -l --no-messages
Arguments:
.
because “ripgrep requires at least one pattern to execute a search”, so.
will search for files that have at least one character--glob
or-g
describes which files and directories to include in search, in this case we want to findLaunch-VsDevShell.ps1
--files-with-matches
or-l
matches the file names--no-messages
suppress any access is denied messages in the results
Output:
Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1
Awesome we found it, we can now run the script:
& 'C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\Launch-VsDevShell.ps1'
and it will setup the shell for Developer environment.
Find Files Even Faster with ripgrep
If that took too long we can do better! We used --glob
to include or exclude directories and files. By design ripgrep searches all the subdirectoreis of your current directory.
In fact, recursively searching your current working directory is the default mode of operation for ripgrep […]1
So instead of excluding a bunch of directories (e.g., `–glob=’!Windows/’) we can just start in the closest directory where we expect the file to be. Depending on were Visual Studio was installed we can just search those directories.
To improve the search time we can do the following:
Visual Studio 2022 default installation is in Program Files
:
cd 'C:\Program Files\'
rg . -g 'Launch-VsDevShell.ps1' -l --no-messages
or even closer for Visual Studio 2022:
cd 'C:\Program Files\Microsoft Visual Studio'
rg . -g 'Launch-VsDevShell.ps1' -l --no-messages
Visual Studio 2019 was installed in Program Files (x86)
:
cd 'C:\Program Files (x86)\'
rg . -g 'Launch-VsDevShell.ps1' -l --no-messages
If one unique results found, launch it!
Similar to the PowerShell script above, but with ripgrep.
Warning ⚠️: Only use this in a trusted environment, as any user written script can match Launch-VsDevShell.ps1
.
# For Visual Studio 2022 default location
cd 'C:\Program Files\Microsoft Visual Studio'
$files = rg . -g 'Launch-VsDevShell.ps1' -l --no-messages
if ( $files.Count -eq 1 )
{
Write-Host 'Found Developer PowerShell!'
& $files
}
else
{
Write-Host 'More than one developer shell found'
}
Voilà! Much faster results. 🐇🥇
Bonus: Find Launch-VsDevShell.ps1
with fzf
Another favorite tool of mine is fzf
, made just for this! It will knock your socks off 🧦🧦 by how easy it is. This is a great way to find files locally on the system but you have to type it, and won’t work with scripts that need to be fully automated.
& $(fzf)
Then type Launch-VsDevSehll.ps1
and press enter. Done! 🤯 You can cd
close to where you think the file is such as C:\Program Files\Microsoft Visual Studio
and run the command there.
The way it works:
$(...)
evaluates first, which callsfzf
- Use
fzf
to type the file you’re looking for fzf
returns the full path of that file, and& ...
excutes it