The Add-Computer cmdlet is used in Windows PowerShell to add a local computer to a domain or workgroup. This cmdlet is part of the Microsoft.PowerShell.Management module and is available in PowerShell 3.0 and later versions.
Key features and usage:
- Domain join: Adds a computer to a specified domain.
- Workgroup join: Adds a computer to a workgroup.
- Credential support: Allows specifying alternate credentials for the operation.
- Restart option: Can restart the computer automatically after joining.
- Supports remote computers: Can add remote computers to a domain or workgroup.
Syntax:
Add-Computer [-ComputerName <String[]>] [-Domain <String>] [-Workgroup <String>] [-Credential <PSCredential>] [-LocalCredential <PSCredential>] [-UnjoinDomainCredential <PSCredential>] [-Restart] [-Force] [-PassThru] [-NewName <String>] [-OUPath <String>] [-Server <String>] [-Unsecure] [-Options <JoinOptions>] [-WhatIf] [-Confirm] [<CommonParameters>]
Common usage examples:
Join local computer to a domain:
Add-Computer -DomainName "contoso.com" -Credential (Get-Credential)
Join a remote computer to a domain:
Add-Computer -ComputerName "RemotePC" -DomainName "contoso.com" -Credential (Get-Credential) -Restart
Add computer to a workgroup:
Add-Computer -WorkgroupName "WORKGROUP"
The Add-Computer cmdlet is particularly useful for system administrators managing domain environments or when setting up new computers in an organization. It simplifies the process of joining computers to domains or workgroups, which would otherwise require multiple steps through the Windows GUI.