将参数传递给Invoke-Command

时间:2018-10-29 11:30:03

标签: powershell powershell-workflow

这是我的脚本:

workflow Run-RemoteScript {
    Param(
        [Parameter(Mandatory,Position=0)][string[]]$Targets,
        [Parameter(Mandatory,Position=1)][PSCredential]$Credentials,
        [Parameter(Mandatory,Position=1)][String]$Path
    )
    foreach -parallel ($Target in $Targets) {
        parallel {
            "Executing on: $Target"
            InlineScript {
                Invoke-Command -FilePath $using:Path -ComputerName $using:Target -Credential $using:Credentials 
            }
        }
    }
}

此工作流程嵌套在一个函数中。如何将参数从顶级函数传递到Invoke-Command?在InlineScript{}里面? $using:MyVar似乎无效。

1 个答案:

答案 0 :(得分:0)

查看有关Invoke-Command的帮助。有两种方法可以实现此目的,而又不会增加工作流程的复杂性。例如,查看-ThrottleLimit或-InDisconnectedSession参数。示例16可能具有相关性

相关问题