I have a script to update fields in AD, which is working well but there are user accounts that are throwing errors such as:
Set-ADUser : Cannot convert 'System.Object[]' to the type 'Microsoft.ActiveDirectory.Management.ADUser' required by parameter 'Identity'. Specified method is not supported.
At D:\Data\Allen\2023_Scripting\RemoteWorker_AD_OU_Switch_Full.ps1:90 char:39
+ 840 {Set-ADUser -Identity $adUser.sAMAccountName -Replace ...
+ ~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : CannotConvertArgument,Microsoft.ActiveDirectory.Management.Commands.SetADUser
How might I go about logging the above with the associated user account that is producing the error in the foreach loop? I don’t want it to become a Terminating error. I’d like the scipt to continue, as it does now, but I’d like to be able to log which user accounts are having issues updating.
Thank you.