2. Active Directory Tasks - Powershell
2.3 Renaming a Computer
to change a computer name, we could use the Rename-Computer cmdlet.
The targeted computer must be online and connected to the domain!
Rename-Computer -ComputerName "WS-IT-01" -NewName "IT-01"
and if you want to run this script locally:
Rename-Computer -NewName "newname" -DomainCredential "Domain\Administrator"
you can make this script better, by putting the targeted Computer into a specific OU like this:
$NewComputerName = "HR-01" # Specify the new computer name.
$DC = "tinker.lab" # Specify the domain to join.
$Path = "OU=HR-Workstations,DC=tinker,DC=lab" # Specify the path to the OU where to put the computer account in the domain.
Add-Computer -DomainName $DC -OUPath $Path -NewName $NewComputerName -Restart -Force
The script should be run on the target machine, not on the domain controller.
a prompt will show up for the creds of an account which has permissions to join computers to the domain, then the computer will be renamed, restarted and be joined to the domain!