Hi,
I am using below powershell script to removal machine from domain, however i am getting error. When i use the same credentials manually it works.
$User = "Admin User"
$PWord = ConvertTo-SecureString -String "Password" -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord
Remove-Computer -UnjoinDomaincredential $Credential -PassThru -Verbose -Restart -Force > c:\temp\output.txt
I am getting below error.
**Remove-Computer : Failed to unjoin computer 'USLVLXXXDSP0001' from domain 'one.ads.bms.com' with the following error message: Access is denied.**
**At line:4 char:1**
**+ Remove-Computer -UnjoinDomaincredential $Credential -PassThru -Verbos ...**
**+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~**
** + CategoryInfo : OperationStopped: (USLVLXXXDSP0001:String) [Remove-Computer], InvalidOperationException**
** + FullyQualifiedErrorId : FailToUnjoinDomain,Microsoft.PowerShell.Commands.RemoveComputerCommand**