by pradeeprawat at 2013-02-22 23:35:28
Hi Experts,by mjolinor at 2013-02-23 10:23:18
I am looking for a way or to find the possibility to run the local powershell functions in a remoting session. E.g.
function foo{
worker
}
function worker{
ps lsass
}
Invoke-Command -ComputerName myserver01 -ScriptBlock {foo}
Any help or pointers will be appreciated. Thanks in advance.
Any functions you want to call in the script block have to be defined in the script block so they exist in the remote session.by pradeeprawat at 2013-02-23 10:38:09function foo{
worker
}
function worker{
ps lsass
}
$sb=[scriptblock]::create(@"
function foo {$function:foo}
function worker {$function:worker}
foo
"@)
Invoke-Command -ComputerName myserver01 -ScriptBlock $sb
Hey mjolinor, thanks that works like a charm. Totally forgot to use ScriptBlock