CmdID

CmdID / PowerShell / Cmdlets / Add

Add-Computer

Add the local computer to a domain or workgroup. PowerShell reference

From the PowerShell reference 16 parameters

Opens CmdID with your command, read as PowerShell. It is read in your browser and sent nowhere.

What it does

from the PowerShell reference, CC BY 4.0

Add the local computer to a domain or workgroup. 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.

Add-Computer [-ComputerName <String[]>] [-LocalCredential <PSCredential>] [-UnjoinDomainCredential <PSCredential>] -Credential <PSCredential> [-DomainName] <String> [-OUPath <String>] [-Server <String>] [-Unsecure] [-Options <JoinOptions>] [-Restart] [-PassThru] [-NewName <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]
Add-Computer [-ComputerName <String[]>] [-LocalCredential <PSCredential>] [-Credential <PSCredential>] [-WorkgroupName] <String> [-Restart] [-PassThru] [-NewName <String>] [-Force] [-WhatIf] [-Confirm] [<CommonParameters>]

Add a local computer to a domain then restart the computer

Add-Computer -DomainName Domain01 -RestartIdentify

Add a local computer to a workgroup

Add-Computer -WorkgroupName WORKGROUP-AIdentify

Add a local computer to a domain

Add-Computer -DomainName Domain01 -Server Domain01\DC01 -PassThru -VerboseIdentify

Add a local computer to a domain using the OUPath parameter

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

Add a local computer to a domain using credentials

$addComputerSplat = @{ ComputerName = 'Server01' LocalCredential = 'Server01\Admin01' DomainName = 'Domain02' Credential = 'Domain02\Admin02' Restart = $true Force = $true } Add-Computer @addComputerSplatIdentify

Move a group of computers to a new domain

$addComputerSplat = @{ ComputerName = 'Server01', 'Server02', 'localhost' DomainName = 'Domain02' LocalCredential = 'Domain01\User01' UnjoinDomainCredential = 'Domain01\Admin01' Credential = 'Domain02\Admin01' Restart = $true } Add-Computer @addComputerSplatIdentify

Move a computer to a new domain and change the name of the computer

$addComputerSplat = @{ ComputerName = 'Server01' DomainName = 'Domain02' NewName = 'Server044' Credential = 'Domain02\Admin01' Restart = $true } Add-Computer @addComputerSplatIdentify

Add computers listed in a file to a new domain

$addComputerSplat = @{ ComputerName = (Get-Content Servers.txt) DomainName = 'Domain02' Credential = 'Domain02\Admin02' Options = 'Win9xUpgrade' Restart = $true } Add-Computer @addComputerSplatIdentify

Add a computer to a domain using predefined computer credentials

$newADComputerSplat = @{ Name = "Server02" AccountPassword = (ConvertTo-SecureString -String 'TempJoinPA$$' -AsPlainText -Force) } New-ADComputer @newADComputerSplat # Then this command is run from Server02 which is not yet domain-joined: $joinCred = New-Object pscredential -ArgumentList ([pscustomobject]@{ UserName = $null Password = (ConvertTo-SecureString -String 'TempJoinPA$$' -AsPlainText -Force)[0] }) $addComputerSplat = @{ DomainName = "Domain03" Options = 'UnsecuredJoin', 'PasswordPass' Credential = $joinCred } Add-Computer @addComputerSplatIdentify

Trips 1 Sigma rule: mediumConvertTo-SecureString Cmdlet Usage Via CommandLine by Teymur Kheirkhabarov (idea), Vasiliy Burov (rule), oscd.community, Tim Shelton

Add a Computer to a domain with a new name

Rename-Computer -NewName "MyNewPC" -Force $addComputerSplat = @{ DomainName = 'Contoso.com' Credential = 'contoso\administrator' Options = 'JoinWithNewName', 'AccountCreate' } Add-Computer @addComputerSplatIdentify

Its page in the reference: Add-Computer.

Parameters

16 in the PowerShell reference
-ComputerNameSpecifies the computers to add to a domain or workgroup. The default is the local computer. 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 is introduced in Windows PowerShell 3.0.
-CredentialSpecifies a user account that has permission to join the computers to a new domain. The default is the current user. 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.
-DomainNameSpecifies the domain to which the computers are added. This parameter is required when adding the computers to a domain.
-ForceSuppresses the user confirmation prompt. Without this parameter, Add-Computer requires you to confirm the addition of each computer. This parameter is introduced in Windows PowerShell 3.0.
-LocalCredentialSpecifies a user account that has permission to connect to the computers that are specified by the ComputerName parameter. The default is the current user. 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 is introduced in Windows PowerShell 3.0.
-NewNameSpecifies 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 is introduced in Windows PowerShell 3.0.
-OptionsSpecifies 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. If you want to pass a machine password, then you must use this option in combination with PasswordPass 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. When using this option, the credential provided to the -Credential parameter _must_ have a null username. …
-OUPathSpecifies 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.
-PassThruReturns an object representing the item with which you are working. By default, this cmdlet does not generate any output.
-RestartRestarts the computers that were added to the domain or workgroup. A restart is often required to make the change effective. This parameter is introduced in Windows PowerShell 3.0.
-ServerSpecifies the name of a domain controller that adds the computer to the domain. Enter the name in FQDN format. By default, no domain controller is specified. Beginning in August 2024, security hardening for domain join requires that you use the FQDN of the domain controller. For example: DC1.contoso.com. For more information, see NetJoin Domain Join Hardening Changes.
-UnjoinDomainCredentialSpecifies a user account that has permission to remove the computers from their current domains. The default is the current user. 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 is introduced in Windows PowerShell 3.0.
-UnsecurePerforms an unsecure join to the specified domain.
-WorkgroupNameSpecifies the name of a workgroup to which the computers are added. The default value is "WORKGROUP".
-ConfirmPrompts you for confirmation before running the cmdlet.
-WhatIfShows what would happen if the cmdlet runs. The cmdlet is not run.