Receive-Job alters object type / name

Welcome Forums General PowerShell Q&A Receive-Job alters object type / name

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
3 years, 9 months ago.

  • Author
    Posts
  • #21643

    Participant
    Points: 0
    Rank: Member

    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

    Keymaster
    Points: 7
    Rank: Member

    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.

The topic ‘Receive-Job alters object type / name’ is closed to new replies.