Passing parameter syntax

This topic contains 4 replies, has 3 voices, and was last updated by  Lery 4 years, 4 months ago.

  • Author
    Posts
  • #7891

    Lery
    Participant

    I need to execute a program.  The program has a switch that I need to pass to it.  The switch is throwing everything off.  I tried looking through the help and did not notice any options.

    invoke-item "c:\test\text.exe"
    
    I need to pass the switches /I and /Q
    
    If there is a better way to accomplish outside of using invoke-item, I'm fine with that.
  • #7894

    Don Jones
    Keymaster

    You don't need Invoke-Item.

    
    c:\test\text.exe /I /Q
    
    

    Should work fine. If it doesn't, and you're using PowerShell 3, consider using the "stop parsing the rest of this line" operator:

    
    c:\test\text.exe %-- /I /Q
    
    

    (from http://technet.microsoft.com/en-us/library/hh847892.aspx)

  • #7895

    Lery
    Participant

    [quote=7894]You don’t need Invoke-Item.

    c:\test\text.exe /I /Q

    Should work fine. If it doesn’t, and you’re using PowerShell 3, consider using the “stop parsing the rest of this line” operator:

    c:\test\text.exe %– /I /Q

    (from http://technet.microsoft.com/en-us/library/hh847892.aspx) [/quote]

    Don, that works perfectly thank you.  Is there some trick to getting it to work when spacing is applicable?  For example:

    c:\test\test.exe works perfectly

    c:\program files\test 1\test.exe does not work.  Enclosing it in single quotes or double quotes is not doing anything.

  • #7896

    Poshoholic
    Participant

    When spaces are involved, you need to use the invoke operator (&):

    & "C:\Program Files\Some.exe" ...

  • #7897

    Lery
    Participant

    [quote=7896]When spaces are involved, you need to use the invoke operator (&): & “C:\Program Files\Some.exe” … [/quote]

    I just had my Ah Ha moment!  Thank you 🙂

You must be logged in to reply to this topic.