Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

unlock user array

Status
Not open for further replies.

GrimR

IS-IT--Management
Jun 17, 2007
1,149
0
0
ZA
Anyone know if this can be done, run vbscript popup a list of users locked out (an array)(create numbers next to the list) select the number of the user you want to unlock.

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
>Anyone know if this can be done
Yes, probably. So what have you tried and where are you stuck?
 
So from the script below its easy enough to get them to echo out, but that's where my talent runs out to, I dont know much about how to get the information into a dynamic array, I have only ever done standard arrays e.g Dim sArray( 6, 1 ) and list the array, i know this is where I gather a dynamic array or dictionary should be used to list them. The Ubound statements really confuse me.

Code:
' FindLockedoutADUsers.vbs
' Sample VBScript to Find and List Locked Out Active Directory users.
' Author: [URL unfurl="true"]http://www.morgantechspace.com/[/URL]
' Usage in CMD: C:\> CScript C:\Scripts\FindLockedoutADUsers.vbs
' -or- C:\>CScript C:\Scripts\FindLockedoutADUsers.vbs > C:\Scripts\LockoutUsers.txt
' ------------------------------------------------------' 

Option Explicit

' Initialize required variables.
Dim adoCommand, adoConnection
Dim varBaseDN, varFilter, varAttributes
Dim objRootDSE, varDNSDomain, strQuery, adoRecordset
Dim lockoutFlag

Const Flag_LOCKOUT = 16


' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
Set adoCommand.ActiveConnection = adoConnection

' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")

varDNSDomain = objRootDSE.Get("defaultNamingContext")
varBaseDN = "<LDAP://" & varDNSDomain & ">"

' varBaseDN is Domain DN, you can give your own OU DN instead of getting from "defaultNamingContext"
' like varBaseDN = "<LDAP://OU=TestOU,DC=Domain,DC=com>" 

' Filter to list locked out user objects.
varFilter = "(&(objectCategory=person)(objectClass=user)(SAMAccountType=805306368)(LockoutTime>=1))"

' Comma delimited list of attribute values to retrieve.
varAttributes = "cn,samaccountname"

' Construct the LDAP syntax query.
strQuery = varBaseDN & ";" & varFilter & ";" & varAttributes & ",msDS-User-Account-Control-Computed;subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 1000
adoCommand.Properties("Timeout") = 20
adoCommand.Properties("Cache Results") = False

' Run the query.
Set adoRecordset = adoCommand.Execute

' Enumerate the resulting recordset.
Do Until adoRecordset.EOF

   ' Ensure the user is still in locked out state by checking UF_LOCKOUT flag
   ' in the msDS-User-Account-Control-Computed attribute
      
     lockoutFlag = adoRecordset.Fields("msDS-User-Account-Control-Computed").Value

    If (lockoutFlag and Flag_LOCKOUT) Then

      WScript.Echo adoRecordset.Fields("cn").Value & "  " _
      & adoRecordset.Fields("samaccountname").Value

    End If

    ' Move to the next record in the recordset.
    adoRecordset.MoveNext
Loop


' close ado connections.
adoRecordset.Close
adoConnection.Close

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
and i need it to pop up like this (off one of my scripts) easy if they static entries, but obviously the number will be next to a username and will execute a command to unlock the AD account.

Code:
Dim WshShell:Set WshShell = WScript.CreateObject("WScript.Shell")
bullet = Chr(10) & "   " & Chr(149) & " "

Do
    response = InputBox("Please enter the script number you wish to run next:" & Chr(10) & bullet & "0.) Quit" & bullet &_
	"1.) Rename Drives" & bullet & "2.) MoveTo CopyTo" & bullet & "3.) Registry Entries" & bullet & "4.) CreateFolders" &_
	bullet & "5.) Wallpaper" & bullet & "6.) Description in AD" & bullet & "7.) Install All Registry Files" & bullet & _
	"8.) Signature" & Chr(10), "Run Script", "Select a script to Run")
	
    If response = "" Then 
		MsgBox "Enter a Value between 1 and 8, OR 0 to Quit"
	else if response = "0" then WScript.Quit  'Detect Cancel
    If IsNumeric(response) Then Exit Do 'Detect value response.
		MsgBox "You must enter a numeric value.", 48, "Invalid Entry"
	end if
Loop

MCSE NT to 2012, MCITP:EA/SA, MCSA, MCDBA, MCTS, MCP+I, MCP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top