{"id":69843,"date":"2005-05-10T16:55:00","date_gmt":"2005-05-10T16:55:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/05\/10\/how-can-i-add-an-email-address-to-the-proxyaddresses-attribute\/"},"modified":"2005-05-10T16:55:00","modified_gmt":"2005-05-10T16:55:00","slug":"how-can-i-add-an-email-address-to-the-proxyaddresses-attribute","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-add-an-email-address-to-the-proxyaddresses-attribute\/","title":{"rendered":"How Can I Add an Email Address to the proxyAddresses Attribute?"},"content":{"rendered":"<p><H2><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> <\/H2>\n<P>Hey, Scripting Guy! How can I add an email address to the proxyAddresses attribute without overwriting all the existing attributes?<BR><BR>&#8212; DH<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, DH. For those of you who aren\u2019t too familiar with the proxyAddresses attribute (and, alas, that includes the Scripting Guys) proxyAddresses is an attribute added to Active Directory by Microsoft Exchange; it\u2019s simply an alias by which an Exchange user can be recognized by a non-Exchange mail system. If you echo back the proxy addresses for a given user you\u2019re likely to see something similar to this:<\/P><PRE class=\"codeSample\">NUMERIC:4257050743\nsip:kenmyer@fabrikam.com\nX500:\/o=fabrikam\/ou=APPS-WGA\/cn=Xenix_Users\/cn=kenmyer\nX500:\/o=fabrikam\/ou=First Administrative Group\/cn=Recipients\/cn=kenmyer\nx400:c=US;a=MCI;p=fab;o=northamerica;s=Myer;g=Ken;\nX500:\/O=fabrikam\/OU=northamerica\/cn=Recipients\/cn=kenmyer\nX400:c=US;a=finance;p=fabrikam;o=fabrikam;s=Myer;g=Ken;\nx500:\/o=fabrikam\/ou=northamerica\/cn=Recipients\/cn=556899\nsmtp:kenmyer@fabrikam.com\nSMTP:kenmyer@finance.fabrikam.com\n<\/PRE>\n<P>If you\u2019re thinking, \u201cWow, that\u2019s s lot of stuff for one little attribute to have,\u201d well, that\u2019s because proxyAddresses happens to be a multi-valued attribute, an attribute that can contain more than one value. And that\u2019s why this particular question is so tricky. Suppose we wanted to add a new proxy address &#8211; kenmyer@northamerica.fabrikam.com &#8211; to the list of proxyAddresses. We don\u2019t want to delete the existing addresses; we just want to add an additional one.<\/P>\n<P>Hey, no problem; after all, everyone knows how to modify an Active Directory attribute, right? And so you try a script similar to this:<\/P><PRE class=\"codeSample\">Set objUser = GetObject _\n    (&#8220;LDAP:\/\/atl-dc-1\/CN=Ken Myer,OU=Finance,DC=fabrikam,DC=com&#8221;)\nobjUser.proxyAddresses = kenmyer@northamerica.fabrikam.com\nobjUser.SetInfo\n<\/PRE>\n<P>And guess what you get back the next time you echo Ken Myer\u2019s proxy addresses:<\/P><PRE class=\"codeSample\">kenmyer@northamerica.fabrikam.com\n<\/PRE>\n<P>Uh-oh: we deleted all the old proxy addresses and <I>replaced<\/I> them with the new address. Not what we wanted to do at all.<\/P>\n<P>So how can we simply tack an additional value onto the end of a multi-valued attribute? Why, we just need to use the <B>PutEx<\/B> method:<\/P><PRE class=\"codeSample\">Const ADS_PROPERTY_APPEND = 3<\/p>\n<p>Set objUser = GetObject _\n    (&#8220;LDAP:\/\/cn=KenMyer,ou=Finance,dc=fabrikam,dc=com&#8221;) <\/p>\n<p>objUser.PutEx ADS_PROPERTY_APPEND, &#8220;proxyAddresses&#8221;, _\n    Array(&#8220;kenmyer@northamerica.fabrikam.com &#8220;)\n<\/PRE>\n<P>PutEx is an ADSI method designed for working with multi-valued attributes; in fact, PutEx offers four different options for working with multi-valued attributes:<\/P>\n<TABLE id=\"EKD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Constant<\/B><\/P><\/TD>\n<TD>\n<P class=\"lastInCell\"><B>Value<\/B><\/P><\/TD>\n<TD>\n<P class=\"lastInCell\"><B>Description<\/B><\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">ADS_PROPERTY_CLEAR<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">1<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">Clears the value (or values) from the specified attribute.<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">ADS_PROPERTY_UPDATE<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">2<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">Replaces the value in the specified attribute with new values.<\/P><\/TD><\/TR>\n<TR class=\"evenRecord\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">ADS_PROPERTY_APPEND<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">3<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">Appends a new value (or values) to the specified attribute.<\/P><\/TD><\/TR>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\">ADS_PROPERTY_DELETE<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">4<\/P><\/TD>\n<TD>\n<P class=\"lastInCell\">Deletes the value (or values) from the specified attribute.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>We won\u2019t spend a lot of time detailing how PutEx works; for more information you might check out the <A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/guide\/sas_ads_kbwl.mspx\" target=\"_blank\"><B>Modifying Multivalued Attributes<\/B><\/A> section in the <I>Microsoft Windows 2000 Scripting Guide<\/I>.<\/P>\n<P>Now, back to our script. We want to append a new value to proxyAddresses; consequently in the first line of the script we define a constant named ADS_PROPERTY_APPEND and set the value to 3:<\/P><PRE class=\"codeSample\">Const ADS_PROPERTY_APPEND = 3\n<\/PRE>\n<P>We bind to the Ken Myer user account and then call the PutEx method, passing three parameters:<\/P>\n<TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>The constant ADS_PROPERTY_APPEND, which tells the script to <I>append<\/I> the new value to any existing values.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>The name of the attribute we want to work with (proxyAddresses).<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P>The value we want to append (in other words, the new proxy address).<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>Note that even though we\u2019re adding only a single value we need to pass that value as an array; hence our actual code looks like this:<\/P><PRE class=\"codeSample\">objUser.PutEx ADS_PROPERTY_APPEND, &#8220;proxyAddresses&#8221;, _\n    Array(&#8220;kenmyer@northamerica.fabrikam.com&#8221;)\n<\/PRE>\n<P>And what do we get when we echo the proxy addresses for Ken Myer:<\/P><PRE class=\"codeSample\">kenmyer@northamerica.fabrikam.com \nNUMERIC:4257050743\nsip:kenmyer@fabrikam.com\nX500:\/o=fabrikam\/ou=APPS-WGA\/cn=Xenix_Users\/cn=kenmyer\nX500:\/o=fabrikam\/ou=First Administrative Group\/cn=Recipients\/cn=kenmyer\nx400:c=US;a=MCI;p=fab;o=northamerica;s=Myer;g=Ken;\nX500:\/O=fabrikam\/OU=northamerica\/cn=Recipients\/cn=kenmyer\nX400:c=US;a=finance;p=fabrikam;o=fabrikam;s=Myer;g=Ken;\nx500:\/o=fabrikam\/ou=northamerica\/cn=Recipients\/cn=556899\nsmtp:kenmyer@fabrikam.com\nSMTP:kenmyer@finance.fabrikam.com\n<\/PRE>\n<P>Cool, huh?<\/P>\n<P>Incidentally, there\u2019s no guarantee that the new proxy address will show up first in the list of addresses; when it comes to multi-valued attributes the order of the individual attributes is not guaranteed. But that doesn\u2019t matter just as long as kenmyer@northamerica.fabrikam.com shows up <I>somewhere<\/I> in the list.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I add an email address to the proxyAddresses attribute without overwriting all the existing attributes?&#8212; DH Hey, DH. For those of you who aren\u2019t too familiar with the proxyAddresses attribute (and, alas, that includes the Scripting Guys) proxyAddresses is an attribute added to Active Directory by Microsoft Exchange; it\u2019s simply [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,27,28,29,200,3,20,5],"class_list":["post-69843","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-exchange","tag-messaging-and-communication","tag-microsoft-exchange-2003","tag-microsoft-exchange-2007","tag-scripting-guy","tag-user-accounts","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I add an email address to the proxyAddresses attribute without overwriting all the existing attributes?&#8212; DH Hey, DH. For those of you who aren\u2019t too familiar with the proxyAddresses attribute (and, alas, that includes the Scripting Guys) proxyAddresses is an attribute added to Active Directory by Microsoft Exchange; it\u2019s simply [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69843","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=69843"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69843\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=69843"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69843"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69843"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}