Remove-Compter : Restart doesn't work

This topic contains 5 replies, has 2 voices, and was last updated by Profile photo of Ludovic Brient Ludovic Brient 2 years, 7 months ago.

  • Author
    Posts
  • #14814
    Profile photo of Ludovic Brient
    Ludovic Brient
    Participant

    Hi,
    i want to use the command Remove-Computer to unjoin computers from domain.
    I use this command :

    Remove-Computer  -UnjoinDomainCredential C_NET\Administrateur -ComputerName VSMW0020 -Force -Restart

    Unjoin domain works, but not the restart :

    Remove-Computer : Impossible de redémarrer l'ordinateur VSMW0020 avec le message d'erreur suivant : Accès refusé .
    Au caractère Ligne:1 : 1
    + Remove-Computer -UnjoinDomainCredential C_NET\Administrateur -ComputerName VSMW ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (VSMW0020:String) [Remove-Computer], InvalidOperationException
    + FullyQualifiedErrorId : RestartcomputerFailed,Microsoft.PowerShell.Commands.RemoveComputerCommand

    Can someone help?

  • #14815
    Profile photo of Ludovic Brient
    Ludovic Brient
    Participant

    Command launched from a 2K8 R2 with powerhsell V3, targeted computers are XP and Win7

  • #14816
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    It's an Access Denied error. Is the account that's running the command also an administrator on the target computer? If not, you'll also need to use the -LocalCredential parameter in addition to -UnjoinDomainCredential. (You can pass the same credentials to both parameters, if appropriate.)

  • #14817
    Profile photo of Ludovic Brient
    Ludovic Brient
    Participant

    This account is domain administrator, isn't enough?

  • #14820
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Which account? There are two sets of credentials in play, in the original command you posted. C_NET\Administrateur is used to connect to the domain controller and perform that part of the unjoin process. To connect to the VSMW0020 computer, though, the cmdlet is just using the credentials of whatever user is logged on and running the command. To use the C_NET\Administrateur account for both parts of the operation, you'd do something like this:

    $cred = Get-Credential C_NET\Administrateur
    Remove-Computer  -UnjoinDomainCredential $cred -LocalCredential $cred -ComputerName VSMW0020 -Force -Restart
    
  • #14823
    Profile photo of Ludovic Brient
    Ludovic Brient
    Participant

    IT WORKS !!!!!!!!!!!!!!!

You must be logged in to reply to this topic.