Share via


PowerShell scripts – delete computer account in Active Directory

$dom = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
$root = $dom.GetDirectoryEntry()
$search = [System.DirectoryServices.DirectorySearcher]$root
$search.filter = "(&(objectclass=computer)(name=windowsserver))"
$search.findall() | %{$_.GetDirectoryEntry() } | %{$_.DeleteObject(0)}

Comments