|
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.
|