Reputation: 19636
How can one make a windows short-cut that opens Powershell into a specific directory?
Such as the target:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-noexit -command {cd c:/path/to/open}
But that just spits out the command as text. How?
Upvotes: 94
Views: 83708
Reputation: 2980
In Windows 11 the shell has a "Settings" section that lets you create profiles. You can easily configure a specific profiles to open to a specific directory and to run as an admin (if required). You can also set specific profiles to be the default any time the shell opens a new tab. That would be equivalent to creating a specific shortcut, but would apply to anytime you open the shell and not limited to a specific shortcut. You can easily open different profiles from within the shell by clicking on the drop down in the tabs bar.
Upvotes: 0
Reputation: 2137
If you are on a folder (File Explorer), you can write powershell
on the address bar. This will open powershell
that already moved to your current folder. The shortcut:
ctrl+L (move keybord to address bar)
powershell
Upvotes: 0
Reputation: 113
I use a .ps1 script file to open a PowerShell terminal at a specific path from a shortcut in the taskbar. The script:
cd 'directory path'
powershell
Running "powershell.exe" from a PowerShell terminal will start a new PowerShell session, preventing the terminal window from closing.
Upvotes: 2
Reputation: 1642
If you prefer to launch Windows Terminal with your prefered command line shell, you can use:
wt.exe -d "c:\temp"
Upvotes: 1
Reputation: 31576
If you want powershell to start as admin and run in a specific directory, even on a different drive, it is better to use the Set-Location
command. Follow these steps
Start in:
blank. (Normally this starts in current working directory when blank; but we do not care.)Target
to this with your targets for powershell and locations:C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command "Set-Location D:\_DCode\Main"
Advanced...
and select Run as administrator
.OK
s out.Don't forget the handy trick to change the colors of the shortcut from the Colors
tab. That way if you have two or more links which open powershell windows, seeing a different color can visually let you know which shell one is working in.
Upvotes: 9
Reputation: 327
If you are using Powershell 7 (pwsh)
, simply use the -WorkingDirectory
flag like this:
pwsh -WorkingDirectory "C:\path\to\your\directory"
Upvotes: 0
Reputation: 197
I just wanted to add my Developer Powershell link ... for the records.
C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -noe -c "&{Import-Module """C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"""; Enter-VsDevShell d998f19b; cd c:\dev\}"
This will start the Developer Powershell (VS 2019) in c:\dev\
.
Upvotes: 0
Reputation: 26120
Use this command.
powershell.exe -noexit -command "cd c:\temp"
-NoExit
: Do not exit after running startup commands.
Upvotes: 152
Reputation: 928
Define a Shortcut for Powershell, and Open the properties of that, and finally in "Start" type the folder target to be opened when Powershell Shortcut is triggered
Upvotes: 12
Reputation: 141
If one wants a explorer right click options run this script:
New-PSDrive -Name HKCR -PSProvider Registry -Root HKEY_CLASSES_ROOT
if(-not (Test-Path -Path "HKCR:\Directory\shell\$KeyName"))
{
Try
{
New-Item -itemType String "HKCR:\Directory\shell\$KeyName" -value "Open PowerShell in this Folder" -ErrorAction Stop
New-Item -itemType String "HKCR:\Directory\shell\$KeyName\command" -value "$env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -noexit -command Set-Location '%V'" -ErrorAction Stop
Write-Host "Successfully!"
}
Catch
{
Write-Error $_.Exception.Message
}
}
else
{
Write-Warning "The specified key name already exists. Type another name and try again."
}
This is what is shown now:
Note that you can download a detailed script from how to start PowerShell from Windows Explorer.
Upvotes: 2
Reputation: 19
Copy this code into notepad and save with a reg extension. Double click the resulting file.If you get a message about importing to the registry click on yes and then ok. Navigate to any folder in explorer and bring up the context menu. This is typically done by clicking the right mouse button.
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\PShell]
"MUIVerb"="Open in Powershell Window"
[HKEY_CLASSES_ROOT\Directory\Background\shell\PShell\command]
@="c:\\windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -Command Set-Location -LiteralPath '%V'"
Upvotes: 1
Reputation: 126702
You can also set the "Start in" shortcut field to your desired location.
Upvotes: 45
Reputation: 60910
try:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-noexit -command "cd c:/path/to/open"
Upvotes: 6
Reputation: 19636
Ok - you need to use the &
parameter to specify it's a powershell comand & the syntax is slightly different:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe
-noexit -command "& {cd c:\path\to\open}"
Upvotes: 10