{"id":3186,"date":"2013-07-21T00:01:00","date_gmt":"2013-07-21T00:01:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2013\/07\/21\/weekend-scripter-create-proxy-addresses-in-active-directory-with-powershell\/"},"modified":"2013-07-21T00:01:00","modified_gmt":"2013-07-21T00:01:00","slug":"weekend-scripter-create-proxy-addresses-in-active-directory-with-powershell","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/weekend-scripter-create-proxy-addresses-in-active-directory-with-powershell\/","title":{"rendered":"Weekend Scripter: Create Proxy Addresses in Active Directory with PowerShell"},"content":{"rendered":"<p><strong style=\"font-size: 12px\">Summary<\/strong><span style=\"font-size: 12px\">: Microsoft Scripting Guy, Ed Wilson, shows how to automatically create p<\/span>roxy addresses<span style=\"font-size: 12px\"> in Active Directory Domain Services by using Windows PowerShell.<\/span><\/p>\n<p>Microsoft Scripting Guy, Ed Wilson, is here. So I have been talking back and forth with one of the members of the Charlotte Windows PowerShell Users group since my presentation to the group on the first Thursday of the month. One of the questions he has is related to the <strong>ProxyAddresses<\/strong> attribute in Active Directory Domain Services (AD DS).<\/p>\n<p>As you are probably aware, Microsoft Exchange Server (including in Office 365) uses <strong>ProxyAddresses<\/strong> as a way to send email to a user if it is addressed to another domain. There is an easy cmdlet that permits one to do this. But because my premises Exchange server is currently turned off, and I do not want to power it back up only for this, I decided to use the <strong>Set-ADUser<\/strong> cmdlet to modify the attribute instead. This is because the <strong>ProxyAddresses<\/strong> attribute is stored directly in AD DS. It is a multi-valued attribute, which means that it will accept an array of email addresses.<\/p>\n<p>Today I am going to add two values to the <strong>ProxyAddresses<\/strong> attribute for each user in a specific organizational unit. I am not even going to write a script&mdash;it is a one-liner.<\/p>\n<h2>Query for existing values<\/h2>\n<p>I first use the <strong>Get-ADUser<\/strong> cmdlet to look for existing values for the <strong>ProxyAddress<\/strong>&nbsp;attribute. I am specifically targeting all users in the <strong>testou<\/strong> organizational unit from the <strong>iammred.net<\/strong> domain. The <strong>ProxyAddress<\/strong>&nbsp;attribute is not returned by default; therefore, I need to use the <strong>Properties<\/strong><em> <\/em>parameter of the <strong>Get-ADUser<\/strong> cmdlet to return the <strong>ProxyAddress<\/strong>&nbsp;attribute. I use the <strong>Select-Object<\/strong> cmdlet to return only the name of the user and any proxy addresses. Here is the command (this is a one-line command that I broke at the pipe character for formatting on the blog page).<\/p>\n<p style=\"padding-left: 30px\">Get-ADUser -Filter * -SearchBase &#8216;ou=testou,dc=iammred,dc=net&#8217; -Properties proxyaddresses |<\/p>\n<p style=\"padding-left: 30px\">Select-object &nbsp;name, proxyaddresses<\/p>\n<p>There are two reasons that I create this command. The first is so I can ensure that I have the <strong>Property<\/strong> (attribute) names correct, and I can see sample data from AD DS. The second reason is I use it to check my results to ensure that the command to modify the values of the attributes completes successfully.<\/p>\n<h2>Modify the ProxyAddresses attribute values<\/h2>\n<p>Groovy. I know that I can get access to the data. I know how to report the values that are stored in AD&nbsp;DS. Therefore, it is now time to modify the <strong>ProxyAddresses<\/strong> attribute values. To do this, I will use the <strong>Set-ADUser<\/strong> cmdlet. For this example, I am creating two new proxy addresses. Each will take the following form: UserName@Iammred.org and UserName@Iammred.com. Therefore, I can create these proxy addresses on the fly in my command. I use the following command to make the changes:<\/p>\n<p style=\"padding-left: 30px\">Get-ADUser -Filter * -SearchBase &#8216;ou=testou,dc=iammred,dc=net&#8217; -Properties proxyaddresses |<\/p>\n<p style=\"padding-left: 30px\">Foreach {Set-ADUser -identity $_ -Add `<\/p>\n<p style=\"padding-left: 30px\">@{&#8216;ProxyAddresses&#8217;=@((&#8220;{0}@{1}&#8221;-f $_.name, &#8216;Iammred.com&#8217;),(&#8220;{0}@{1}&#8221; -f $_.name, &#8216;Iammred.org&#8217;))} }<\/p>\n<p style=\"padding-left: 30px\"><strong>Note<\/strong>&nbsp;&nbsp;The previous command is a single logical line. I broke it at the pipe character, and I added a line continuation character ( <strong>` <\/strong>) after the <strong>&ndash;Add<\/strong> parameter. When typing the command into the Windows PowerShell console, it is not necessary to break the command; but instead, you can permit it to wrap.<\/p>\n<p>The command produces no output. Therefore, I use the Up arrow and retrieve my earlier search command. The commands and associated output are shown in the following image.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4265.hsg-7-21-13-01.png\"><img decoding=\"async\" title=\"Image of command output\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/4265.hsg-7-21-13-01.png\" alt=\"Image of command output\" \/><\/a><\/p>\n<p>I invite you to follow me on <a href=\"http:\/\/bit.ly\/scriptingguystwitter\" target=\"_blank\">Twitter<\/a> and <a href=\"http:\/\/bit.ly\/scriptingguysfacebook\" target=\"_blank\">Facebook<\/a>. If you have any questions, send email to me at <a href=\"mailto:scripter@microsoft.com\" target=\"_blank\">scripter@microsoft.com<\/a>, or post your questions on the <a href=\"http:\/\/bit.ly\/scriptingforum\" target=\"_blank\">Official Scripting Guys Forum<\/a>. See you tomorrow. Until then, peace.<\/p>\n<p><strong>Ed Wilson, Microsoft Scripting Guy<\/strong><span style=\"font-size: 12px\">&nbsp;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to automatically create proxy addresses in Active Directory Domain Services by using Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. So I have been talking back and forth with one of the members of the Charlotte Windows PowerShell Users group since my presentation to the group [&hellip;]<\/p>\n","protected":false},"author":596,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,3,198,61,45],"class_list":["post-3186","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-active-directory","tag-scripting-guy","tag-users","tag-weekend-scripter","tag-windows-powershell"],"acf":[],"blog_post_summary":"<p>Summary: Microsoft Scripting Guy, Ed Wilson, shows how to automatically create proxy addresses in Active Directory Domain Services by using Windows PowerShell. Microsoft Scripting Guy, Ed Wilson, is here. So I have been talking back and forth with one of the members of the Charlotte Windows PowerShell Users group since my presentation to the group [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3186","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\/596"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=3186"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/3186\/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=3186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=3186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=3186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}