'Impossible to rename a machine and join it to the active directory : No mapping between account names and security IDs was done

I'm trying to rename a machine and join it to the Active Directory. Each time,, I'm facing the same error : No mapping between account names and security IDs was done

I've tried many scripts without success:

Rename-Computer -NewName $ComputerName -Force -PassThru -Verbose
Start-Sleep -s 5
Add-Computer -NewName $ComputerName -DomainName $DomainName -Option JoinWithNewName -Credential $credential -OUPath $OUPath -Force  -Passthru -Verbose


Rename-Computer -NewName $ComputerName -Force -PassThru -Verbose
Start-Sleep -s 5
Add-Computer -DomainName $DomainName -Option JoinWithNewName -Credential $credential -OUPath $OUPath -Force  -Passthru -Verbose

Any insight?

Thanks.



Solution 1:[1]

I am not sure if this is will work for you but this is also possible.

Add-Computer -ComputerName (Get-Content Servers.txt) -DomainName Domain02 -Credential Domain02\Admin02 -Options Win9xUpgrade  -Restart

This command moves the Server01 computer to the Domain02 and changes the machine name to Server044.

The command uses the credential of the current user to connect to the Server01 computer and unjoin it from its current domain. It uses the Credential parameter to specify a user account that has permission to join the computer to the Domain02 domain.

You can refer this documentation from Microsoft

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-computer?view=powershell-5.1

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leul