Remove-Compter : Restart doesn't work

Welcome Forums General PowerShell Q&A Remove-Compter : Restart doesn't work

This topic contains 5 replies, has 2 voices, and was last updated by

 
Participant
4 years, 7 months ago.

  • Author
    Posts
  • #14814

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

  • #14816

    Member
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

    This account is domain administrator, isn't enough?

  • #14820

    Member
    Points: 0
    Rank: Member

    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

    Participant
    Points: 0
    Rank: Member

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

The topic ‘Remove-Compter : Restart doesn't work’ is closed to new replies.