Receive-Job alters object type / name

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 1 year, 11 months ago.

  • Author
    Posts
  • #21643

    Dear all,

    I am attempting to use start-job in combination with a function that returns a Invoke-Webrequest session variable.
    When performing .getType() on returned variable:

    IsPublic IsSerial Name BaseType
    ——– ——– —- ——–
    True False WebRequestSession System.Object

    However when using job-start (or related commands) it changes the object to:
    IsPublic IsSerial Name BaseType
    ——– ——– —- ——–
    True False PsObject System.Object

    This object is no longer a valid Invoke-Session variable and is rejected by all following Invoke-WebRequest commands. Although the variable contains all the required data,

    Question: How can I instruct start-job (or receive-job) to return the object in its original state? It seems receive-job always returns a PsObject.

    Best Regards,

    Christian

  • #21644
    Profile photo of Don Jones
    Don Jones
    Keymaster

    Yeah, you kinda can't. That's because the job results are serialized and then deserialized, and in the process what PowerShell constructs isn't the same kind of thing. It's no longer a "live" object, so to speak. It's been translated to XML and back. Sorta.

    If your goal is to use some of the data in the object's properties, you'd need to do so directly by accessing those properties.

You must be logged in to reply to this topic.