Adding Powershell command to right click menu both on and in a folder
11,198
Solution 1
Here is the solution:
This adds powershell to the opening window (i.e. when right click on a file)
[HKEY_CLASSES_ROOT\Directory\shell]
1. Create a key such as "powershell" or whatever you want without space
2. Set the default value of the key as your desired text, e.g.:"PS here dear"
3. Create a nested key inside the "powershell" key as "command"
4. Edit the command value by this:
C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%L'
This adds powershell to right click menu inside the folder
[HKEY_CLASSES_ROOT\Directory\Background\shell]
1. Create a key such as "powershell" or whatever you want withuout space
2. Set the default value of the key as your desired text e.g "PS here dear"
3. Create a nested key inside the "powershell" key as "command"
4. Edit the command value by this:
C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%V'
Note to %V and %L differences in the command
Solution 2
This is SdidS's solution as a regedit file:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell_here]
@="PowerShell Here"
[HKEY_CLASSES_ROOT\Directory\Background\shell\powershell_here\command]
@="C:\\\\Windows\\\\system32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe -NoExit -NoProfile -Command Set-Location -LiteralPath '%V'"
Solution 3
Execute the following script in PowerShell to add to the context menu:
'Directory',
'Directory\Background',
'Drive' | ForEach-Object {
$Path = "Registry::HKEY_CLASSES_ROOT\$_\shell\PowerShellHere";
New-Item -Path $Path -Name 'command' -Force | Out-Null;
Set-ItemProperty -Path "$Path\command" -Name '(default)' -Value 'PowerShell -WindowStyle Maximized -NoExit -NoLogo -Command Set-Location "%V"';
Set-ItemProperty -Path $Path -Name '(default)' -Value 'PowerShell';
Set-ItemProperty -Path $Path -Name 'Icon' -Value "${Env:WinDir}\System32\WindowsPowerShell\v1.0\powershell.exe,0";
}
Related videos on Youtube
Author by
SddS
Updated on September 18, 2022Comments
-
SddS over 1 year
There are some solution online but most of them just add the command when you right click on the folder. I've find a solution (which work both) for Run As Administrator here. But it works just for administrator access.
-
SddS over 10 years
-
J Slick over 10 yearsIs that a question? The format of this site is question and answer. It's fine to answer your own question, but the thing above should be a question, and the answer(s) should appear below.
-
J Slick over 10 yearsthat's fine, but you should pose it as a question, and then you can provide your answer to your own question below. Or if there is already an existing question, you should answer that. I'm sure you are providing useful information, but it's best to present that in the format that people will expect.
-
-
Knuckle-Dragger over 10 yearsYou can do similar things at
HKEY_CLASSES_ROOT\*\shell
and utilize the %1 variable to send the highlighted filename into your script. The*
key applies shell ext to all file types.