Using Invoke-Command -ScriptBlock on a function with arguments

后端 未结 3 1011
遥遥无期
遥遥无期 2020-11-29 22:08

I\'m writing a PowerShell script that will execute commands on a remote host using Invoke-Command and its -ScriptBlock parameter. For example,

         


        
3条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 22:16

    I think you want:

    function Foo ( $a,$b) {
        $a
        $b
        return "foo"
    }
    
    $x = "abc"
    $y= 123
    
    Invoke-Command -Credential $c -ComputerName $fqdn -ScriptBlock ${function:Foo} -ArgumentList $x,$y
    

提交回复
热议问题