Question : Disable User Account with VBS Script in Active Directory

The user account will not set to disable when the date is expired or passed.

Dim objSysInfo ,objUser ,strwWWHomePage,strUserDN,ppt, strMbox

Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)

' Enable error handling
On Error Resume Next
' First command resets the value of the variable to ""
' Second attempts to set it with the value from AD
' If the second fails the variable will still be set to ""
strwWWHomePage = "" : strwWWHomePage = objUser.Get("wWWHomePage")
' Disable error handling
On Error Goto 0

dteCutOffDate = CDate("18-Jul-2010")

intDaysLeft = DateDiff("d", Now, dteCutOffDate)

If intDaysLeft > 0 Then
      ' Test the value in the variable
      If strwWWHomePage = "" Then
        Set ppt = CreateObject("PowerPoint.Application")
        strMbox = MsgBox("You have " & intDaysLeft & " days to complete this mandatory training or your account will be locked. Click OK to start PowerPoint presentation")
        ppt.Visible = True
        ppt.Presentations.Open "\\serverxx\tracking\ppt.ppsx"
      Else
        objUser.AccountDisabled = True
        objUser.SetInfo
            wscript.quit
      End If
End If

Answer : Disable User Account with VBS Script in Active Directory

Then, the morning after the cut off date, run this script, and it will read the text file and disable the accounts.

Regards,

Rob.
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:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const intForAppending = 8
strDisableAccountsFile = "\\serverxx\tracking\UsersToDisable.txt"
strDisabledReportFile = "\\serverxx\tracking\DisabledUsers.txt"
Set objOutput = objFSO.OpenTextFile(strDisabledReportFile, intForAppending, True)
Set objFile = objFSO.OpenTextFile(strDisableAccountsFile, intForReading, True)
While Not objFile.AtEndOfStream
	strUserDN = objFile.ReadLine
	If Trim(strUserDN) <> "" Then
		Set objUser = GetObject("LDAP://" & strUserDN)
		objUser.AccountDisabled = True
		objUser.SetInfo
		Set objUser = Nothing
		objOutput.WriteLine strUserDN
	End If
Wend
objFile.Close
objOutput.Close
Set objFile = Nothing
Set objOutput = Nothing
Set objFile = objFSO.CreateTextFile(strDisableAccountsFile, True)
objFile.Close
Set objFile = Nothing
MsgBox "Accounts that have been disabled have been written to " & VbCrLf & strDisabledReportsFile & VbCrLf & "and the file of users to disalbe has been cleared " & strDisableAccountsFile
Random Solutions  
 
programming4us programming4us