Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Remove/rejoin computer to domain via Powershell script?

Posted on 2014-12-29
5
9,576 Views
Last Modified: 2014-12-29
Hi,

I need to revert to an ESXI vmware snapshot of a vm all the time.
Regularely I get the message "trust relationship between this workstation and the domain failed".
I need to remove it from the domain, reboot add it to the domain reboot what is ennoying.

Please advise howto do this in an easier way, via Powershell or other?

J.
0
Comment
Question by:janhoedt
5 Comments
 
LVL 19

Expert Comment

by:Peter Hutchison
ID: 40521487
Use the Add-Computer command:
e.g.
$name = $Env:ComputerName
$cred = Get-Credential
Add-Computer -WorkgroupName WORKGROUP -ComputerName $name
Add-Computer -Domain domain-name -Credential $cred -ComputerName $name
0
 

Author Comment

by:janhoedt
ID: 40521490
Ok, but howto do this remotely?
0
 
LVL 5

Accepted Solution

by:
GG VP earned 333 total points
ID: 40521521
You can use Remove-Computer to remove the computer from domain,

http://technet.microsoft.com/en-us/library/hh849816%28v=wps.620%29.aspx

Parameter Set: Remote
Remove-Computer -UnjoinDomainCredential <PSCredential> [-ComputerName <String[]> ] [-Force] [-LocalCredential <PSCredential> ] [-PassThru] [-Restart] [-Workgroup <String> ] [ <CommonParameters>]

PS C:\> Remove-Computer -ComputerName Server01 -UnjoinDomainCredential Domain01\Admin01 -Workgroup Local -Restart -Force
0
 
LVL 84

Assisted Solution

by:oBdA
oBdA earned 167 total points
ID: 40521523
Easier solution to prevent this from happening in the first place: create a GPO applied only to this VM (by security filtering or a separate GPO), in which you enable the "Domain member: Disable machine account password changes" policy (http://technet.microsoft.com/en-us/library/cc785826(v=ws.10).aspx).
Restore the snapshot, re-join the restored machine one last time to the domain (btw: you can save yourself the first reboot; remove from domain, close the dialogs, re-open the dialog, rejoin, reboot), open rsop.msc to make sure the policy is applied, then take a new base snapshot.
0
 
LVL 5

Assisted Solution

by:GG VP
GG VP earned 333 total points
ID: 40521528
You can use Add-Computer to join the computer to domain,

http://technet.microsoft.com/en-us/library/hh849798(v=wps.620).aspx

Syntax:

Parameter Set: Domain
Add-Computer [-DomainName] <String> -Credential <PSCredential> [-ComputerName <String[]> ] [-Force] [-LocalCredential <PSCredential> ] [-NewName <String> ] [-Options <JoinOptions> ] [-OUPath <String> ] [-PassThru] [-Restart] [-Server <String> ] [-UnjoinDomainCredential <PSCredential> ] [-Unsecure] [-Confirm] [-WhatIf] [ <CommonParameters>]

Open in new window


Example:

This command adds the Server01 computer to the Domain02 domain. It uses the LocalCredential parameter to specify a user account that has permission to connect to the Server01 computer

PS C:\> Add-Computer -ComputerName Server01 -LocalCredential Server01\Admin01 -DomainName Domain02 -Credential Domain02\Admin02 -Restart -Force

Open in new window

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If we need to check who deleted a Virtual Machine from our vCenter. Looking this task in logs can be painful and spend lot of time, so the best way to check this is in the vCenter DB. Just connect to vCenter DB(default DB should be VCDB and using…
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question