I have the below code:
$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 = $.email.Replace("gmail.com","contoso.com"); $ | Set-ADObject -mail $newUpn}
And get the below error:
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADPropertyValueCollection] does not contain a method named 'Replace'.
At line:2 char:24
+ ... | foreach {$newUpn = $_.email.Replace("gmail.com","contoso.com"); ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Set-ADObject : A parameter cannot be found that matches parameter name 'mail'.
At line:2 char:99
+ ... Replace("gmail.com","contoso.com"); $_ | Set-ADObject -mail $newUpn ...
+ ~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADObject], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADObject
Thank you for your help!
Regards,
BT