invoke expression use

St R 1 Reputation point
2020-12-19T19:25:38.503+00:00

Is this a valid command, to have a cmd.exe open and run a file with proper switches?

start-process -filepath "cmd.exe"
Invoke-Expression -Command "C:\Program Files\TestAppDiagnosticsCli.exe /bi/c"

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,363 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 29,651 Reputation points Microsoft Vendor
    2020-12-21T06:45:06.217+00:00

    Hi

    You can run it directly in powershell

    C:\Program Files\TestAppDiagnosticsCli.exe /bi/c  
    

    or use the call operator

    & 'C:\Program Files\TestAppDiagnosticsCli.exe' /bi/c  
    

    Best Regards,
    Ian Xue

    ============================================

    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

  2. Andreas Baumgarten 96,361 Reputation points MVP
    2020-12-19T20:02:34.78+00:00

    It should be possible to start the exe directly without starting a cmd.exe:

    & "C:\Program Files\TestAppDiagnosticsCli.exe /bi/c"
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten

    0 comments No comments

  3. Rich Matheisen 44,776 Reputation points
    2020-12-19T20:22:18.017+00:00

    No, it's not. Use the call operator instead. about_operators

    See this, too: invoke-expression-considered-harmful

    This should work for you:

    & 'C:\Program Files\TestAppDiagnosticsCli.exe' /bi/c  
    
    0 comments No comments