Remove the local computer from a workgroup or domain.
Syntax
Remove-Computer [-UnjoinDomainCredential] PSCredential [-ComputerName String[]]
[-LocalCredential PSCredential] [-WorkgroupName String]
[-PassThru] [-Restart] [-Confirm] [-Force] [-WhatIf] [CommonParameters]
Key
-ComputerName String[]
Specify the computers to be removed from their domains. The default is the local computer.
Type the NetBIOS name, an IP address, or a fully qualified domain name of the remote computers.
To specify the local computer, type the computer name, a dot (.), or localhost.
This parameter does not rely on PowerShell remoting. You can use the -ComputerName parameter of
Remove-Computer even if your computer is not configured to run remote commands.
This parameter was introduced in PowerShell 3.0.
-UnjoinDomainCredential PSCredential
Specify a user account that has permission to remove the computers from their current domains. Explicit
credentials, as provided by this parameter, are required to remove remote computers from a domain, even when
the value is the credentials of the current user.
Type a user name, such as "User64" or "Domain64\User64", or enter a PSCredential object, such as one generated by
Get-Credential . If you type a user name, you will be prompted for a password.
You can refer to this parameter by its name, -UnjoinDomainCredential , or its alias, -Credential.
To specify a user account that has permission to connect to the remote computers, use the -LocalCredential
parameter. This parameter was introduced in PowerShell 3.0.
-LocalCredential PSCredential
Specify a user account that has permission to connect to the -ComputerName.
The default is the current user.
-Force
Suppresses the user prompt. By default, Remove-Computer prompts for confirmation before removing each computer.
-PassThru
Return the results of the command. Otherwise, this cmdlet does not generate any output.
-confirm
Prompt for confirmation before executing the command.
-whatIf
Describe what would happen if you executed the command without actually
executing the command.
-WorkgroupName String
Specify the name of a workgroup to which the computers are added when they are removed from their domains.
The default value is WORKGROUP. When you remove a computer from a domain, you must add it to a workgroup.
This parameter was introduced in PowerShell 3.0.
CommonParameters:
-Verbose, -Debug, -ErrorAction, -ErrorVariable, -WarningAction, -WarningVariable,
-OutBuffer -OutVariable.
Remove-Computer removes the local computer from its current workgroup or domain.
When a computer is removed from a domain, Remove-Computer will also disable the computer's domain account.
You must provide explicit credentials to unjoin the computer from its domain, even when they are the credentials of the current user. Also, when you remove a computer from a domain, you must move it to a workgroup. Use the -WorkgroupName parameter to specify the workgroup.
Restart the computer to make the change effective.
Use the -Verbose and -PassThru parameters to view the results of the command.
Examples
Remove the local computer from the domain to which it is joined:
PS C:> remove-computer -credential domain64\admin64 -passthru -verbose; restart-computer
Move several old computers to a 'Room101' workgroup:
PS C:> Remove-Computer -ComputerName (Get-Content OldServers.txt) -LocalCredential ss64dom\Admin64 -UnJoinDomainCredential ss64dom\Admin64 -WorkgroupName "Room101" -Force -Restart
Remove computers from a workgroup without confirmation:
PS C:> Remove-Computer -ComputerName "Server64", "localhost" -UnjoinDomainCredential ss64dom\Admin64 -WorkgroupName "Local" -Restart -Force
“No amount of time can erase the memory of a good cat, and no amount of masking tape can ever totally remove his fur from your couch” ~ Leo F. Buscaglia
Related PowerShell Cmdlets:
Add-Computer - Add a computer to the domain.
Restart-Computer - Restart the operating system on a computer.