Powershell Command Processing (Passing in Variables)

后端 未结 6 2156
没有蜡笔的小新
没有蜡笔的小新 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:50

    Args are treated differently when they are contained in a String:

    PS D:\> echo "1 2 3"
    1 2 3
    PS D:\> echo 1 2 3
    1
    2
    3
    

    The same results occur when you use a variable for the args:

    PS D:\> $param = "1 2 3"
    PS D:\> echo $param
    1 2 3
    

    The SOLUTION is to use an Array:

    PS D:\> $param = @(1,2,3)
    PS D:\> echo $param
    1
    2
    3
    

提交回复
热议问题