add pc to domin and change name with powershell

C++
Add-Computer -DomainName xxxx -ComputerName xxxx -NewName xxxx -Credential Domain\Admin -Restart
Source

Also in C++: