Share via

Powershell script to remove computer from Domain

Anonymous
2021-11-10T20:16:34+00:00

Hello,

I am trying to remove computers from the domain with a powershell script.

I will be using the Local Admin. credentials to remove the devices from the domain so users don't have to type in anything

I have encrypted the password with the following commands:

Creating the Secure Password

$userPassword = read-host -AsSecureString

$stringObject = ConvertFrom-SecureString $userPassword

$stringObject | Set-Content -Path "C:...path"

Removing from the Domain

$userName = '.\LocalAdminName'

$pw = Get-Content "C:\path to $stringObject"

$securePW = $pw | ConvertTo-SecureString -AsPlainText -Force

$plainCred = New-Object System.Management.automation.pscredential -ArgumentList ($userName, $securePW)

Remove-Computer -UnjoinDomainCredential $plainCred -PassThru -Restart -Force -WorkgroupName 'WORKGROUP'

I keep getting this error that doesn't make sense.

Remove-Computer : Failed to unjoin computer 'Computer Name' from domain 'Domain Name' with the following error message:

Unable to update the password. The value provided for the new password does not meet the length, complexity, or history requirements of the domain.

Windows for home | Windows 10 | Settings

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Anonymous
    2021-11-10T20:58:27+00:00

    Hi, I'm Robinson, and I’m happy to help you today.

    I know how frustrating this may be for you but I'll do my very best to help you.

    I believe that your question will be better resolved if it is posted in a more suitable location, you may get better help at our sister forums for IT Professionals, Q&A forums, the Community is for common consumers with domestic issues. Go here: https://docs.microsoft.com/en-us/answers/index....

    Was this answer helpful?

    0 comments No comments