># Setting the parameters Param ( [Parameter(Mandatory=$true)] [string]$Username ) # Import the tools to work with AD. Import-Module ActiveDirectory # Get Primary Proxy Address. $user = Get-ADUser -Identity $username -Properties proxyAddresses $primarySMTPAddress = "" foreach ($address in $user.proxyAddresses) { if (($address.Length -gt 5) -and ($address.SubString(0,5) -ceq 'SMTP:')) { $primarySMTPAddress = $address.SubString(5) break } } $primarySMTPAddress