Passing “native” object to background jobs

前端 未结 2 1933
盖世英雄少女心
盖世英雄少女心 2020-12-19 02:11

Here is what I\'d like to achieve in one way or another.

I have a custom assembly defining some objects. In my script, I create a custom object that I\'d like to pa

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-19 03:10

    Background jobs are built on top of PowerShell remoting and as such, perform similar actions when passing objects around. They would serialize/ deserialize them rather than pass them with all their complexity.

    My guess is that the only way to get complex object is just to pass constructor arguments and/ or operations as -ArgumentList and create object inside job.

    In such a case also adding assembly would have to be part of the job:

    Start-Job {
        param ($ConstructorArguments)
        Add-Type -AssemblyName MyCustomDll
        $object = New-Object MyCustomDll.MyCustomObject $ConstructorArguments
        $object | Get-Member
    } -ArgumentList Foo, Bar | Wait-Job | Receive-Job 
    

提交回复
热议问题