How to Invoke-Command and pass path to command as parameter

后端 未结 2 2070
名媛妹妹
名媛妹妹 2021-01-16 03:05

I\'m tearing my hair out trying to invoke-command but pass the path to the exe as a parameter

eg: I want to take this command

powershell Invoke-Comma         


        
2条回答
  •  误落风尘
    2021-01-16 03:26

    Try this option. It shows me help for cscript.exe.

    C:\>powershell.exe Invoke-Command -ComputerName localhost -ScriptBlock { param($path, $command ) cmd /c $path $command } -args '"C:\windows\system32\cscript.exe"','"/?"'
    

    I tried other options using & and then path and arguments and it was giving me missing } exception. Then using cmd /c instead of & inside scriptblock fixed the issue.

提交回复
热议问题