By PinkelCreated 31 Mar 2011, Modified 01 Apr 2011
My Rating:
Vote
Rating:
(1 votes)
Views:39557
Downloads:602
Source:

Query Active Directory for User(s) last login

Language:  VBScript

Compatibility

Windows XP Yes Windows 2003 Yes
Windows 2000 Yes Windows NT Unknown
Vista Yes Windows 2008 Yes
Description

Queries the Active Directory/Domain for a user last login time or all users (output in .csv file) last loging older then X days. The necessary info will be requested.

Code

Line Numbers: On  Off      Plain Text
'******************************************************************
' naam:     ActiveADUsers.vbs
' function: Query in Active Directory for user(s) Last Login
' options:  The necessary info will be requested
' author:   Pinkel
' versie:   1.2
' datum:    31-03-2011
'******************************************************************
On Error Resume Next
Dim objFileSys, objLogFile
Dim objDomain
strDomain=InputBox("Enter the FQN domain in:","Check Active AD Users","DomainName.local")
If strDomain="" Then
	wscript.echo "Script canceled, no FQN domain."
	wscript.quit
Else
	If strDomain="DomainName.local" Then
		wscript.echo "Script canceled, no FQN domain."
		wscript.quit
	End If
End If
strADomain = Split(strDomain, ",")
Set objDomain = GetObject("WinNT://" & strADomain (0))
If err.number<>0 Then
	wscript.echo "Error, no contact with " & objDomain
	wscript.quit
End If
strUserName=InputBox("Enter the user name:" & vbCrLf & _
	"(when blanck, all users)" & vbCrLf & _
	"Please note, case sensitive","Check Active AD Users","")
If strUserName="" Then
	strNumDays=InputBox("The number of days not logged in?","Check Active AD Users","180")
	If strNumDays="" Then
		wscript.echo "Script canceled, no number of days."
		wscript.quit
	Else
		objOlderThen = Now - strNumDays
	End If
	strLogName=InputBox("Enter the name of csv file in:","Check Active AD Users","DomainUsers.csv")
	If strLogName="" Then
		wscript.echo "No csv file entered!"
		wscript.quit
	End If
	Set objFileSys = CreateObject("Scripting.FileSystemObject") 
	Set objLogFile = objFileSys.CreateTextFile(strLogName, True) 
	objLogFile.write "UserName;Full Name;Lastlogin;Description" & vbNewLine
	objDomain.Filter = Array("user")
	For Each objUser In objDomain
	    strDisplayName = objUser.FullName
		strUserLogin = objUser.LastLogin
		strDescription = objUser.Description
		If UBound(strADomain) >= 1 Then
			For ii = 1 To UBound(strADomain)
				Set strAccount = GetObject("WinNT://" & strADomain(ii) & "/" & objUser.Name & ",user")
				If strAccount.LastLogin > strUserLogin Then strUserLogin = strAccount.LastLogin
			Next
		End If
		If strUserLogin < objOlderThen Then
			objLogFile.write Left(objUser.Name,22) & ";" & strDisplayName & ";" & FormatDateTime(strUserLogin) & ";" & strDescription & vbNewLine
		End If
	Next
	objLogFile.close
	Wscript.echo "Script ActiveADUsers.vbs ready."
Else
	objDomain.Filter = Array("user")
	
	For Each objUser In objDomain
		strUserLogin = objUser.LastLogin
		If UBound(strADomain) >= 1 Then
			For ii = 1 To UBound(strADomain)
				Set strAccount = GetObject("WinNT://" & strADomain(ii) & "/" & objUser.Name & ",user")
				If strAccount.LastLogin > strUserLogin Then strUserLogin = strAccount.LastLogin
			Next
		End If
		If objUser.Name = strUserName Then
			WScript.Echo "User " & Left(objUser.Name,22) & " last login is: " & FormatDateTime(strUserLogin)
			Set objDomain=Nothing
			Set Shell=Nothing
			WScript.Quit
		End If
	Next
	Wscript.echo "Uer " & strUserName & " not found. Please note, case sensitive."
End If
Set objDomain=Nothing
Set Shell=Nothing
Wscript.Quit

 


Got a useful script? Click here to upload!


 

  Post Comment
Order By:  
User Comments
      
Robert Bolana
Posted On: 6/28/2018 5:24:08 AM

Thanks for sharing such great Article. You really shared such a useful Information with us which helped me a lot and I have bookmarked your page so that I can get to learn new things each time you share any great Information to us. Thanks for sharing. Keep up the Good Work!! Click Here

qzyfffff
Posted On: 1/12/2019 8:41:04 AM

