locked
Selecting a specific ProxyAddress RRS feed

  • Question

  • Hi Guys, 

    I'm trying to search users based on e-mail from Domain A and take a specific proxy address from their list. I will then use that variable to put that as a targetAddress in Domain B. I cannot seem to find how to select a specific proxy address.

    get-aduser -filter "Mail -like 'John.Smith@contoso.com'" -Properties ProxyAddresses | Select -ExpandProperty ProxyAddresses | Where $_ -like "*@MyDomain.com"

    I keep receiving this error:

    Where-Object : Cannot validate argument on parameter 'Property'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command aga
    At line:1 char:120
    + ... -Properties ProxyAddresses | Select ProxyAddresses | Where $_ -like " ...
    +                                                                ~~
        + CategoryInfo          : InvalidData: (:) [Where-Object], ParameterBindingValidationException
        + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.WhereObjectCommand

    I cannot use something like this because the proxies i want will be in different array indexes for everyone

    $array = get-aduser -filter "Mail -like 'John.Smith@contoso.com'" -Properties ProxyAddresses | Select -ExpandProperty ProxyAddresses
    $array[0]

    Using the following command I can retrieve all the proxies in an array but cannot select a specific one.

    get-aduser -filter "Mail -like 'John.Smith@contoso.com'" -Properties ProxyAddresses | Select -ExpandProperty ProxyAddresses





    • Edited by MC Nunzio Tuesday, August 13, 2019 3:57 PM
    Tuesday, August 13, 2019 3:55 PM

Answers

  • Get-AdUser -filter "Mail -eq 'XXXXXXXXX@xyz.com'" -Properties proxyAddresses |
        Select-Object -ExpandProperty proxyAddresses |
        Where-Object{ $_ -match '@xyz.com'}

    Using proper constructs makes this easier and more reliable.

    It is also best to avoid cramming everything on one line.


    \_(ツ)_/



    • Edited by jrv Tuesday, August 13, 2019 4:37 PM
    • Marked as answer by MC Nunzio Tuesday, August 13, 2019 5:08 PM
    Tuesday, August 13, 2019 4:36 PM

All replies

  • use this 
     get-aduser -filter "Mail -like 'XXXXXXXXX@xyz.com' "  -Properties proxyAddresses | select  -ExpandProperty proxyAddresses | % { if ( $_ -like "*abc@xyz.com") { write-host $_ } }

    Tuesday, August 13, 2019 4:23 PM
  • Get-AdUser -filter "Mail -eq 'XXXXXXXXX@xyz.com'" -Properties proxyAddresses |
        Select-Object -ExpandProperty proxyAddresses |
        Where-Object{ $_ -match '@xyz.com'}

    Using proper constructs makes this easier and more reliable.

    It is also best to avoid cramming everything on one line.


    \_(ツ)_/



    • Edited by jrv Tuesday, August 13, 2019 4:37 PM
    • Marked as answer by MC Nunzio Tuesday, August 13, 2019 5:08 PM
    Tuesday, August 13, 2019 4:36 PM
  • To learn how to properly write PS code see the following guidelines:

    The PowerShell Best Practices and Style Guide


    \_(ツ)_/

    Tuesday, August 13, 2019 4:38 PM
  • Thanks for this. I just slightly modified this and instead of -match i use -like and it worked as intended
    Tuesday, August 13, 2019 5:09 PM