Deleting Computer Accounts

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

When a computer is no longer used within an organization, you might want to delete its corresponding computer account from Active Directory. Retaining accounts that are not tied to a specific computer can complicate computer management in the following ways:

  • The organization will appear to be responsible for more computers than it actually has.
  • The one-to-one correspondence between the computers listed in the computer inventory and the computer accounts shown in Active Directory will no longer exist.
  • Automated scripts that attempt to run against every computer account in an Active Directory container will encounter problems because the script will try to access computers that no longer exist.

The ADSI IADsDeleteOps interface enables you to programmatically delete computer accounts from Active Directory.

Note

  • When you programmatically delete a computer account, no confirmation box will appear (although you can write code that displays such a confirmation box before actually carrying out the DeleteObject method). Instead, the account object is deleted as soon as the DeleteObject method is called.

Scripting Steps

Listing 9.3 contains a script that deletes a computer account from Active Directory. To carry out this task, the script must perform the following steps:

  1. Use a GetObject call to connect to Workstation4, a computer account located in the Computers container in fabrikam.com.
  2. Use the DeleteObject method with the required parameter (0) to remove the account.

    The value (0) is the only value that can be used as the parameter for the DeleteObject method.

Listing 9.3   Deleting a Computer Account

1 2 3 
set objComputer = GetObject _     ("LDAP://CN=Workstation4, CN=Computers, DC=fabrikam, DC=com") objComputer.DeleteObject (0)

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net