This cmdlet is part of the Vexasoft Cmdlet Library. You can download it now or click here to find out more.

Set-Domain

Synopsis

Join the local or a remote computer to a domain or workgroup.

Syntax

  • Set-Domain [-ComputerName] [-Domain] [-Reboot] [-ServerCredential] [-DomainCredential] [-WhatIf] [-Confirm]
  • Set-Domain [-ComputerName] [-Workgroup] [-Reboot] [-ServerCredential] [-DomainCredential] [-WhatIf] [-Confirm]

Description

The Set-Domain cmdlet is used to join computers to a domain or workgroup. Set-Domain is similar to the existing Add-Computer cmdlet, but can also be used against remote computers. Set-Domain requires a reboot for the changes it makes to take effect and the -Reboot parameter of this cmdlet is included for this purpose.

Parameters

  • ComputerName The computer against which to run the cmdlet. By default this parameter will be populated with the name of the local computer.
  • Domain The domain to which the computer should be joined. Cannot be used in conjunction with the Workgroup parameter.
  • Workgroup The workgroup to which the computer should be joined. Cannot be used in conjunction with the Domain parameter.
  • Reboot Reboot the computer so that configuration changes take effect.
  • ServerCredential The server credentials under which to run the cmdlet. This credential must have rights to perform domain join operations on the target computer.
  • DomainCredential The domain credentials under which to run the cmdlet. This credential must have rights to perform domain join operations on the target domain.

Inputs

Set-Domain accepts pipeline input only for the ComputerName parameter and requires that the input object contain a property named either Computer, CN or ComputerName.

Outputs

Set-Domain does not output any Powershell objects.

Notes

The cmdlet requires that the Remote Registry and RPC services are started on the computer it is trying to access and that DNS services are available to resolve target host names.

Example 1

This command will join the local computer to the domain AD.MYDOMAIN.COM. The $MyServerCreds and $MyDomainCreds variables have been previously created by the user using the Get-Credential cmdlet:

Set-Domain -Domain AD.MYDOMAIN.COM -ServerCredential $MyServerCreds -DomainCredential $MyDomainCreds

Example 2

This command will join the remote computer PC01 to the domain AD.MYDOMAIN.COM. In this example $MyServerCreds is the credentials of the PC01 administrator previously created by the user via the Get-Credential cmdlet:

Set-Domain -Domain AD.MYDOMAIN.COM -Computer PC01 -ServerCredential $MyServerCreds -DomainCredential $MyDomainCreds

Example 3

This command will join remote computer PC01 to the local workgroup LocalWorkstations. Because no credentials have been provided the user will be prompted for the required usernames and passwords before the join is executed:

Set-Domain -Computer PC01 -Workgroup LocalWorkstations