PowerShell Commands

Add-Computer

Add-Computer [-DomainName*] <String> [-ComputerName <String[]>] [-Confirm] -Credential* <PSCredential> [-Force][-LocalCredential <PSCredential>] [-NewName <String>] [-OUPath <String>] [-Options {AccountCreate | Win9XUpgrade |UnsecuredJoin | PasswordPass | DeferSPNSet | JoinWithNewName | JoinReadOnly | InstallInvoke}] [-PassThru][-Restart] [-Server <String>] [-UnjoinDomainCredential <PSCredential>] [-Unsecure] [-WhatIf] [<CommonParameters>]
Add-Computer [-WorkgroupName*] <String> [-ComputerName <String[]>] [-Confirm] [-Credential* <PSCredential>] [-Force][-LocalCredential <PSCredential>] [-NewName <String>] [-PassThru] [-Restart] [-WhatIf] [<CommonParameters>]

The Add-Computer cmdlet adds the local computer or remote computers to a domain or workgroup, or moves them from one domain to another. It also creates a domain account if the computer is added to the domain without an account.

You can use the parameters of this cmdlet to specify an organizational unit (OU) and domain controller or to perform an unsecure join.

To get the results of the command, use the Verbose and PassThru parameters.

Parameters

-ComputerName <String[]>

  • Default value is None
  • Accepts pipeline input ByPropertyName

Specifies the computers to add to a domain or workgroup. The default is the local computer.

Type the NetBIOS name, an Internet Protocol (IP) address, or a fully qualified domain name of each of the remote computers. To specify the local computer, type the computer name, a dot (.), or "localhost".

This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Add-Computer even if your computer is not configured to run remote commands.

This parameter was introduced in Windows PowerShell 3.0.

