Select specific value from Multi-Value attribute

Welcome Forums General PowerShell Q&A Select specific value from Multi-Value attribute

Viewing 2 reply threads
  • Author
    Posts
    • #192727
      Participant
      Topics: 28
      Replies: 44
      Points: 165
      Rank: Participant

      I need to be able to iterate through the values in a multi-value property (AD or Exchange) and set a variable with a specific value if it exists.

      I have read numerous articles on how to add, remove specific values from/to a multi-value property but haven’t been able to successfully figure out how to capture a specific one into a variable for use later in the script.

      Example: Set variable if the address @contoso.com exists

      ProxyAddresses (AD) or EmailAddresses (Exchange) loop through these values and set $var1 to the value for the @contoso.com address if it exists.

      smtp: [email protected]
      smtp: [email protected]
      smtp: [email protected]
      smtp: [email protected]$

      I have this much:

    • #192736
      Participant
      Topics: 12
      Replies: 38
      Points: 261
      Helping Hand
      Rank: Contributor

      It might not be the most efficient, but I’d do ForEach ($add in $Var) {IF($Add -like “*@contoso.com”) {$var1 = $Add}}.

       

      • #192742
        Participant
        Topics: 28
        Replies: 44
        Points: 165
        Rank: Participant

        At this point as long as it works, I will take it.   I can revise for efficiency at a later date.

        Thank you

         

    • #192772
      Participant
      Topics: 13
      Replies: 1753
      Points: 3,136
      Helping Hand
      Rank: Community Hero
Viewing 2 reply threads
  • The topic ‘Select specific value from Multi-Value attribute’ is closed to new replies.