Important Notice: On February 29th, this community was put into read-only mode. All existing posts will remain but customers are unable to add new posts or comment on existing. Please feel to join our Community Discord for any questions and discussions.

Remove a PC and switch domain

Hey there, I am currently trying to find way to stream line removeing and re adding PCs to a new domain. I have found a powershell script that works without an in-between boot.

$User = "newdomain\adminuser"
$Password = ConvertTo-SecureString "password" -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential $User,$Password

Function Join-Domain {
    Add-Computer -Domainname "newdomain" -Credential $Credentials
}

If ( (Get-WMIObject win32_computersystem).partofdomain -eq $true ) {
    Remove-Computer
    Join-Domain
} Else {
    Join-Domain
}

Any ideas? Still researching as well. If I run this script on the PC it works, but when I push it through PDQ it errors out:

Windows PowerShell is in NonInteractive mode. Read and Prompt functionality is not available.
At C:\WINDOWS\AdminArsenal\PDQDeployRunner\service-1\exec\Error Handling Wrapper.ps1:47 char:2
+     Throw $_.Exception.ErrorRecord
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : InvalidOperation
 
0

Comments

1 comment
Date Votes
  • Have you tried Remove-Computer -UnjoinDomainCredential $Credentials -Confirm:$false ?

    -UnjoinDomainCredential is required parameter

    Remove-Computer

    0