Hi,
If you are using Active Directory environment in you infrastructure then you does the one thing for sure , remove / add computers to the domain.
Some times when you format user computer and add it again to the Domain it gives an error that "Computer Already exists in the domain". Or you can say that you have multiple remote offices and syncing / replication between those all DC's are slow and you need to delete that computer from All DC including the local and remote domain Controllers.
I wrote this small script which delete the provided "computer" in to all DC which is on you replicated Server List. Before running this script make sure you have "Active Directory" module installed.
This script works for me and hope this works for you too.
You can Download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Remove-Computer-Account-326f1e22
#########################################################
# Import Module
Import-Module ActiveDirectory
# Variables
$computer = $env:Computername # Computername which you want to use
$localdc = "Dc-XXXX" # Chnage with ur local DC
$credentials = Get-Credential # This should be Admin Credentials
# AD
$ADResult = (Get-ADComputer -Filter {cn -like $computer} -Server "$localdc" -Credential $credentials ).name -eq $computer
$dclist = (Get-ADDomain -Server "$localdc" -Credential $credentials).ReplicaDirectoryServers
$arrDc = @()
foreach ($obj in $dclist) {
$nlist = $obj.Replace("`.XYZ.com","") # Replace XYZ.com with your Domain Name
$arrDc += $nlist
}
# If you want to remove it from AD remove -wahtif and un-commnted -confirm:$false
if ($ADResult -eq $true) {
Write-Host -ForegroundColor Red "$computer exists in AD, I am going to remove it"
foreach ( $dc in $arrdc) {
Remove-ADComputer -Identity "$computer" -Server $dc -Credential $credentials -whatif #-confirm:$false
write-host $([char]7)
write-Host "$computer is deleted on $dc " -ForegroundColor Green
}
}
## ENd of Script##### a m a n d h a l l y ________
You can Download the script from here : http://gallery.technet.microsoft.com/scriptcenter/Remove-Computer-Account-326f1e22
Thanks for Reading.
Aman Dhally