offwhite yeezy boost 350 yeezy 500 vans outlet replica rolex jordans balenciaga adidas shoes jordan 6 adidas ultra boost westbrook shoes adidas tubular shadow chrome hearts nike flyknit racer michael kors outlet nfl jerseys cheap nba jerseys off white shoes jordan shoes michael kors handbags balenciaga fila nike air max 2018 fila shoes cheap nfl jerseys nike air max 2017 adidas yeezy fila disruptor nike air huarache curry 4 shoes golden goose outlet golden goose fila nike hyperdunk hermes handbags bag yeezy hermes handbags for sale goyard crazy explosive coach handbags nike sneakers for men kyrie irving shoes pandora bracelet off white fake rolex michael kors handbags kobe sneakers moncler jackets cheap jordans nike react yeezy boost 350 golden goose outlet adidas tubular nike kd 11 nike react louboutin shoes balenciaga triple s yeezy boost 350 v2 yeezy boost 350 v2 adidas shoes outlet off white clothing jordan shoes adidas stan smith sneakers adidas nmd r1 lebron 16 nike flyknit nike polo shirts kd shoes kd 11 lebron 16 shoes nike cortez men nfl store red bottoms hermes handbags lebron 16 shoes james harden shoes yeezy boost 350 golden goose outlet michael kors outlet online goyard bag air max 2019 adidas ultra boost uncaged lacoste online shop goyard handbags cat boots goyard bag balenciaga nike air max lebron 11 hermes belt michael kors handbags tory burch shoes nike huarache air max 270 hermes belts for men adidas tubular balenciaga shoes yeezy boost 350 coach outlet caterpillar boots adidas ultra boost fake rolex hogan outlet online golden goose kate spade handbags air jordan 4 yeezy shoes nike shoes red bottom shoes lacoste polo kd shoes lebron james shoes timberland outlet nike sneakers for women nike air max 90 yeezy shoes yeezy shoes curry 5 yeezy shoes adidas nmd off white adidas yeezy kobe shoes off white nike ultra boost fila shoes yeezy shoes fitflops gucci belt yeezy nhl jerseys timberland boots yeezy kd shoes yeezy boost 350 nike epic react hermes belt hermes birkin golden goose sneakers nike vapormax kevin durant shoes adidas zx flux adidas pure boost yeezy boost polo ralph lauren air jordan supreme hoodie valentino shoes nike cortez nike lebron 16 kd 11 shoes asics shoes vapormax jimmy choo shoes chrome hearts coach factory outlet kobe byrant shoes birkin bag adidas stan smith michael kors outlet online michael kors nike air max 2019 nike polo nike shox nike roshe run lacoste outlet adidas crazy explosive michael kors handbags fila shoes goyard handbags mbt shoes curry 4 jordan shoes mbt shoes online coach outlet online fila sneakers off white hoodie yeezy boost 350 v2 calvin klein outlet yeezys cheap jordans adidas tubular longchamp outlet basketball shoes kyrie 3 retro jordans links of london yeezy boost 350 michael kors purses yeezy boost lacoste outlet adidas gazelle yeezy boost 700 air yeezy chrome hearts online curry 4 lebron shoes asics running shoes goyard handbags nike foamposite coach outlet sale air max 2018 hermes belt kyrie 4 shoes jordan retro 6 adidas superstars goyard bags cheap nba jerseys hermes outlet online michael kors outlet air jordans russell westbrook shoes yeezy boost 350 v2 hermes bags jordan 12 lacoste polo shirts longchamp handbags fitflops sale clearance yeezys longchamp kd 10 birkin bag ralph lauren uk jordan 4 golden goose sneakers ysl handbags lacoste polo converse outlet store nike air max nmd valentino ysl longchamp bags converse outlet harden shoes adidas stan smith shoes adidas eqt support yeezy boost fila hogan outlet nike basketball shoes nike air max goyard canada goose jacket coach factory outlet yeezy boost paul george shoes nike epic react retro jordans iniki bape hoodie moncler jacket nike air max jordan shoes cheap mlb jerseys adidas yeezy adidas outlet online canada goose fila yeezy boost 350 air jordan curry 5 balenciaga shoes nike air max 270 stephen curry 5 golden goose nike roshe calvin klein outlet online michael kors outlet michael kors outlet online rolex replica bape hoodie ferragamo belt yeezy boost 350 michael jordan shoes michael kors handbags off white hoodie nike shox for men jordans red bottom heels coach outlet kobe 9 goyard bags ralph lauren uk nmd michael kors outlet hermes online shop jordan retro pure boost golden goose outlet adidas outlet balenciaga shoes fake rolex watches balenciaga sneakers nike air force 1 coach outlet chrome hearts online jordan shoes adidas iniki coach outlet yeezy boost gucci belts golden goose sneakers kd 11 stephen curry 5 nike huarache air jordan 13 birkin bag coach outlet sale goyard wallet michael kors handbags lebron shoes ferragamo belt vans shoes michael kors outlet jordan 13 adidas yeezy boost fila shoes ferragamo belts tory burch outlet nike sneakers kobe 9 lebron 10 yeezy boost 350 v2 lebron 16 adidas shoes online yeezy shoes yeezy boost 500 michael kors jordan 11 cheap jordans links of london outlet store nike max lebron 15 shoes supreme hoodie hermes handbags off white clothing goyard st louis tot reebok outlet air max 90 chrome hearts moncler jackets nike jordans jordan sneakers off white x jordan 1 golden goose sneakers yeezy boost golden goose michael kors factory outlet adidas stan smith nba jerseys coach outlet online adidas superstar golden goose tory burch off white shoes adidas yeezy tory burch sandals yeezy boost 350 yeezy 700 jordans lacoste adidas nmd kyrie 4 golden goose adidas nmd cheap jordans air force 1 yeezy boost kobe basketball shoes birkin bag golden goose outlet michael kors uk reebok shoes jordan 11 retro baseball jerseys 100% real jordans for cheap adidas nmd runner supreme clothing nike air force lebron 16 ferragamo belts louboutin shoes uk moncler outlet jordan retro 12 Kanye West shoes lebron 15 air max christian louboutin off white lacoste polo yeezy shoes michael kors handbags outlet zx flux yeezy boost 350 v2 pandora jewelry kobe 11 adidas eqt kyrie shoes adidas ultra kobe 11 off white clothing yeezy 500 mbt shoes outlet chrome hearts online kobe shoes off white jordan 1 michael kors outlet mlb jerseys