Headlines

Rename and Join the computer to domain

In the Previous article you have learn, How to Install and configure domain controller and in this article you are going learn join the computer to domain using PowerShell which as easier than Joining via GUI.

Domain name: source.com

on you computer that you want to join domain controller, Open PowerShell with Administrative privilege.


Copy the below command paste in the PowerShell you have just opened. the Script provides you step by step explanation and you do not require to make anything changes within the script.

#Prompt user to input new computer name
# By: Imraan H
$newComputerName = Read-Host -Prompt "Enter the new computer name"
# Prompt user to enter domain credentials (username and password)
$domainCredential = Get-Credential -Message "Enter domain credentials"
# Prompt user to input the domain name (e.g., 'yourdomain.com')
$domainName = Read-Host -Prompt "Enter your Active Directory domain name"
# Join the computer to the domain first
Add-Computer -DomainName $domainName -Credential $domainCredential
Write-Host "Computer successfully joined to the domain '$domainName'."
# Rename the computer after it has joined the domain
Rename-Computer -NewName $newComputerName -Force
Write-Host "Computer successfully renamed to '$newComputerName'."
# Restart the computer after both actions are completed
Restart-Computer -Force

After pasting the above script in the PowerShell, You will be asked for the hostname .Enter the hostname of computer you wish to put according to your standard and hit Enter.

Once you put the computer name PowerShell request will be Opened as shown in below image. Put your domain\username and password using which you want to join the computer to you Active Directory and again hit enter. In my case username = source\administrator

Provide the domain name of your domain controller and hit enter. In my case it is source.com

That’s it, Your Script is successfully ran and here you can see my computer names was Client04 previously, now it will be Client06 after restart. restart your computer to rename and join to domain.

Here, as shown in the below images computer is joined to domain and renamed successfully.

Conclusion!!!
In this article you have learn, how to join computer to domain and rename it using PowerShell script. this method will save your time and effort compared to GUI.
In the next article you will learn how to Update DNS forwarder in your Domain controller for external DNS resolution.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top