How to pass a local PS5 class to a remote session?

This topic contains 2 replies, has 2 voices, and was last updated by Profile photo of Zuldan Zuldan 8 months, 1 week ago.

  • Author
    Posts
  • #37013
    Profile photo of Zuldan
    Zuldan
    Participant

    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?

  • #37033
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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.

  • #37066
    Profile photo of Zuldan
    Zuldan
    Participant

    Thanks for the heads up Don.

You must be logged in to reply to this topic.