Remove a PC and switch domain
J. Doss
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
Have you tried
Remove-Computer -UnjoinDomainCredential $Credentials -Confirm:$false?-UnjoinDomainCredential is required parameter
Remove-Computer