Author Posts

June 7, 2018 at 9:39 am

Hi Masters,

I have just achieved on executing a function on remote machine using the code below.

Function Foo {
param( [String[]] $str )
#do stuff here
}

Invoke-Command -ComputerName $server -ScriptBlock ${Function:Foo} -ArgumentList @(,$str)

However, I couldn't make it work when using start-job, since I wanted this to be in background job for windows form. I am using the below that didn't work.

$thisSB = { Invoke-Command -ComputerName $args[0] -ScriptBlock ${Function:args[1]} -ArgumentList @(,$args[2]) }
Start-Job -Name getTempAccJob -Scriptblock $thisSB -ArgumentList $server,$thisSB,@(,$str)

Please help, I'm totally out of resource.

Thanks.

June 7, 2018 at 12:24 pm

After long research and not knowing everything of Invoke-Command, simply adding -Asjob will do.