Windows Vista Forums
Vista Forums Home Join Vista Forums Webcasts Windows 7 Forum Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > PowerShell

removing computer accounts from AD

Update your Vista Drivers Update Your Drivers Now!!
Closed Thread
 
Thread Tools Display Modes
Old 06-07-2007   #1 (permalink)
Andrew Zirkel
Guest


 

removing computer accounts from AD

I'm working on a script that involves unbinding machines from Active
Directory. I'm Using UnjoinDomainOrWorkgroup from the win32_ComputerSystem
class. The machine is successfully removed from the domain but the machine
account is still in AD. When I pass a 2 to FUnjoinOptions the account is
not disabled. The return value is 0 and I'm specifying domain admin
credentials for the password and username.

Any help is appreciated.
Andrew Zirkel.


My System SpecsSystem Spec
Old 06-08-2007   #2 (permalink)
RichS
Guest


 

RE: removing computer accounts from AD

To remove a computer account from AD look at something like this

$cname = "Computer6"
$compname = "(cn=$cname)"

## get the domain
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()
$domain = $dom.GetDirectoryEntry()

## get the computer
$searcher = new-object System.DirectoryServices.DirectorySearcher($domain,
$compname)
$computer = $searcher.FindOne()

## and delete
$compdel = $computer.GetDirectoryEntry()
$compdel.psbase.DeleteTree()

If you know the distinguished name the code could be shortened

--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk


"Andrew Zirkel" wrote:

> I'm working on a script that involves unbinding machines from Active
> Directory. I'm Using UnjoinDomainOrWorkgroup from the win32_ComputerSystem
> class. The machine is successfully removed from the domain but the machine
> account is still in AD. When I pass a 2 to FUnjoinOptions the account is
> not disabled. The return value is 0 and I'm specifying domain admin
> credentials for the password and username.
>
> Any help is appreciated.
> Andrew Zirkel.
>
>

My System SpecsSystem Spec
Closed Thread

Thread Tools
Display Modes



Similar Threads
Thread Thread Starter Forum Replies Last Post
removing a computer from the network in windows vista Johnny Whaley Vista networking & sharing 4 07-20-2008 03:55 PM
I need the SID for all the computer accounts in AD!! Gabe VB Script 4 06-06-2008 11:55 AM
removing computer from workgroup tommygun Vista networking & sharing 1 02-21-2008 06:31 PM
Removing Loose program files from my computer dyno12345 Vista performance & maintenance 0 08-02-2007 01:44 AM
Removing misnamed computer from networked connections =?Utf-8?B?bWFydHlmZWxrZXI=?= Vista networking & sharing 0 09-14-2006 04:46 PM


Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51