Analogue of Add-Computer in PowerShell 7
August 18, 2022
Testing with PowerShell 7.3.0-preview.5 shows that Add-Computer is back!
Get-Command -module Microsoft.PowerShell.Management
outputs the following:
CommandType Name Version Source ----------- ---- ------- ------ Function Add-Computer 1.0 Microsoft.PowerShell.Management …………………. ………………….
That is, Add-Computer is present, it is a function (not a cmdlet), the version is indicated as 1.0. The status of Add-Computer is not completely clear: is it a temporary hotfix or a gradual return of the cmdlet?
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.
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
- PowerShell with administrator rights: how to run and verify (100%)
- How to display all environment variables at the Windows command prompt (90.5%)
- How to manage services on Windows (90.5%)
- How to set IP address, netmask, default gateway and DNS for a network interface in PowerShell (90.5%)
- How to configure the network interface to use a dynamic IP address (DHCP) in PowerShell (90.5%)
- Error “convert: cache resources exhausted” (SOLVED) (RANDOM - 9.5%)