Update-PWUser error message

Hello, I am trying to change users emails and identities from one domain to another but when testing this I get an error message saying the below, which seems to contradict itself. What am I doing wrong?

Script:

    #get all user accounts with BAM email
    $bamusers = Get-PWUsersByMatch -Email '*@bamnuttall.co.uk'
   
    foreach($user in $bamusers)
    {
        write-host 'updateing ->' $user.email -ForegroundColor green
        #find replace template number with group
        $user.email = $user.email -replace ($olddomain, $newdomain)
        $user.Identity = $user.email
        Update-PWUser -User $user
    }

Error:

Update-PWUser : Cannot bind parameter 'User'. Cannot convert the "Bentley.ProjectWise.PowerShell.Common.User" value of type "Bentley.ProjectWise.PowerShell.Common.User" to type
"Bentley.ProjectWise.PowerShell.Common.User".
At line:49 char:29
+         Update-PWUser -User $user
+                             ~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Update-PWUser], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Bentley.ProjectWise.PowerShell.Commands.UpdatePWUser