Running powershell from windows right click

Welcome Forums General PowerShell Q&A Running powershell from windows right click

Viewing 4 reply threads
  • Author
    Posts
    • #267761
      Participant
      Topics: 4
      Replies: 5
      Points: 30
      Rank: Member

      Hello to all,

      Hope you can help me 🙂

      My goal is to get an msi product code as fast as possible.

      So I found a powershell script that will do the job:

      Next to it I add a new powershell script (run.ps1) that will run the first script:

      So far so good. Every time I run the script I get the product code to clipboard.

      Now I have created under Windows right click a new menu that run the run.ps1 and its also working.

      What shell I do in order to get the product code of the msi file I am right clicking?

      What should I write instead of absolute path c:\scripts\example.msi

      Hope it was clear enough.
      Thank you very much

      Amir 🙂

      • This topic was modified 4 weeks, 1 day ago by grokkit. Reason: code formatting
    • #267806
      Participant
      Topics: 5
      Replies: 177
      Points: 686
      Helping Hand
      Rank: Major Contributor

      Create the context menu by modifying the registry to add a key with the name of the menu and and a sub-key for “command” with a command to launch your powershell script (wrapper) and use %1 as a placeholder for the file that was selected:

      Key: Computer\HKEY_CLASSES_ROOT\*\shell\OpenPS\command

      Value: powershell C:\pathtoscript\run.ps1 %1

      When you click on the new context menu it will launch your run.ps1 script and pass the full file path to run.ps1 as an argument.

       

    • #268616
      Participant
      Topics: 4
      Replies: 5
      Points: 30
      Rank: Member

      Hi,

      I did as you suggested, but seems that I am missing something.

      the command under the registry is:
      Powershell c:\scripts\run.ps1 %1

      What I should fill in run.ps1 under the -path parameter?
      $pc = c:\scripts\produtcode.ps1 -path “???” -property ProductCode
      Write-Output $pc | clip

      Thanks again

      Amir

      • This reply was modified 1 month ago by Amir Atary.
    • #268796
      Participant
      Topics: 5
      Replies: 177
      Points: 686
      Helping Hand
      Rank: Major Contributor

      %1 is the placeholder for this argument in the command.  I believe path was the only parameter so it is passing the argument positionally.  “Path” will have the full path to the msi file when this command is ran.

    • #269765
      Participant
      Topics: 4
      Replies: 5
      Points: 30
      Rank: Member

      Thank you very much

      Work like a charm 🙂

Viewing 4 reply threads
  • You must be logged in to reply to this topic.