Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Аватара для Daemonstar

Новый участник


Сообщения: 43
Благодарности: 0

Профиль | Сайт | Отправить PM | Цитировать


Добавлено логирование и мейл нотификация.

читать дальше »
Set wshShell = WScript.CreateObject( "WScript.Shell" )
Dim strComputer
Dim objIADsContainer
Dim objIADsUser
Dim dtLastLogon
Dim objDictExcludeUsers
dateStamp = Now()

Set objDictExcludeUsers = WScript.CreateObject("Scripting.Dictionary")

With objDictExcludeUsers
.Add "excludе_login1", ""
.Add "exclude_login2", ""
.Add "exclude_login3", ""
.Add "login4", ""
End With

Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Set objLog = objFSO.CreateTextFile("C:\blocked_users_log.txt")
objLog.WriteLine (cstr(dateStamp))

StrComputer = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Set objIADsContainer = GetObject("WinNT://" & strComputer & ",computer")
objIADsContainer.Filter = Array("user")
For Each objIADsUser In objIADsContainer
On Error Resume Next
dtLastLogon = CDate(objIADsUser.LastLogin)
If Err.Number = 0 Then
On Error Goto 0
If DateDiff("d", dtLastLogon, Now()) > 90 And (objIADsUser.AccountDisabled = False) Then
If Not objDictExcludeUsers.Exists(objIADsUser.Name) Then
objLog.WriteLine "Blocked account: " & objIADsUser.Name & " Last login: " & dtLastLogon & vbNewLine
objIADsUser.AccountDisabled = True
objIADsUser.SetInfo
End If
End If
End If
Next
objLog.Close
On Error Goto 0
Set S = CreateObject("Wscript.Shell")
set FSO=createobject("scripting.filesystemobject")
Call SendPost("smtp.server.com","to_email1@example.com, to_email2@example.com","from_email@example.com","Accounts blocked on "&StrComputer,"")
Function SendPost(strSMTP_Server,strTo,strFrom,strSubject,strBody)
Set iMsg=CreateObject("CDO.Message")
Set iConf=CreateObject("CDO.Configuration")
Set Flds=iConf.Fields
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate")=0
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername")="blabla"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword")="xXx"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver")="smtp.example.com"
Flds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
Flds.Update
iMsg.Configuration=iConf
iMsg.To=strTo
iMsg.From=strFrom
iMsg.Subject=strSubject
iMsg.TextBody=strBody
'iMsg.AddAttachment "C:\blocked_users_log.txt"
Const FileToBeUsed = "C:\blocked_users_log.txt"
Set objLog = objFSO.OpenTextFile(FileToBeUsed)
'** The ReadAll method reads the entire file into the variable BodyText
iMsg.Textbody = objLog.ReadAll
'** Close the file
objLog.Close
'** Clear variables
Set objLog = Nothing
iMsg.Send
End Function
Set iMsg=Nothing
Set iConf=Nothing
Set Flds=Nothing
WScript.Quit 0

Отправлено: 16:05, 28-05-2013 | #11