Question on PSSession and Custom Object

Welcome Forums General PowerShell Q&A Question on PSSession and Custom Object

Viewing 1 reply thread
  • Author
    Posts
    • #285388
      Participant
      Topics: 12
      Replies: 12
      Points: 145
      Rank: Participant

      Hi
      Here is the output of my present script. I am creating New-PSSession to each server for the output. Can someone show me how can I relate it to CustomObject so that I can get the format table output at the end. Please give 1 example of creating CustomObject in PSSession.

      • This topic was modified 2 weeks ago by mrdon03.
    • #285442
      Participant
      Topics: 6
      Replies: 14
      Points: 126
      Rank: Participant

      PSSession object has properties as documented here:

      PSSession Class (System.Management.Automation.Runspaces) | Microsoft Docs

       

      Therefore all you have to do is create a custom object, for example:

      [PSSession] $Session = New-PSSession ...

      $MyCustomObject = [PSCustomObject] @{

             Domain = $Session.ComputerName

             Name = $Session.Name

             # etc. continue adding properties yourself here...

      }

      $MyCustomObject | Format-Table

      That’s pretty easy and straightforward unless you want something else.

      I think you should also be able to just run:

      [PSCustomObject] $MyCustomObject = $Session -As [PSCustomObject]

      But I’m not sure.

Viewing 1 reply thread
  • You must be logged in to reply to this topic.