locked
ProxyAddress class, C#, Exchange 2010, Powershell 2 RRS feed

  • Question

  • In C#, I am trying to get the the property on the Exchange mailbox of a user, "EmailAddresses" using powershell 2010. Previously I had code that did it for Powershell 1.0 but it seems that the type of the results returned from the get-mailbox command has changed with regard to this property.

    for powershell 1.0, this used to work.

    emailaddresses  = ps.Members["EmailAddresses"].Value as Microsoft.Exchange.Data.ProxyAddressCollection;

    Now however, it complains that 

    ps.Members["EmailAddresses"].Value is a PSMemberInfo.Value

    OK, I can grab the string from it using this

    ps.Members["EmailAddresses"].Value.ToString();

    but I still need the type ProxyAddress for the code varaible emailaddresses.

    ProxyAddress() constructo is protected and  I can't see to cast it from string to type ProxyAddress.

    I saw in a code sample: http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/thread/593e0793-2485-431a-a923-c5acf53bd65a/ where Mangia did this:

    Microsoft.Exchange.Data.ProxyAddress externalemailaddr = new Microsoft.Exchange.Data.SmtpProxyAddress(emailmail, true);

    Can someone give me pointers to the derived classes of ProxyAddress?

    I have searched on the web without success.

    Is there a way to construct a new ProxyAddress from a string?

    I have to put all the email addresses in the string into a ProxyAddressCollection to make it work again.

    Any help or references would be greatly appreciated. This is powershell 2 and Exchange 2010

    Thanks in advance.

    • Moved by Lisa Zhu Wednesday, October 17, 2012 9:36 AM (From:Visual C# General)
    • Moved by Just Karl Wednesday, October 17, 2012 1:37 PM Moving to correct forum (From:Where is the Forum For…?)
    Thursday, October 11, 2012 1:31 PM

Answers

  • Had to process thes returned object differently, without the Powershell Snapin....no wrappers.

    So:

    emailaddresses = CreateEmailAddresses(ps.Members["EmailAddresses"].Value.ToString());

            private ProxyAddressCollection CreateEmailAddresses(string value)
            {
                // var a = ps.Members["EmailAddresses"].Value;
                // get string of ps.Members["EmailAddresses"].Value, see if valid...ProxyAddressBase.IsAddressStringValid Method                 
                // add it to ProxyAddressCollection
                // then add it to emailaddresses {emailaddresses.Add(validaddressstring)}
                // the string, value can contain stuff like "SMTP:pegduffy@whyu.edu smtp:pegduffy@bozo.com"
                emailaddresses = new ProxyAddressCollection();
                string[] addrs = value.Split(' ');
                foreach (string addr in addrs)
                {
                    var valid_address = Regex.Replace(addr, "smtp:", "", RegexOptions.IgnoreCase);
                    ProxyAddress address;
                    if (ProxyAddressBase.IsAddressStringValid(valid_address))
                    {
                        address = new SmtpProxyAddress(valid_address, false);
                        emailaddresses.Add(address);
                    }
                    else //could emailaddresses be empty?
                    {
                        emailaddresses.Add(new SmtpProxyAddress("", false));
                    }
                }
                return emailaddresses;
            

    • Marked as answer by P Duffy Wednesday, October 17, 2012 5:12 PM
    Wednesday, October 17, 2012 5:12 PM

All replies

  • I am not sure this is the right forum for this topic, maybe Exchange Development .:)
    Monday, October 15, 2012 10:16 AM
  •  Hi P Duffy,

    Thank you for visiting the MSDN forum.

    I’m afraid that it is not the correct forum about this issue. I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum. Thanks for your understanding.

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, October 17, 2012 9:35 AM
  • I think BlueblueSumerSky is right - this should be in Exchange Development.

    I'm moving it to that forum.

    Karl


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    My Blog: http://unlockpowershell.wordpress.com
    My Book: Windows PowerShell 2.0 Bible
    My E-mail: -join ("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})

    Wednesday, October 17, 2012 1:34 PM
  • Had to process thes returned object differently, without the Powershell Snapin....no wrappers.

    So:

    emailaddresses = CreateEmailAddresses(ps.Members["EmailAddresses"].Value.ToString());

            private ProxyAddressCollection CreateEmailAddresses(string value)
            {
                // var a = ps.Members["EmailAddresses"].Value;
                // get string of ps.Members["EmailAddresses"].Value, see if valid...ProxyAddressBase.IsAddressStringValid Method                 
                // add it to ProxyAddressCollection
                // then add it to emailaddresses {emailaddresses.Add(validaddressstring)}
                // the string, value can contain stuff like "SMTP:pegduffy@whyu.edu smtp:pegduffy@bozo.com"
                emailaddresses = new ProxyAddressCollection();
                string[] addrs = value.Split(' ');
                foreach (string addr in addrs)
                {
                    var valid_address = Regex.Replace(addr, "smtp:", "", RegexOptions.IgnoreCase);
                    ProxyAddress address;
                    if (ProxyAddressBase.IsAddressStringValid(valid_address))
                    {
                        address = new SmtpProxyAddress(valid_address, false);
                        emailaddresses.Add(address);
                    }
                    else //could emailaddresses be empty?
                    {
                        emailaddresses.Add(new SmtpProxyAddress("", false));
                    }
                }
                return emailaddresses;
            

    • Marked as answer by P Duffy Wednesday, October 17, 2012 5:12 PM
    Wednesday, October 17, 2012 5:12 PM