-Confirm [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Prompts you for confirmation before running the cmdlet.

-Credential <PSCredential>

  • This value is required
  • Default value is None
  • Accepts pipeline input False

Specifies a user account that has permission to join the computers to a new domain. The default is the current user.

Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

To specify a user account that has permission to remove the computer from its current domain, use the UnjoinDomainCredential parameter. To specify a user account that has permission to connect to a remote computer, use the LocalCredential parameter.

-DomainName <String>

  • This value is required
  • Default value is None
  • Accepts pipeline input False

Specifies the domain to which the computers are added. This parameter is required when adding the computers to a domain.

-Force [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Forces the command to run without asking for user confirmation. Without this parameter, Add-Computer requires you to confirm the addition of each computer.

This parameter was introduced in Windows PowerShell 3.0.

-LocalCredential <PSCredential>

  • Default value is None
  • Accepts pipeline input False

Specifies a user account that has permission to connect to the computers that are specified by the ComputerName parameter. The default is the current user.

Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

To specify a user account that has permission to add the computers to a new domain, use the Credential parameter. To specify a user account that has permission to remove the computers from their current domain, use the UnjoinDomainCredential parameter.

This parameter was introduced in Windows PowerShell 3.0.

-NewName <String>

  • Default value is None
  • Accepts pipeline input ByPropertyName

Specifies a new name for the computer in the new domain. This parameter is valid only when one computer is being added or moved.

This parameter was introduced in Windows PowerShell 3.0.

-OUPath <String>

  • Default value is None
  • Accepts pipeline input False

Specifies an organizational unit (OU) for the domain account. Enter the full distinguished name of the OU in quotation marks. The default value is the default OU for machine objects in the domain.

-Options <JoinOptions>

  • Default value is None
  • Accepts pipeline input False

Specifies advanced options for the Add-Computer join operation. Enter one or more values in a comma-separated string.

The acceptable values for this parameter are:

- AccountCreate : Creates a domain account. The Add-Computer cmdlet automatically creates a domain account when it adds a computer to a domain. This option is included for completeness.

- Win9XUpgrade : Indicates that the join operation is part of a Windows operating system upgrade.

- UnsecuredJoin : Performs an unsecured join. To request an unsecured join, use the Unsecure parameter or this option.

- PasswordPass : Sets the machine password to the value of the Credential (DomainCredential) parameter after performing an unsecured join. This option also indicates that the value of the Credential (DomainCredential) parameter is a machine password, not a user password. This option is valid only when the UnsecuredJoin option is specified.

-- JoinWithNewName : Renames the computer name in the new domain to the name specified by the NewName parameter. When you use the NewName parameter, this option is set automatically. This option is designed to be used with the Rename-Computer cmdlet. If you use the Rename-Computer cmdlet to rename the computer, but do not restart the computer to make the change effective, you can use this parameter to join the computer to a domain with its new name.

- JoinReadOnly : Uses an existing machine account to join the computer to a read-only domain controller. The machine account must be added to the allowed list for password replication policy and the account password must be replicated to the read-only domain controller prior to the join operation.

- InstallInvoke : Sets the create (0x2) and delete (0x4) flags of the FJoinOptions parameter of the JoinDomainOrWorkgroup method.

This parameter was introduced in Windows PowerShell 3.0.

-PassThru [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Returns an object representing the item with which you are working. By default, this cmdlet does not generate any output.

-Restart [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Indicates that this cmdlet restarts the computers that were added to the domain or workgroup. A restart is often required to make the change effective.

This parameter was introduced in Windows PowerShell 3.0.

-Server <String>

  • Default value is None
  • Accepts pipeline input False

Specifies the name of a domain controller that adds the computer to the domain. Enter the name in DomainName\ComputerName format. By default, no domain controller is specified.

-UnjoinDomainCredential <PSCredential>

  • Default value is None
  • Accepts pipeline input False

Specifies a user account that has permission to remove the computers from their current domains. The default is the current user.

Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

Use this parameter when you are moving computers to a different domain. To specify a user account that has permission to join the new domain, use the Credential parameter. To specify a user account that has permission to connect to a remote computer, use the LocalCredential parameter.

This parameter was introduced in Windows PowerShell 3.0.

-Unsecure [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Indicates that this cmdlet performs an unsecured join to the specified domain.

-WhatIf [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Shows what would happen if the cmdlet runs. The cmdlet is not run.

-WorkgroupName <String>

  • This value is required
  • Default value is None
  • Accepts pipeline input False

Specifies the name of a workgroup to which the computers are added. The default value is "WORKGROUP".

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs
System.String
You can pipe computer names and new names to this cmdlet.
Outputs
Microsoft.PowerShell.Commands.ComputerChangeInfo
When you use the PassThru parameter, Add-Computer returns a ComputerChangeInfo object. Otherwise, this cmdlet does not generate any output.
Examples
  1. Add a local computer to a domain then restart the computer:
    PS C:\> Add-Computer -DomainName "Domain01" -Restart
    

    This command adds the local computer to the Domain01 domain and then restarts the computer to make the change effective.

  2. Add a local computer to a workgroup:
    PS C:\> Add-Computer -WorkGroupName "WORKGROUP-A"
    

    This command adds the local computer to the Workgroup-A workgroup.

  3. Add a local computer to a domain:
    PS C:\> Add-Computer -DomainName "Domain01" -Server "Domain01\DC01" -Passthru -Verbose
    

    This command adds the local computer to the Domain01 domain by using the Domain01\DC01 domain controller.

    The command uses the PassThru and Verbose parameters to get detailed information about the results of the command.

  4. Add a local computer to a domain using the OUPath parameter:
    PS C:\> Add-Computer -DomainName "Domain02" -OUPath "OU=testOU,DC=domain,DC=Domain,DC=com"
    

    This command adds the local computer to the Domain02 domain. It uses the OUPath parameter to specify the organizational unit for the new accounts.

  5. Add a local computer to a domain using credentials:
    PS C:\> Add-Computer -ComputerName "Server01" -LocalCredential "Server01\Admin01" -DomainName "Domain02" -Credential Domain02\Admin02 -Restart -Force
    

    This command adds the Server01 computer to the Domain02 domain. It uses the LocalCredential parameter to specify a user account that has permission to connect to the Server01 computer. It uses the Credential parameter to specify a user account that has permission to join computers to the domain. It uses the Restart parameter to restart the computer after the join operation completes and the Force parameter to suppress user confirmation messages.

  6. Move a group of computers to a new domain:
    PS C:\> Add-Computer -ComputerName "Server01", "Server02", "localhost" -Domain "Domain02" -LocalCredential Domain01\User01 -UnjoinDomainCredential Domain01\Admin01 -Credential Domain02\Admin01 -Restart
    

    This command moves the Server01 and Server02 computers, and the local computer, from Domain01 to Domain02.

    It uses the LocalCredential parameter to specify a user account that has permission to connect to the three affected computers. It uses the UnjoinDomainCredential parameter to specify a user account that has permission to unjoin the computers from the Domain01 domain and the Credential parameter to specify a user account that has permission to join the computers to the Domain02 domain. It uses the Restart parameter to restart all three computers after the move is complete.

  7. Move a computer to a new domain and change the name of the computer:
    PS C:\> Add-Computer -ComputerName "Server01" -Domain "Domain02" -NewName "Server044" -Credential Domain02\Admin01 -Restart
    

    This command moves the Server01 computer to the Domain02 and changes the machine name to Server044.

    The command uses the credential of the current user to connect to the Server01 computer and unjoin it from its current domain. It uses the Credential parameter to specify a user account that has permission to join the computer to the Domain02 domain.

  8. Add computers listed in a file to a new domain:
    PS C:\> Add-Computer -ComputerName (Get-Content Servers.txt) -Domain "Domain02" -Credential Domain02\Admin02 -Options Win9xUpgrade -Restart
    

    This command adds the computers that are listed in the Servers.txt file to the Domain02 domain. It uses the Options parameter to specify the Win9xUpgrade option. The Restart parameter restarts all of the newly added computers after the join operation completes.

Additional Notes
 In Windows PowerShell 2.0, the Server parameter of Add-Computer fails even when the server is present. In 
 Windows PowerShell 3.0, the implementation of the Server* parameter is changed so that it works reliably.

This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here.

PowerShell Commands