Share via


Remove-Computer

Applies To: Windows PowerShell 2.0

Removes the local computer from its domain.

Syntax

Remove-Computer [[-Credential] <PSCredential>] [-Force] [-PassThru] [-Confirm] [-WhatIf] [<CommonParameters>]

Description

The Remove-Computer cmdlet removes the local computer from its current domain.

When you remove a computer from a domain, Remove-Computer also disables the computer's domain account. When the computer is in a domain, you must provide credentials, even when they are the credentials of the current user, and you must restart the computer to make the change effective.

To get the results of the command, use the Verbose and PassThru parameters. To suppress the user prompt, use the Force parameter.

Parameters

-Credential <PSCredential>

Specifies a user account that has permission to perform this action. The default is the current user.

Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

To remove a computer from a domain, you must use the Credential parameter, even when you are using the credentials of the current user.

Required?

false

Position?

2

Default Value

The credentials of the current user

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Force

Suppresses the user prompt. By default, Remove-Computer prompts you for confirmation before removing a computer.

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-PassThru

Returns the results of the command. Otherwise, this cmdlet does not generate any output.

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before executing the command.

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Describes what would happen if you executed the command without actually executing the command.

Required?

false

Position?

named

Default Value

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This command supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, OutBuffer, OutVariable, WarningAction, and WarningVariable. For more information, see about_CommonParameters.

Inputs and Outputs

The input type is the type of the objects that you can pipe to the cmdlet. The return type is the type of the objects that the cmdlet returns.

Inputs

None

You cannot pipe input to this cmdlet.

Outputs

Microsoft.PowerShell.Commands.ComputerChangeInfo

When you use the PassThru parameter, Remove-Computer returns a ComputerChangeInfo object. Otherwise, this cmdlet does not generate any output.

Notes

This cmdlet will not remove a computer from a workgroup.

Although the cmdlet does not require the Credential parameter, commands to remove a computer from a domain fail if it is omitted.

Example 1

C:\PS>remove-computer -credential domain01\admin01 -passthru -verbose; restart-computer

Description
-----------
These commands remove the local computer from the domain to which it is joined.

The first command removes the computer from the domain. The command uses the Credential parameter to supply the credentials of a domain administrator. It uses the PassThru parameter and the Verbose common parameter to display information about the success or failure of the command.

The second command uses the Restart-Computer cmdlet to restart the computer, which is required to complete the remove operation.

The semi-colon (;) separates the two commands.





Example 2

C:\PS>remove-computer -credential domain01\admin01 -force; restart-computer

Description
-----------
This command removes the local computer from its domain without requiring user confirmation. The Force parameter suppresses the user prompt that appears by default.





See Also

Concepts

Add-Computer
Checkpoint-Computer
Remove-Computer
Restart-Computer
Restore-Computer
Stop-Computer
Test-Connection