Hi,
For the first error, the property is "mail", not "email".
For the second error, the Set-ADObject cmdlet has no "-mail" parameter. Please use "-replace" to set the mail attribute.
$LocalUsers = Get-ADObject -Filter {(objectClass -eq "contact") -and (mail -like '*gmail.com')} -SearchBase "OU=T,OU=Test,DC=contoso,DC=com" -Properties mail -ResultSetSize $null
$LocalUsers | foreach {$newUpn = $_.mail.Replace("gmail.com","contoso.com"); $_ | Set-ADObject -Replace @{mail=$newUpn} }
Best Regards,
Ian Xue
============================================
If the Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.