Question on PSSession and Custom Object

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.

DLP Version : 15.1.0200.01028
Checking vfsmfd.sys in \System32\drivers : Exist
Checking vnwcd.sys in \System32\drivers : Exist
Checking vrtam.sys in \System32\drivers : Exist
Checking edpa.log in Manufacturer\Endpoint Agent : Not Exist
Checking edpa_ext0.log in Manufacturer\Endpoint Agent : Not Exist
Checking EDPA service : Stopped
Checking WDP service : Stopped

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.