Powershell Command Processing (Passing in Variables)

后端 未结 6 2206
没有蜡笔的小新
没有蜡笔的小新 2021-02-15 23:01

I\'m creating a Powershell script to deploy some code and part of the process is to call a command-line compression tool called RAR.EXE to back-up some folders.

I\'m at

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-15 23:53

    I have had problems with the & call operator in the past when trying to invoke executable type commands like you are trying. Not sure I understand why. Invoke-Expression however, always seems to work in this context:

    PS C:\> $cmd = "cmd /c echo foo"
    PS C:\> Invoke-expression $cmd
    foo
    

提交回复
热议问题