The cmdlet “Add-Computer” in PowerShell is utilized for adding a computer to a domain or a workgroup. It also moves the computers from one specific domain to the other. Moreover, if the computer is added to the specific domain without having an account, then, it will create a domain account. The additional parameters can also be specified, such as organizational units.
This post will illustrate the “Add-Computer” cmdlet in PowerShell.
What is an Add-Computer in PowerShell?
As described above, the “Add-Computer” cmdlet is used for adding a computer to a domain. Let’s consider the below-provided examples for more detail about this cmdlet.
Example 1: Add a Local Computer/PC to a Specific Domain by Utilizing the Cmdlet “Add-Computer”
Execute the given command for adding a specified computer to a specified:
In accordance with the stated code:
- First, mention the “Add-Computer” cmdlet, along with the “-DomainName” parameter having the computer name assigned to it.
- Lastly, define the “-Restart” parameter to restart the computer:
Example 2: Add a Specified Local Computer to a Workgroup Using the “Add-Computer” Cmdlet
Run the below command for adding a specified local computer to a workgroup:
In the above-illustrated command, specify the “Add-Computer” along with the “-WorkgroupName” parameter having the name of the workgroup “Workstation-A” assigned to it.
Example 3: Utilize the Cmdlet “Add-Computer” to Add a Specific Computer to a Certain Domain
To add a local computer to a domain, execute the below command:
According to the above-stated command:
- First, add the “Add-Computer” cmdlet.
- Then, specify the “-DomainName” parameter and assign the local computer name “New-PC” to it.
- After that, write the “-Server” and assign the specified server or domain name to it.
- Lastly, specify the “-PassThru” and the “-Verbose” parameters at the end.
Example 4: Utilize the Cmdlet “Add-Computer” Along with the Parameter OUPath
Run the below-mentioned command to accomplish the stated task:
After mentioning the stated cmdlet and the specific domain name. After that, add the “-OUPath” parameter and specify the stated values to it.
Example 5: Move a Specific Computer to a New Domain and also Change Computer’s Name
Execute the given command for moving a computer/PC to a new domain with a new name:
In accordance with the above command
- First, specify the stated cmdlet along with the “-ComputerName” and the “-DomainName” parameter having the specified values assigned to them.
- After that, specify the “-NewName” parameter and assign the new computer name to it.
- Then, add the “-Credential” parameter to specify the credentials.
- Lastly, write the “-Restart” parameter to restart the system after changing the computer name.
That’s all! We have provided the usage of the “Add-Computer” command in PowerShell.
Conclusion
The “Add-Computer” cmdlet is responsible for adding a computer to a domain. If the computer is added to a domain without an account, then, it will also create a domain account. This post has explained the “Add-Computer” cmdlet in PowerShell with the aid of various examples.