Sign in
|
Join PowerShell.com!
|
Help
Home
PowerTips
Ask the Experts
Forums
Webcasts
Blogs
eBookV2
Script Library
Twitter Grid
Modules
QuickClick
Scripts
Snippets
Videos
Library
»
Script Library
»
Active Directory
»
Slideshow
Active Directory Slideshow
Share
|
Browse Library
Module Library
QuickClick Library
Script Library
Active Directory
BizTalk
Citrix
Clustering
Desktop
Exchange Server 2003
Exchange Server 2007
File System
Group Policy
Internet Information Server (IIS)
Local Accounts
Logs
Microsoft Office
Microsoft Team Foundation Server
MySQL
Networking
Registry
Remote Desktop Services
Remoting
Security
SharePoint
SQL Server
System Center Virtual Machine Manager
System Center Configuration Manager
System Center Operations Manager
Tutorial
Terminal Server
Using .Net
Virtual Server
VMware
Windows 7
Windows HPC
Windows Server 2000
Windows Server 2003
Windows Server 2008
Windows XP
WMI
Misc
Snippet Library
Video Library
Members Only
Tags
Active Directory
ad
Administrator
aman dhally
Computer
Deleted
DirectorySearcher
domain
Domain Controller
Exchange
Exchange 2003
Forest
fsmo
Group
local
Member
OU
Password
script
search
Security
Site
Tombstone
User
Users
View more
Remove Computer Account from All Domain controllers
<
#
"SatNaam WaheGuru"
Date: 24
-
Feb
-
2012 ; 14:31Pm
Author: Aman Dhally
Email:
amandhally@
gmail.com
web:
www.amandhally.net
/
blog
blog:
http:
//
newdelhipowershellusergroup.blogspot.com
/
More Info :
Version :
/
^(
o.o
)^\
#>
## make sure you have Active Directory Moudle Installed ##
# Import Module
Import-Module
ActiveDirectory
# Variables
$computer
=
$env:Computername
# Computername which you want to use
$localdc
=
"Dc-Del"
# Chnage with ur 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 ________
Loading...
Remove Computer...
Delete a Computer...
Remote Server...
Get-MailAddress
AD Tools with...
Display the...
Display the...
Generate a...
Copy Group...
Move computer...
View all files
Copyright 2011 PowerShell.com. All rights reserved.