{"id":111,"date":"2018-09-07T11:18:45","date_gmt":"2018-09-07T15:18:45","guid":{"rendered":"http:\/\/www.thelamberts.com\/wiki\/?p=111"},"modified":"2018-09-10T07:41:01","modified_gmt":"2018-09-10T11:41:01","slug":"get-primary-smtp-email-address-from-ad-user-name","status":"publish","type":"post","link":"http:\/\/www.thelamberts.com\/wiki\/2018\/09\/07\/get-primary-smtp-email-address-from-ad-user-name\/","title":{"rendered":"Get Primary SMTP email address from AD User name"},"content":{"rendered":"<pre class=\"brush: powershell; title: ; notranslate\" title=\"\">&gt;# Setting the parameters \r\nParam (\r\n&#x5B;Parameter(Mandatory=$true)]\r\n&#x5B;string]$Username\r\n)\r\n\r\n\r\n# Import the tools to work with AD.\r\nImport-Module ActiveDirectory\r\n\r\n# Get Primary Proxy Address.\r\n$user = Get-ADUser -Identity $username  -Properties proxyAddresses\r\n$primarySMTPAddress = &quot;&quot;\r\nforeach ($address in $user.proxyAddresses)\r\n{\r\n    if (($address.Length -gt 5) -and ($address.SubString(0,5) -ceq 'SMTP:'))\r\n    {\r\n        $primarySMTPAddress = $address.SubString(5)\r\n        break\r\n    }\r\n}\r\n$primarySMTPAddress<\/pre>\r\n&nbsp;","protected":false},"excerpt":{"rendered":"&gt;# Setting the parameters Param ( &#x5B;Parameter(Mandatory=$true)] &#x5B;string]$Username ) # Import the tools to work with AD. Import-Module ActiveDirectory # Get Primary Proxy Address. $user = Get-ADUser -Identity $username -Properties proxyAddresses $primarySMTPAddress = &quot;&quot; foreach ($address in $user.proxyAddresses) { if (($address.Length -gt 5) -and ($address.SubString(0,5) -ceq &#8216;SMTP:&#8217;)) { $primarySMTPAddress = $address.SubString(5) break } } $primarySMTPAddress [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,2,3],"tags":[],"class_list":["post-111","post","type-post","status-publish","format-standard","hentry","category-active-directory","category-exchange","category-powershell"],"_links":{"self":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":2,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":113,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/posts\/111\/revisions\/113"}],"wp:attachment":[{"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.thelamberts.com\/wiki\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}