$users = Get-ADUser -Filter {proxyAddresses -like '*'} -SearchBase "ou=sydney,dc=omnicom,dc=com,dc=au" -Properties proxyAddresses
$pp=$null
$pp=@{'name'=$null;'primarysmtp'=$null}
$obj=New-Object -TypeName psobject -Property $pp
$result=@()
foreach($user in $users){
$primarySMTPAddress = ""
foreach ($address in $user.proxyAddresses)
{
if (($address.Length -gt 5) -and ($address.SubString(0,5) -ceq 'SMTP:') )
{
$primarySMTPAddress = $address.SubString(5)
break
}
}
$objtemp=$obj | select *
$objtemp.name=$user.Name
$objtemp.primarysmtp=$primarySMTPAddress
$result+=$objtemp
}
$result | Where-Object{$_.primarysmtp -like "*aus.ddb.com*"} | sort Name