Why PSObject is hidden?

Welcome Forums General PowerShell Q&A Why PSObject is hidden?

Viewing 4 reply threads
  • Author
    Posts
    • #24276
      Inactive
      Topics: 29
      Replies: 32
      Points: 0
      Rank: Member

      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
      Member
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      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
      Inactive
      Topics: 29
      Replies: 32
      Points: 0
      Rank: Member

      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
      Participant
      Topics: 9
      Replies: 1277
      Points: 1,051
      Helping Hand
      Rank: Community Hero

      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
      Member
      Topics: 9
      Replies: 2322
      Points: 0
      Rank: Member

      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.

Viewing 4 reply threads
  • The topic ‘Why PSObject is hidden?’ is closed to new replies.