If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.
Option Explicit Dim objDSE, strDefaultDN, strDN, objContainer, objChild, dtmValue, intAge, strFileName dim objFSO, objFile, objTextFile, strReportName Const ForAppending = 8 '**** OPEN OBJECTS Set objDSE = GetObject("LDAP://rootDSE") 'open Active Directory strDefaultDN = "OU=Users,OU=Insurance,OU=SABC," & objDSE.Get("defaultNamingContext") 'full path to users folder 'strDefaultDN = "OU=Users," & objDSE.Get("defaultNamingContext") 'full path to users folder '**** ARE YOU SURE? strDN = InputBox("Enter the distinguished name of a container" & _ vbCrLf & "(e.g. " & strDefaultDN & ")", , strDefaultDN) 'allow user to change folder If strDN = "" Then WScript.Quit(1) 'user clicked Cancel = exit script '******** NAME REPORT strReportName = InputBox("Enter Report File Name:", , "PasswordReport") 'allow user to name report '***** CREATE AND OPEN TEXT FILE Set objContainer = GetObject("LDAP://" & strDN) 'open users folder objContainer.Filter = Array("user") 'only read users strFileName = "C:\Documents and Settings\maunw\Desktop\Password Age Checker\Report\" & strReportName & ".txt" Set objFSO = CreateObject("Scripting.FileSystemObject") 'create file system object Set objFile = objFSO.CreateTextFile(strFileName) 'create report file objFile.close 'close report file Set objTextFile = objFSO.OpenTextFile(strFileName, ForAppending, True) 'open report file to edit '**** PROCESS on error resume next 'if there is a bad record, move to the next For Each objChild In objContainer 'process each user dtmValue = objChild.PasswordLastChanged 'date password was changed intAge = Int(Now - dtmValue) 'Today - password last changed = age objTextFile.WriteLine(objChild.FullName & vbtab & intAge) 'write line to file Next objTextFile.Close 'close file WScript.Echo "END" 'notify that processing is done
Add your voice to the tech community where 5M+ people just like you are talking about what matters.
Join the community of 500,000 technology professionals and ask your questions.