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,435 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 32,326 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 100.7K 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 45,431 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