Powershell: Get specific domain email address from their proxy addresses

Viewed 26

Using Powershell I want to parse through all users in the domain and pull out just a specific email address from their proxy addresses. My users have multiple email addresses in their proxy addresses. I want to get just the email address from each user that ends in a specific domain. Example if each user had @test.com,@franklin.com, and @thisone.com. I want to pull just the @thisone.com only. I am starting with this but want to pull only the one that ends with @thisone.com

Get-ADUser -Filter * -Properties proxyaddresses | Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -like 'smtp:*') -join ";"}} | Export-Csv -Path C:\PowerShell\AdUsersProxyAddresses.csv -NoTypeInformation

1 Answers
(Get-ADUser -Filter * -Properties proxyaddresses).proxyaddresses | ?{$_ -match '@thisone.com'}

This gives you only the proxyaddress back which matches '@thisone.com'

Related