Welcome › Forums › General PowerShell Q&A › Question on PSSession and Custom Object
- This topic has 1 reply, 2 voices, and was last updated 2 weeks ago by
Participant.
-
AuthorPosts
-
-
January 12, 2021 at 3:31 am #285388
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.PowerShell123456789Server: RZAPRVMRDS05DLP Version : 15.1.0200.01028Checking vfsmfd.sys in \System32\drivers : ExistChecking vnwcd.sys in \System32\drivers : ExistChecking vrtam.sys in \System32\drivers : ExistChecking edpa.log in Manufacturer\Endpoint Agent : Not ExistChecking edpa_ext0.log in Manufacturer\Endpoint Agent : Not ExistChecking EDPA service : StoppedChecking WDP service : Stopped-
This topic was modified 2 weeks ago by
mrdon03.
-
This topic was modified 2 weeks ago by
-
January 12, 2021 at 8:09 am #285442
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.
-
This reply was modified 2 weeks ago by
metablaster.
-
This reply was modified 2 weeks ago by
-
-
AuthorPosts
- You must be logged in to reply to this topic.