Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - removing computer accounts from AD

Reply
 
Old 06-07-2007   #1 (permalink)
Andrew Zirkel


 
 

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


 
 

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
Reply

Thread Tools


Similar Threads
Thread Forum
Removing accounts-where does the mail go? Live Mail
removing a computer from the network in windows vista Vista networking & sharing
removing computer from workgroup Vista networking & sharing
Removing Loose program files from my computer Vista performance & maintenance
Removing misnamed computer from networked connections Vista networking & sharing


Vista Forums 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 Ltd

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