I created Windows context menu item to execute a powershell command. However, I can't figure out how to pass %1 to my Powershell script with escaped quotes.
Current registry entry:
[HKEY_CLASSES_ROOT\*\shell\Share file on FTP\Command]
@="cmd.exe /C nircmd elevate PowerShell -NoProfile -NoLogo -Command \"& {(dir \"%1\" | Copy-ToFTP -Destination Public.Screenshots).source | clip}\""
Produces the following error when I select a file via the "Share file on FTP" context menu item:
dir : Cannot find path 'D:\Multimedia' because it does not exist.
At line:1 char:5
+ & {(dir D:\Multimedia Files\Pictures\HTPC\20150328_220120.jpg | Copy-ToOnedrive ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (D:\Multimedia:String) [Get-ChildItem], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
BONUS I'm currently using a 3rd party tool, Nircmd, to elevate the Powershell Prompt (since my powershell command needs it). If possible, I'd like to use native Windows to do this instead (keeping my command code to a single line, if possible).... NOT afterwards, by creating a Powershell PS1 script that elevates itself.
EDIT: Below line of code "should" work.. however, instead of getting a a shortname path, I get an unexpected incorrect result:
I'm copying and pasting the registry key value to make it easier to read (instead of .reg file content)
cmd.exe /c for %%A in (%1) do @set I=%%~sA | PowerShell.exe -NoExit -NoProfile -NoExit -NoLogo -Command "& {(dir %I% | Copy-ToFTP -Destination Public.Screenshots).source | clip}"
Ultimately produces this output in Powershell:
dir : Cannot find path 'D:\Multimedia Files\Pictures\HTPC\:433310880:4624'
because it does not exist.