Windows Powershell: Executing commands via the context menu?
Solution 1:
You can run PowerShell commands from the command-line (batch files, etc.) by using this format:
C:\> PowerShell <PowerShell command you want to run>
ie:
C:\> PowerShell "kramdown MyFileName.txt | Out-Clipboard"
So we can use that in a context menu entry.
For simplicity here's how you can add a new Context Menu command to run it against whichever file you have selected/right-clicked (this is probably not the ONLY way to do this):
- Head to
HKEY_CLASSES_ROOT\*\shell
in the registry. - Create a new Key named what you want (like say "Kramdown").
- Set the "Default" REG_SZ value of that new key to the text you want to appear on the context menu (like say "Kram This Down").
- Create another new Key inside the key you just made, and name it "command".
- Set the value of the "Default" REG_SZ in that new 'command' key to run the command you want.
The command you'll want to enter is like above, only we need to tell it to do it in the command prompt, and use the %1 variable so it knows the file you clicked on:
cmd /C PowerShell "kramdown %1 | Out-Clipboard"
The /C causes the CMD window to close after it's done.
As soon as you make these registry changes they will affect the context menu, so you don't need to logout or reboot to enable or test your changes.
Since I don't have your source files, Kramdown, or Out-Clipboard I can't test this 100%; but this should be enough info to get you going, if it doesn't 'just work' as-is. :)