Extract Single specific value from Multi-Value Attribute

Welcome Forums General PowerShell Q&A Extract Single specific value from Multi-Value Attribute

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
2 weeks, 3 days ago.

  • Author
    Posts
  • #180953

    Participant
    Topics: 26
    Replies: 41
    Points: 134
    Rank: Participant

    Is there a simpler way to extract a specific value from a multi-value attribute in AD or Exchange?   Currently doing this (returns john.doe@contoso.com).   Would love to be able to get this in a single step instead of multiple steps.

    
    $var = get-unifiedgroup xxxx | select -expandproperty emailaddresses
    
    $var1 = $var[0].substring(5)
    
    
  • #180965

    Participant
    Topics: 6
    Replies: 97
    Points: 239
    Helping Hand
    Rank: Participant

    You can shorten it to one line. It gets a little more complicated to read, but it should work the same.

    We don't use O365, so I don't have the same cmdlets. But this case should work the same way:

    PS C:\> (get-aduser user1 -Properties msExchMailboxGuid).msExchMailboxGuid
    21
    145
    67
    178
    141
    184
    137
    73
    183
    ...
    PS C:\> (get-aduser user1 -Properties msExchMailboxGuid).msExchMailboxGuid[0]
    21
    
    • #180995

      Participant
      Topics: 26
      Replies: 41
      Points: 134
      Rank: Participant

      Unfortunately when you are getting information from Exchange you don't get the -properties attribute.   You have to use select:

      get-unifiedgroup xxxxx | select emailaddresses

      Update.  I didn't realize you could do the same thing with that command:    (get-unifiedgroup xxxxx | select -emailaddresses).emailaddresses[0]

      That worked.   Now to see if I can add substring to that.

    • #181001

      Participant
      Topics: 6
      Replies: 97
      Points: 239
      Helping Hand
      Rank: Participant

      Yep! You should be able to string it all together:

      (get-unifiedgroup xxxx | select -expandproperty emailaddress).emailaddress[0].Substring(5)
      

      If you want to verify it is a string before you try to run Substring() against it,p ipe the object to Get-Member or run the GetType() method:

      PS C:\> (get-aduser user1 -Properties showinaddressbook).showinaddressbook[0] | get-member
      
      
         TypeName: System.String
      
      Name             MemberType            Definition
      ----             ----------            ----------
      Clone            Method                System.Object Clone(), System.Object ICloneable.Clone()
      CompareTo        Method                int CompareTo(System.Object value), int CompareTo(string strB), int IComparab...
      Contains         Method                bool Contains(string value)
      CopyTo           Method                void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int co...
      EndsWith         Method                bool EndsWith(string value), bool EndsWith(string value, System.StringCompari...
      Equals           Method                bool Equals(System.Object obj), bool Equals(string value), bool Equals(string...
      GetEnumerator    Method                System.CharEnumerator GetEnumerator(), System.Collections.IEnumerator IEnumer...
      GetHashCode      Method                int GetHashCode()
      GetType          Method                type GetType()
      GetTypeCode      Method                System.TypeCode GetTypeCode(), System.TypeCode IConvertible.GetTypeCode()
      ...
      ...
      ...
      
      
      PS C:\> (get-aduser user1 -Properties showinaddressbook).showinaddressbook[0].GetType()
      
      IsPublic IsSerial Name                                     BaseType
      -------- -------- ----                                     --------
      True     True     String                                   System.Object
      

You must be logged in to reply to this topic.