Why PSObject is hidden?

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Dave Wyatt Dave Wyatt 2 years, 1 month ago.

  • Author
    Posts
  • #24276
    Profile photo of
    Anonymous

    Hi Guys,
    Could some one please reveal the secret why $XXX.PSOBJECT is hidden (.PSObject)? What hidden I mean is, I cannot find this in intelligence. To be honest until Don Jones said about in one of my previous posts !!

    Do we have any more such hidden ones ( i don't know technically what PSObject is called)? If so how to self explore and know about this?

  • #24277
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Are you asking about the output of Get-Member? You can display that information by using the -Force switch on that cmdlet. I assume that they're hidden by default simply because they exist on every single object in PowerShell, and would clutter up the output. (They're also rarely needed from inside a PowerShell script.)

    The Get-Member help file has this to say about the -Force switch: "Adds the intrinsic members (PSBase, PSAdapted, PSObject, PSTypeNames) and the compiler-generated get_ and set_ methods to the display. By default, Get-Member gets these properties in all views other than "Base" and "Adapted," but it does not display them."

  • #24278
    Profile photo of
    Anonymous

    WOW. Fantastic. Thanks a lot Wyatt. I was not aware of " | gm -force"
    Now I am relaxed, because its proved that Microsoft is not hiding anything (in PS) and which can be explored only by programmers or like you or Don or Jeff..etc.

    My ego satisfied :-p

  • #24294
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    The only time I've use PSObject is to enumerate the Name (attribute\column name) and Value...

    $processes = Get-Process | Select Name, Company, WS -First 3
    
    $processes | foreach {
        $_.PSObject.Properties | foreach {
            "ColumnName: {0}" -f $_.Name
            "ColumnValue: {0}" -f $_.Value
        }
    
    }
    

    Output:

    ColumnName: Name
    ColumnValue: agent
    ColumnName: Company
    ColumnValue: 
    ColumnName: WS
    ColumnValue: 6688768
    ColumnName: Name
    ColumnValue: armsvc
    ColumnName: Company
    ColumnValue: 
    ColumnName: WS
    ColumnValue: 1708032
    ColumnName: Name
    ColumnValue: chrome
    ColumnName: Company
    ColumnValue: Google Inc.
    ColumnName: WS
    ColumnValue: 28418048
    
    
  • #24296
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    It's sometimes handy to make code compatible with StrictMode (where trying to access a non-existent property on an object will produce an error.) So I use $object.PSObject.Properties['PropertyName'] in order to check whether the property exists.

You must be logged in to reply to this topic.