asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search








Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Archive
Writers
Code Samples
Components
Tools
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

Add to Your ADSI Code Library
By Remie Bolte
Rating: 4.6 out of 5
Rate this article


  • email this article to a colleague
  • suggest an article

    Introduction

    Here are a few ADSI scripts for carrying out various Windows administration tasks. The one thing to be aware of is that you can't pull out the user password; therefore, it is impossible to authenticate a user through a script. If you would like to learn more about ADSI before using these scripts, check out my previous two articles on ADSI:

    Learning ADSI - Part 2: Editing Users and Administering Groups
    http://www.15seconds.com/issue/011127.htm

    Learning ADSI - Part 1: Adding Users To W2K
    http://www.15seconds.com/issue/011005.htm

    1. Domain Computers

    1.1 Display all domains in the server NameSpace

    
      Sub PullAllDomains
        Dim objNameSpace
        Dim Domain
    
        Set objNameSpace = GetObject("WinNT:")
        For Each Domain in Namespace
           Response.Write Domain.Name
        Next
      End sub
    
    
    1.2 Display all Connected Computers on the Primary Domain Controller
      
    Sub PullAllComputers(strDomain)
        Dim PrimDomainContr
    
        Set PrimDomainContr = getobject("WinNT://" & strDomain)
        PrimDomainContr.filter = Array("Computer")
       
        For each Computer in PrimDomainContr
          Reponse.write Computer.Name
        Next
      End sub
    
    
    1.3 Remove a Connected Computer from a Primary Domain Controller
      
    Sub DelComputerFromPDC(strDomain,strDelComputer)
        Dim PrimDomainContr
        Set PrimDomainContr = getobject("WinNT://" & strDomain)
        Call PrimDomainContr.Delete("Computer", strDelComputer)
      End Sub
    
    

    2. Computer Users

    2.1 Display all user accounts

    
    sub PullAllUsers(strDomain)
        Dim Computer
        Dim User
    
        Set Computer = GetObject("WinNT://" & strDomain)
        Computer.Filter = Array("User")
        For Each User in Computer
          Response.Write User.Name
        Next
      End Sub
    
    
    2.2 Display Minimum Password Age
      
    Sub DispMinPassAge(strDomain)
        Dim Computer
        Set Computer = GetObject("WinNT://" & strDomain)
        Response.Write ((Computer.MinPasswordAge) / 86400)
      End Sub
    
    
    2.3 Display Minimum Password Length
      
    Sub DispMinPassLength(strDomain)
        Dim Computer
        Set Computer= GetObject("WinNT://" & strDomain)
        Response.Write Computer.MinPasswordLength
      End Sub
    
    
    2.4 Display Password History Length
      
    Sub DispPassHisLength(strDomain)
        Dim Computer
        Set Computer = GetObject("WinNT://" & strDomain)
        Response.Write Domain.PasswordHistoryLength
      End Sub
    
    
    2.5 Display Auto Unlock Interval
      
    Sub DispAutoUnlock(strDomain)
        Dim Computer
        Set Computer = GetObject("WinNT://" & strDomain)
        Response.Write Computer.AutoUnlockInterval
      End Sub
    
    
    2.6 Display Lockout Observation Interval
    
    Sub DispAutoUnlockObservation(strDomain)
        Dim Computer
        Set Computer = GetObject("WinNT://" & strDomain)
        Response.Write Computer.LockOutObservationInterval
      End Sub
    
    

    3. Computer Groups

    3.1 Display All Groups

      
    Sub PullAllGroups(strDomain)
        Dim Computer
        Dim Group  
    
        Set Computer = GetObject("WinNT://" & strDomain)
        Computer.Filter = Array("Group")
        For Each Group in Computer
          Response.Write Group.Name
        Next
      End Sub
    
    

    4. User Specific Fields

    4.1 Display User Fullname

      
    Sub PullUserFullname(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.write User.Fullname
      End sub
    
    
    4.2 Display User Description
      
    Sub PullUserDescription(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.write User.Description
      End sub
    
    
    4.3 Display User Must Change Password Flag
    
      Sub PullUserMustChangePass(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.write User.Get("PasswordExpired")  '// 1 Means the Password Expired
      End Sub
    
    
    4.4 Display User Can't Change Password Flag
    
    Sub PullUserCannotChangePass(strDomain,strUser)
        Dim User
        Dim Flags
        
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Flags = User.Get("UserFlags")
        Response.write  Flags And &H00040 '// 0 Means that user CAN change pass
      End sub
    
    
    4.5 Display Password Never Expires Flag
      
    Sub PullPassNeverExpires(strDomain,strUser)
        Dim User
        Dim Flags
        
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Flags = User.Get("UserFlags")
        Response.write  Flags And &H10000 '// 0 Means that Password DOES expire
      End sub
    
    
    4.6 Display User Password Minimum Length
      
    Sub PullUserPassMinLength(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.PasswordMinimumLength
      End Sub
    
    
    4.7 Display User Password Required
      
    Sub PullUserPassRequired(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.PasswordRequired
      End Sub
    
    
    4.8 Display User Account Disabled Flag
      
    Sub PullUserAccountDisabled(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.AccountDisabled
      End Sub
    
    
    4.9 Display User Account Lockout Flag
    
      Sub PullUserAccountLockout(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.IsAccountLocked
      End Sub
    
    
    4.10 Display User Account Type
    
      Sub PullUserAccountType(strDomain,strUser)
        Dim User
        Dim Flags
        
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Flags = User.Get("UserFlags")
        Response.write  Flags And &H100  '// 0 Means that account is GLOBAL
      End sub
    
    
    4.11 Display User Profile Path
      
    Sub PullUserProfilePath(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.Profile
      End Sub
    
    
    4.12 Display User Login Script
    
      Sub PullUserLoginScript(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.LoginScript
      End Sub
    
    
    4.13 Display User Home Directory Path
    
      Sub PullUserHomeDirPath(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.HomeDirectory
      End Sub
    
    
    4.14 Display User Home Directory Mapping
    
      Sub PullUserHomeDirDrive(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.Get("HomeDirDrive")
      End Sub
    
    
    4.15 Display User Account Expiration Date (NT 4.0 only)
    
      Sub PullUserAccountExpireDate(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.AccountExpirationDate
      End Sub
    
    
    4.16 Display User Bad Login Count (NT 4.0 only)
    
      Sub PullUserBadLoginCount(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.BadLoginCount
      End Sub
    
    
    4.17 Display User Last Login (NT 4.0 only)
    
      Sub PullUserLastLogin(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.LastLogin
      End Sub
    
    
    4.18 Display User Last Logoff (NT 4.0 only)
    
      Sub PullUserLastLogoff(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.LastLogoff
      End Sub
    
    
    4.19 Display User Last Logoff (NT 4.0 only)
    
      Sub PullUserLastLogoff(strDomain,strUser)
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write User.LastLogoff
      End Sub
    
    
    4.20 Display User Logon Hours Restriction(NT 4.0 only)
    
      Sub PullUserLogonHourRestriction(strDomain,strUser)
        Dim User
        Dim RegTime
        Dim Restrict
    
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        For Each RegTime In User.LoginHours
          If RegTime < 255 Then Restrict = True
        Next
        Response.write Restrict
      End Sub
    
    

    5. Group Specific Fields

    5.1 Display All Users in a Group

    
      Sub PullAllUserFromGroup(strDomain,strGroup)
        Dim Group
        Dim User
        Set Group = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
        For Each User in Group.Members
          Response.Write User.Name
        Next
      End Sub
    
    
    5.2 Display if a Users is listed in a Group
    
      Sub DispUserInGroup(strDomain,strGroup,strUser)
        Dim Group
        Dim User
        Set Group = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        Response.Write Group.IsMember(User.ADsPath)
      End Sub
    
    
    5.2 Display Group Description
      
    Sub PullGroupDescription(strDomain,strGroup,strUser)
        Dim Group
        Set Group = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
        Response.Write Group.Description
      End Sub
    
    
    5.2 Display Which Group a User is Listed in
    
      Sub DispUserInWhichGroup(strDomain,strGroup,strUser)
        Dim Group
        Dim User
        Set User = GetObject("WinNT://" & strDomain & "/" & strUser & ",user")
        For Each Group in User.Groups
         Response.Write Group.Name
        Next
      End Sub
    
    

    About the Author

    Remie Bolte is a student at communicatiesystemen in the Netherlands. He has experience with VB, ASP, VBScript and SQL. His goal in life is to clean up the Internet and show people how it can benefit their needs. Remie can be reached at r.bolte@vinrem.nl.

  • Rate This Article
    Not HelpfulMost Helpful
    1 2 3 4 5
    Other Articles
    Jul 30, 2002 - Accessing Active Directory Through the .NET Framework
    In this article, Robert Chartier shows how to use the System.DirectoryServices Class for some simple User and Group administration tasks with impersonation.
    [Read This Article]  [Top]
    Nov 27, 2001 - Learning ADSI - Part 2: Editing Users and Administering Groups
    In this article, Remie Bolte further demonstrates the power of ADSI with code that renames users, changes user properties, changes user boundaries, and creates, populates, and removes user groups.
    [Read This Article]  [Top]
    Oct 5, 2001 - Learning ADSI - Part 1: Adding Users To W2K
    Remie Bolte uses his popular Adding Users to W2K code sample as a basis for introducing and exploring Microsoft's Active Directory Services Interface.
    [Read This Article]  [Top]
    Jul 10, 2001 - Web site Administration with ADSI and the .NET DirectoryServices Namespace
    The power of Active Directory Service Interfaces (ADSI) and the Microsoft .NET Framework is introduced by Tony Caudill. After completing this article you will be able to easily tame the System.DirectoryServices Namespace and use ADSI services to programatically create, delete, and update all aspects of your Web farm's virtual directories.
    [Read This Article]  [Top]
    Mar 16, 1998 - ADSI Part II: Configuring NTLM with ADSI
    ADSI Part II describes and demonstrations the power of ADSI by showing how to manipulate the NTLM database. Examples in this article show how to add a user to a domain, delete the user, add a group, and add the user to the group. There is also a discussion on security and an overview of the Group, User and Domain ADSI objects.
    [Read This Article]  [Top]
    Mar 4, 1998 - Programming IIS 4.0 with ADSI
    Have you wanted to add virtual roots through VBScript? Create ISAPI server extensions that install themselves in IIS 4.0? Or script the installation of your entire web site including user permissions? You can do this and more with ADSI.
    [Read This Article]  [Top]
    Mailing List
    Want to receive email when the next article is published? Just Click Here to sign up.

    Support the Active Server Industry



    JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES