Loading...
X

Analogue of Add-Computer in PowerShell 7

Add a computer to a domain or workgroup in PowerShell

The Add-Computer cmdlet joins a computer to a Windows Domain or to a 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.

An example of a command that adds the local computer to the domain and restarts the computer:

Add-Computer -DomainName Domain01 -LocalCredential Domain01\Administrator -Restart

The following command adds the local computer to the workgroup, or renames the workgroup (if the computer is already in a workgroup with a different name):

Add-Computer -WorkgroupName WORKGROUP-A

These commands work fine in PowerShell 5, which is built in by default in all versions of Windows up to Windows 11 and all server versions up to Windows Server 2022.

See also: How to check PowerShell version in Windows 11

Error “Add-Computer: The term 'Add-Computer' is not recognized as a name of a cmdlet, function, script file, or executable program.”

But in PowerShell 7, this command is missing:

Add-Computer
Add-Computer: The term 'Add-Computer' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

Suggestion [4,General]: The most similar commands are: Add-Computer, Stop-Computer, Get-ADComputer, New-ADComputer, Set-ADComputer, Add-Content, Rename-Computer, Add-Member.

You can verify that the command named Add-Computer is indeed present in PowerShell 5, where it is placed in the Microsoft.PowerShell.Management module:

powershell
Get-Command -Module Microsoft.PowerShell.Management -Name *Computer* | Select Name

But Add-Computer is missing from PowerShell 7:

pwsh
Get-Command -Module Microsoft.PowerShell.Management -Name *Computer* | Select Name

You can count exactly how many commands are removed from the Management module when moving from PowerShell 5 to PowerShell 7:

powershell
Get-Command -Module Microsoft.PowerShell.Management | Measure-Object | select Count

pwsh
Get-Command -Module Microsoft.PowerShell.Management | Measure-Object | select Count

There were 89 command, 61 commands remained.

How to replace Add-Computer in PowerShell 7

One of the suggested alternatives seems to be the New-ADComputer cmdlet, but the documentation explicitly says that “This cmdlet does not join a computer to a domain”.

There is no information about where the Add-Computer cmdlet or what its alternative is in PowerShell.

One working solution, if you've already installed PowerShell 7, is to run the join Domain or Workgroup command in PowerShell 5. To do this, run the following sequence of commands:

powershell
Add-Computer -DomainName Domain01 -LocalCredential Domain01\Administrator -Restart

See also: How to install the latest PowerShell on Windows 11


Leave Your Observation

Your email address will not be published. Required fields are marked *