码迷,mamicode.com
首页 > 系统相关 > 详细

remove computer from join with powershell

时间:2018-07-26 13:15:33      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:alter   effective   pow   http   button   disable   work   nbsp   alt   

Removes the local computer from its domain.
Remove-Computer
      [-UnjoinDomainCredential] <PSCredential>
      [-LocalCredential <PSCredential>]
      [-Restart]
      [-ComputerName <String[]>]
      [-Force]
      [-PassThru]
      [-WorkgroupName <String>]
      [-WhatIf]
      [-Confirm]
      [<CommonParameters>]

Description

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.

Examples

Example 1: Remove the local computer from its domain

PowerShell
PS C:\> Remove-Computer -UnjoinDomaincredential Domain01\Admin01 -PassThru -Verbose -Restart

This command removes the local computer from the domain to which it is joined.

The command uses the UnjoinDomainCredential 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 and the Restart parameter restart the computer, which is required to complete the remove operation.

Because the command does not specify a workgroup name, the local computer is moved to the WORKGROUP workgroup after it is removed from its domain.

Example 2: Move several computers to a legacy workgroup

PowerShell
PS C:\> Remove-Computer -ComputerName (Get-Content OldServers.txt) -LocalCredential Domain01\Admin01 -UnJoinDomainCredential Domain01\Admin01 -WorkgroupName "Legacy" -Force -Restart

This command removes all of the computers that are listed in the OldServers.txt file from their domains and includes them in the Legacy workgroup.

The command uses the LocalCredential parameter to supply the credentials of a user who has permission to connect to remote computers and the UnjoinDomainCredential parameter to supply the credentials of a user who has permission to remove the computers from their domains. It uses the Force parameter to suppress the confirmation prompts for each computer and the Restart parameter to restart each of the computers after it is removed from its domain.

Example 3: Remove computers from a workgroup without confirmation

PowerShell
PS C:\> Remove-Computer -ComputerName "Server01", "localhost" -UnjoinDomainCredential Domain01\Admin01 -WorkgroupName "Local" -Restart -Force

This command removes the Server01 remote computer and the local computer from their domains and adds them to the Local workgroup. It uses the Force parameter to suppress the confirmation prompt for each computer and the Restart parameter to restart the computers to make the change effective.

 

Refer:

https://docs.microsoft.com/zh-cn/powershell/module/Microsoft.PowerShell.Management/Remove-Computer?view=powershell-5.1

https://ss64.com/ps/remove-computer.html

remove computer from join with powershell

标签:alter   effective   pow   http   button   disable   work   nbsp   alt   

原文地址:https://www.cnblogs.com/oskb/p/9370910.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!