Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


November 15, 2004

Dsmod.exe Improvement

RSS
View this exclusive article with VIP access -- click here to join |
See More Active Directory (AD) Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

Download the Code Here

[Editor's Note: Share your scripting discoveries, comments, problems, solutions, and experiences with products. Email your contributions (500 words or less) to r2rwinscriptsol@windowsitpro.com. We edit submissions for style, grammar, and length. If we print your submission, you'll get $100.]

I work as a security administrator in a Windows 2000 Professional and Win2K Active Directory (AD) environment. I often need to disable user logon IDs (i.e., Windows NT IDs) when employees leave the company. However, I don't like using the Microsoft Management Console (MMC) Active Directory Users and Computer snap-in because it requires you to search through all the employees in AD to find the logon IDs you want to disable.

Windows Server 2003's dsmod.exe lets you disable user accounts from the command line. You can also use this tool in Win2K Pro. To disable user accounts, you use the Dsmod User command. This command has many options. In my organization, we use the syntax

dsmod user DistinguishedName
  [-disabled yes|no]

where DistinguishedName is the distinguished name (DN) of the user for whom we want to disable the account. We use the -disabled yes option to disable the user account. (You'd specify no if you want to enable the account.)

Entering the DN every time we need to disable a user account is cumbersome because of our extensive organizational unit (OU) hierarchy. So, I wrote a simple script called Disable.vbs that lets us enter the NT ID rather than the DN to disable user accounts. Listing 1 shows an excerpt from Disable.vbs. You can download the entire script from the Windows Scripting Solutions Web site. Go to http://www.windowsitpro.com/windowsscripting, enter InstantDoc ID 44325 in the InstantDoc ID text box, then click the 44325.zip hotlink.

To run this script, we use the command

cscript disable.vbs NtId true|false

where NtId is the user's NT ID. Including the true value disables the user account, whereas including the false value enables it. As callout A in Listing 1 shows, Disable.vbs checks the OU's hierarchy, so you can use it in any organization.

End of Article



Reader Comments
no need for vbscript !!!

you could use

dsquery user -samid NTID | dsmod user -disabled YES

blahblahblah December 28, 2005 (Article Rating: )


NameTranslate for Scripts!
As microsoft won't document it's own steaming load of CIM crudology, here you go:
http://www.rlmueller.net/NameTranslateFAQ.htm

Does anyone else fear new MS tech since they won't ever bother to document it? (*cough monad cough*)

blahblah1 May 18, 2006 (Article Rating: )


You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

How can I stop and start services from the command line?

...

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...


Active Directory (AD) Whitepapers Sustainable Compliance: How to reconnect compliance, security and business goals

Managing Unix/Linux with Microsoft System Center Operations Manager 2007 Cross Platform Extensions Beta

Addressing the Insider Threat with NetIQ Security and Administration Solutions

Related Events Concrete Ways to Make Sure Your SharePoint Deployment Doesn't Blow Up

PCI Requirements for Windows and Active Directory: Straight from a Certified Auditor

Check out our list of Free Email Newsletters!

Active Directory (AD) eBooks Keeping Your Business Safe from Attack: Monitoring and Managing Your Network Security

Keeping Your Business Safe from Attack: Encryption and Certificate Services

Windows 2003: Active Directory Administration Essentials

Related Active Directory (AD) Resources Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing