CmdID / PowerShell / Cmdlets / Remove
Remove-Computer
Removes the local computer from its domain. PowerShell reference
From the PowerShell reference 9 parameters
What it does
Removes the local computer from its domain. The Remove-Computer cmdlet removes the local computer and remote computers from their current domains. When you remove a computer from a domain, Remove-Computer also disables the domain account of the computer. You must provide explicit credentials to unjoin the computer from its domain, even when they are the credentials of the current user. You must restart the computer to make the change effective. Also, when you remove a computer from a domain, you must move it to a workgroup. Use the WorkgroupName parameter to specify the workgroup. To move a computer from a workgroup to a domain, from one workgroup to another, or from one domain to another, use the Add-Computer cmdlet. To get the results of the command, use the Verbose and PassThru parameters. To suppress the user prompt, use the Force parameter. Remove-Computer removes the local computer and remote computers from domains. It includes credential parameters that specify alternate credentials for connecting to remote computers, and unjoining from a domain, a Restart parameter for restarting the affected computers, and a WorkgroupName parameter for specifying the name of the workgroup to which computers are added.
Remove-Computer [[-UnjoinDomainCredential] <PSCredential>] [-Restart] [-Force] [-PassThru] [-WorkgroupName <String>] [-WhatIf] [-Confirm] [<CommonParameters>]Remove-Computer -UnjoinDomainCredential <PSCredential> [-LocalCredential <PSCredential>] [-Restart] [-ComputerName <String[]>] [-Force] [-PassThru] [-WorkgroupName <String>] [-WhatIf] [-Confirm] [<CommonParameters>]
Remove the local computer from its domain
Remove-Computer -UnjoinDomaincredential Domain01\Admin01 -PassThru -Verbose -RestartIdentifyMove several computers to a legacy workgroup
Remove-Computer -ComputerName (Get-Content OldServers.txt) -LocalCredential Domain01\Admin01 -UnJoinDomainCredential Domain01\Admin01 -WorkgroupName "Legacy" -Force -RestartIdentifyRemove computers from a workgroup without confirmation
Remove-Computer -ComputerName "Server01", "localhost" -UnjoinDomainCredential Domain01\Admin01 -WorkgroupName "Local" -Restart -ForceIdentifyIts page in the reference: Remove-Computer.
Parameters
-ComputerNameSpecifies the computers to be removed from their domains. The default is the local computer.
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.-ForceSuppresses the user prompt. By default, Remove-Computer prompts you for confirmation before removing each computer.-LocalCredentialSpecifies a user account that has permission to connect to the computers that the ComputerName parameter specifies. The default is the current user.
This parameter was introduced in PowerShell 3.0.-PassThruReturns the results of the command. Otherwise, this cmdlet does not generate any output.-RestartIndicates that this cmdlet restarts the computers that are being removed. A restart is often required to make the change effective.
This parameter was introduced in PowerShell 3.0.-UnjoinDomainCredentialSpecifies 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.
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.-WorkgroupNameSpecifies 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.-ConfirmPrompts you for confirmation before running the cmdlet.-WhatIfShows what would happen if the cmdlet runs. The cmdlet is not run.