PowerShell Pass Named parameters to ArgumentList

前端 未结 7 1952
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 08:14

I have a PowerShell script that accepts 3 named parameters. Please let me know how to pass the same from command line. I tried below code but same is not working. It assigns the

7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-20 08:50

    Here's a simple solution:

    [PowerShell]::Create().AddCommand('D:\test.ps1').AddParameters(@{ P1 = 1; P2 = 2; P3 = 3 }).Invoke()
    

    Here's output:

    PS C:\Windows\system32> [PowerShell]::Create().AddCommand('D:\test.ps1').AddParameters(@{ P1 = 1; P2 = 2; P3 = 3 }).Invoke()
    P1 Value :
    1
    P2 Value:
    2
    P3 Value :
    3
    

提交回复
热议问题