Powershell

What is an Add-Computer in PowerShell?

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:

Add-Computer -DomainName New-PC -Restart

 

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:

Add-Computer -WorkgroupName Workstation-A

 

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:

Add-Computer -DomainName New-PC -Server Domain01\DC01 -PassThru -Verbose

 

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:

Add-Computer -DomainName Domain02 -OUPath "OU=testOU,DC=domain,DC=Domain,DC=com"

 

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:

Add-Computer -ComputerName Server01 -DomainName Domain02 -NewName Server044 -Credential Domain02\Admin01 -Restart

 

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.

About the author

Muhammad Farhan

I am a Computer Science graduate and now a technical writer who loves to provide the easiest solutions to the most difficult problems related to Windows, Linux, and Web designing. My love for Computer Science emerges every day because of its ease in our everyday life.