Add the local computer to a domain or workgroup.

Syntax

Add-Computer [-DomainName] <string> [-Credential <PSCredential>] [-OUPath <string>] [-Server <string>] [-Unsecure] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

Add-Computer [-WorkGroupName] <string> [-Credential <PSCredential>] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

Description

The Add-Computer cmdlet adds the local computer to a domain or workgroup, or moves it 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

-Credential <PSCredential>

Specifies a user account that has permission to perform this action. 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.

Required?

false

Position?

named

Default Value

Current User Account Credentials

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DomainName <string>

Specifies a domain for the computer account. This parameter is required.

Required?

true

Position?

2

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-OUPath <string>

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

Required?

false

Position?

named

Default Value

The default OU for machine objects for in the domain

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-PassThru

Returns the results of the command. By default, this cmdlet does not generate any output.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Server <string>

Specifies the name of a domain controller that adds the computer to the domain. Enter the name in DomainName\ComputerName format. The default is the local computer.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Unsecure

Performs an unsecure join.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WorkGroupName <string>

Specifies the name of a work group for the computer. If you omit this parameter, the computer is joined to a domain.

Required?

true

Position?

3

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before executing the command.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Describes what would happen if you executed the command without actually executing the command.

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see about_CommonParameters.

Inputs and Outputs

The input type is the type of the objects that you can pipe to the cmdlet. The return type is the type of the objects that the cmdlet returns.

Inputs

None

You cannot pipe objects to Add-Computer.

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.

Example 1

C:\PS>add-computer -domainname Domain01; restart-computer

These commands add the local computer to the Domain01 domain using the credentials of the current user.

The first command adds the computer to the domain. The second command uses the Restart-Computer cmdlet to restart the computer, which completes the join operation. The semi-colon (;) separates the two commands.






Example 2

C:\PS>add-computer -workgroupname WORKGROUP-A

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






Example 3

C:\PS>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.






Example 4

C:\PS>Add-Computer -domainname Domain02 -OUPath OU=testOU,DC=domain,DC=Domain,DC=com

This command adds the Server01 and Server02 computers to the Domain02 domain. It uses the OUPath command to specify the organization unit for the new accounts.






Example 5

C:\PS>Add-Computer -domainname Domain02 -cred Domain02\Admin02 -passthru

This command adds the local computer to the Domain02 domain by using the credentials of a domain administrator. The command uses the PassThru parameter to generate a brief report about the results of the command.






See Also




Table Of Contents