- notageek.it di Mirko Iodice - http://www.notageek.it -
List All Users Last Login, Account And Password Expiration Details
Posted By Mirko On 28 aprile 2010 @ 17:54 In Scripts | 1 Comment
Questo script permette di estrarre da Active Directory alcuni dettagli relativi agli account utente, nello specifico per ogni utente verranno mostrati i seguenti valori (separati da tabulazione):
La ricerca degli oggetti utente non deve necessariamente interessare l’intero dominio dal momento che lo script prevede la possibilità di limitarla ad una determinata unità organizzativa e ad uno specifico numero di sottolivelli (profondità della ricerca) all'interno di essa.
E' necessario specificare correttamente il BaseDN ed il nome del dominio in formato LDAP (per farlo dovete aver chiaro il concetto di percorso LDAP [1]), queste impostazioni sono assolutamente necessarie poiché identificano la base di partenza per la ricerca. Per approfondimenti su LDAP leggete LDAP per Amministratori Active Directory [2].
Lo script non gestisce in maniera autonoma le operazioni di scrittura dei risultati su file perciò vi consiglio di eseguirlo per mezzo del prompt dei comandi utilizzando il motore WSH “cscript.exe”, in questo modo potrete reindirizzarne facilmente l’output in un file di testo.
cscript.exe list_all_users_lastlogin_account_and_password_expiration_details.vbs > output.txt
ADS_SCOPE_SUBTREE (riga 7), strLDAPDomain (riga 10) e strLDAPBaseDN (riga 13) sono le uniche variabili da modificare nel codice sorgente.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 'ADS_SCOPE_SUBTREE specifies the depth of the search operation performed against the BaseDN 'I suggest you to use cscript.exe from a command prompt to redirect the output of this script on a text file On Error Resume Next 'Set here the depth of the search operation performed against the BaseDN Const ADS_SCOPE_SUBTREE = 30 'Set here the LDAP Domain Name strLDAPDomain = "dc=domain,dc=lan" 'Set here the LDAP BaseDN strLDAPBaseDN = "dc=domain,dc=lan" Const ADS_UF_ACCOUNTDISABLE = 2 Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000 Set objConnection = CreateObject("ADODB.Connection") Set objCommand = CreateObject("ADODB.Command") objConnection.Provider = "ADsDSOObject" objConnection.Open "Active Directory Provider" Set objCommand.ActiveConnection = objConnection objCommand.Properties("Page Size") = 1000 objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE objCommand.CommandText = _ "SELECT ADsPath,Name,userAccountControl FROM 'LDAP://" & strLDAPBaseDN &"' WHERE objectCategory='User'" Set objRecordSet = objCommand.Execute objRecordSet.MoveFirst Wscript.Echo "User Name" & vbTab & "Account Status" & vbTab & "Account Expiration Date" & vbTab & "Password Status" & vbTab & "Password Expiration Date: " & vbTab & "Last Password Change: " & vbTab & "Last Login: " Do Until objRecordSet.EOF strPath = objRecordSet.Fields("ADsPath").Value Set objUser = GetObject(strPath) Set objDomain = GetObject("LDAP://" & strLDAPDomain) strPasswordChangeDate = "" strAccExpDate = "" strLastLogin = "" strAccountDisabled ="" 'strAccountDisabled ="Account Enabled" strPwdExpires = "Password Expires" Set maxPwdAge = objDomain.maxPwdAge wscript.echo objUser.maxPwdAge numDays = CCur((maxPwdAge.HighPart * 2 ^ 32) + maxPwdAge.LowPart) / CCur(-864000000000) strName = objRecordSet.Fields("Name").Value strPwdLastSet = objUser.PasswordLastChanged strAccExpDate = objUser.AccountExpirationDate strLastLogin = objUser.LastLogin strPwdExpirationDate = DateAdd("d", numDays, objUser.PasswordLastChanged) intUAC = objRecordset.Fields("userAccountControl").Value boolAccountDisabled = objUser.AccountDisabled 'If (intUAC AND ADS_UF_ACCOUNTDISABLE) Then 'strAccountDisabled = "Account Disabled" 'End If If boolAccountDisabled Then strAccountDisabled = "Account Disabled" Else strAccountDisabled = "Account Enabled" End If If (intUAC AND ADS_UF_DONT_EXPIRE_PASSWD) Then strPwdExpires = "Password Never Expires" End If Wscript.Echo strName & vbTab & strAccountDisabled & vbTab & strAccExpDate & vbTab & strPwdExpires & vbTab & strPwdExpirationDate & vbTab & strPwdLastSet & vbTab & strLastLogin objRecordSet.MoveNext Loop |
Article printed from notageek.it di Mirko Iodice: http://www.notageek.it
URL to article: http://www.notageek.it/list-all-users-last-login-account-and-password-expiration-details.html
URLs in this post:
[1] percorso LDAP: http://it.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol#Struttura
[2] LDAP per Amministratori Active Directory: http://www.notageek.it/ldap-for-ad-administrators.html
[3] list_all_users_lastlogin_account_and_password_expiration_details.zip: http://www.notageek.it/wp-content/files/list_all_users_lastlogin_account_and_password_expiration_details.zip
Click here to print.
Copyright © 2009 notageek.it. All rights reserved.