title: How to rejoin domain when trust relationship is lost
body: <p>I have a number of virtual machines which have snapshots applied by using a PowerShell script. Occasionally, the virtual machines lose their "trust relationship" with the domain. This breaks the script as I can no longer use PowerShell remoting to get into the machines and configure them.</p>
  
  <p>How can I <em>remotely</em> reset the trust relationship of these virtual machines? Perhaps there are possibilities for rejoining the domain that don't involve remoting?</p>
  
  <p>Any alternate solutions to manually rejoining the domain require logging in to the computer and doing this locally. I haven't found anything that can do this otherwise.</p>
  
  <p>So far, I've attempted to put together a script that simply remotes into the box as the local administrator:</p>
  
  <pre><code>$password = ConvertTo-SecureString "password" -AsPlainText -Force
  $cred= New-Object System.Management.Automation.PSCredential ("Administrator", $password)
  $sesh = new-pssession -computername "theMachine" -credential $cred
  </code></pre>
  
  <p>At this point, I was hoping to use PowerShell to reset the password or something like that to reset the domain trust relationship. However, this results in an error on the last line: <code>Access is Denied</code>.</p>
  
  <p>I don't think you can use the local administrator account with PowerShell remoting. Is there any other way I can remotely get a virtual machine that has lost its domain trust relationship to rejoin the domain?</p>