PowerShell Pass Named parameters to ArgumentList

前端 未结 7 1842
没有蜡笔的小新
没有蜡笔的小新 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 09:07

    One option:

    $params = @{
    P1 = 1
    P2 = 2 
    P3 = 3
    }
    
    $ScriptPath = 'D:\Test.ps1'
    
    $sb = [scriptblock]::create(".{$(get-content $ScriptPath -Raw)} $(&{$args} @params)")
    
    Invoke-Command -ComputerName server -ScriptBlock $sb
    

提交回复
热议问题