Original Message:
Sent: Jun 16, 2023 01:40 PM
From: Ed-White
Subject: Removing Computer Account from Domain
Hi Matt,
We just setup a task to copy the powershell script to the computer, execute the file on the local machine, then delete the script after. That way the script always uses the local computer name. We use a domain account that can only add or remove objects and change its password on a regular basis. I included a sample of the ps script we run below.
Later
Ed
$domain = "DS.WHATEVER.WHATEVER"
$password = "YOUR-PASSWORD" | ConvertTo-SecureString -asPlainText -Force
$username = "$domain\DOMAIN-ACCOUNT"
$credential = New-Object System.Management.Automation.PSCredential($username,$password)
$joined = (Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain
if ($joined -eq $true) {
Remove-Computer -Credential $credential -passthru -force
}
Original Message:
Sent: Jun 12, 2023 09:27 AM
From: Matthew Stewart
Subject: Removing Computer Account from Domain
Good morning!
I am curious if anyone has a good way to remove computer accounts from the domain during the imaging process? In theory I would like to do this before setup.exe for Windows is executed on the machine. I have found some PowerShell scripts, but with the ones I've found, you have to specify the computer name each time you run it. If there is a way to have it check/remove the computer account of the target machine instead of having to specify the computer name each time, that would be ideal. Any thoughts, ideas suggestions welcome...thanks!
Matt