Author Posts

March 27, 2016 at 11:01 pm

So pass to a local function you could do something like...

function FTest
{
Param([string]$Myoutput)
Write-Output $Myoutput
}

$FTestDef = "function FTest { ${function:FTest} }"

Invoke-Command -ArgumentList $FTestDef -ComputerName labserver01 -ScriptBlock {
Param( $FTestDef )

. ([ScriptBlock]::Create($FTestDef))

Write-Host "You can call the function as often as you like:"
FTest "It works!"
}

or something like

Invoke-Command -ScriptBlock ${function:foo} -argumentlist "Yay" -ComputerName labserver01

But how would you pass a PS5 class?

March 28, 2016 at 10:53 am

I'm not sure you can, in the current version (keep in mind classes are far from "done" at this point), apart from just statically passing it.

March 29, 2016 at 1:41 pm

Thanks for the heads up Don.