I'm trying to pull some information from AD but having difficulty. I'm trying to get a list of users that have the PRIMARY smtp address from the ProxyAddresses attribute (an array) in a specific format (SMTP:firstname.lastname*) only. I only want the ones that match "SMTP" (case sensitive) and of those only those that have the email address in the format of firstname.lastname.
Get-ADUser -SearchBase "DC=corp,DC=companyx,DC=com" -Filter * -Properties ProxyAddresses,sn,givenname,displayname,mail |
Where-Object {$_.ProxyAddresses -clike "SMTP:{$_.givenname+$_.sn}*"} # | Select-Object proxyaddresses,displayName,givenName,sn
Try this:
Get-ADUser -SearchBase "DC=corp,DC=companyx,DC=com" -Filter * -Properties ProxyAddresses,sn,givenname,displayname,mail |
Where-object {($_.ProxyAddresses -cmatch "SMTP:") -and ($_.ProxyAddresses -match "$($_.givenname).$($_.sn)*")}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.