locked
read a registry value and execute it isn't working RRS feed

  • Question

  • hi all,

    I'm creating a tool for our team which requires that some PS1 scripts are edited to enter some values when installing a software, like the MSI file name and parameters, etc...

    I had the idea to read the registry value to locate and start PowerShell instead of the default engine because we have several editors and I would like that everyone can use his/her own preferred one.

    here's my attempt;

    $string = ((get-itemproperty -literalpath HKLM:\SOFTWARE\Classes\Microsoft.PowerShellScript.1\Shell\edit\command).'(default)')
    $string = $string.remove($string.length - 5)
    
    & $string 

    When the script hits the execution (&), it gives me this error, and I can't understand why. Can someone please give me a clue on what is wrong?

    ERROR: & : The term '"C:\Program Files\SAPIEN Technologies, Inc\PowerShell Studio 2017\PowerShell Studio.exe"' is not recognized as the name of a cmdlet, function,
    ERROR: script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
    1.ps1 (6, 3): ERROR: At Line: 6 char: 3
    ERROR: + & $string
    ERROR: +   ~~~~~~~
    ERROR:     + CategoryInfo          : ObjectNotFound: ("C:\Program Fil...ell Studio.exe":String) [], CommandNotFoundException
    ERROR:     + FullyQualifiedErrorId : CommandNotFoundException
    ERROR:

    thank you!

    Monday, July 3, 2017 7:18 PM

Answers

  • This is how to remove unwanted bits:

    $cmd = $string -replace '"|%1'
    & $cmd


    \_(ツ)_/

    • Marked as answer by Kardock Tuesday, July 4, 2017 12:19 PM
    Monday, July 3, 2017 7:47 PM

All replies

  • This is how to remove unwanted bits:

    $cmd = $string -replace '"|%1'
    & $cmd


    \_(ツ)_/

    • Marked as answer by Kardock Tuesday, July 4, 2017 12:19 PM
    Monday, July 3, 2017 7:47 PM
  • nice trick. I'll keep this one for sure.

    thanks!

    Tuesday, July 4, 2017 12:19 PM