none
Script alerta contas que vão expirar RRS feed

  • Pergunta

  • Senhores bom dia;
    Em minha empresa eu tenho um dominio 2003 e uso o google mail.
    Preciso saber quando as contas de rede vão expirar, com isso, queria um script que realizasse a tal tarefa.
    Achei esse script no site do script center, mas não estou conseguindo colocar para funcionar com o google mail.

    Vocês podem me ajudar?
    O erro está ocorrendo na linha 64 e caracter 37, caractere inválido.

     



    '==========================================================================
    'Milan on 1/12/2011
    ' This script can be used to notify users of when their windows passords
    ' are going to expire. Especially useful in those cases where user does not logon
    ' to windows with individual login and uses OWA for email
    ' Script is currently running fine in a Exchange 2010 env with AD 2008
    '==========================================================================
    On Error Resume Next
    Const ADS_SCOPE_SUBTREE = 2
    Const SEC_IN_DAY = 86400
    Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000 ' tocheck for accounts that have "no expire" set on the password

    Dim maxPwdAge
    maxpwdage = 90 'set this according to policy in your organization
    Dim numDays
    Dim warningDays
    warningDays = 14 ' set this according to policy in your organization

    'ADO to access Active Directory
    Set objConnection = CreateObject("ADODB.Connection")
    Set objCommand = CreateObject("ADODB.Command")
    objConnection.Provider = "ADsDSOObject"
    objConnection.Open "Active Directory Provider"
    Set objCommand.ActiveConnection = objConnection
    Set objRootDSE = GetObject("LDAP://rootDSE")

    DomainString = objRootDSE.Get("dnsHostName")

    objCommand.Properties("Page Size") = 1000
    objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE

    objCommand.CommandText = "SELECT DisplayName,mail,DistinguishedName,sAMAccountName  FROM 'LDAP://DC=marcus-ti,DC=local'" & _
        " where objectClass='user'"
     '" WHERE objectCategory='user'" 'This was creating problems where it was picking up two objects that were contacts, not users
    Set objRecordSet = objCommand.Execute

    objRecordSet.MoveFirst 'get to the first record in the recordset
    Do Until objRecordSet.EOF
        strUser = objRecordSet.Fields("sAMAccountName").Value
        strDN = objRecordSet.Fields("DistinguishedName").Value   'This is important otherwise we cannot pull the "last Password Change date
        strMail = objRecordSet.Fields("mail").Value
        strFullName = objRecordSet.Fields("DisplayName").Value
     
            For Each objItem in strUser  'one record at a time
                Set objUserLDAP = GetObject ("LDAP://" & strDN & "")
                intCurrentValue = objUserLDAP.Get("userAccountControl") ' For checking if the account is disabled
               
       '*******************************************************************************************
       'BEGIN OF PASSWORD EXPIRATION WARNING
       '*******************************************************************************************

        numDays = maxpwdage
        dtVal = objUserLDAP.PasswordLastChanged 'The latest date the user changed her/his password
        whenPasswordExpires = DateAdd("d", numDays, dtval)
        fromDate = Date
        daysLeft = DateDiff("d",fromDate,whenPasswordExpires)
        If (daysLeft < warningDays) and (daysLeft > 0) then  'If 14 days or less remain until Password expires
            If strMail <> "" Then
             Set objEmail = CreateObject("CDO.Message")
          objEmail.From = "marcus.p.gioscia@gmail.com"
          objEmail.To = marcus.p.gioscia@gmail.com
          objemail.cc = "marcus.p.gioscia@gmail.com"
          objEmail.Subject = strFullname & ", your Windows Password is expiring soon!!"
          objEmail.HTMLBody = "Your Password Expires in " & daysLeft & " day(s)" & vbcrlf & _
          "<h3>Windows users - Press CTRL-ALT-DEL and select the CHANGE A PASSWORD option</h3>" & vbcrlf & _
          "<h3>Outlook Web Users - Please click (Options) and choose (Change your Password)</h3>" & vbcrlf & _
          "<h3>This reminder will continue until you change your password</h3>" & vbcrlf & _
          "<h3> Please do not reply to this email</h3>"
          objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "192.168.xx.xx"
              objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          objEmail.Configuration.Fields.Update
          objEmail.Send
           'end if
         End If
            End if
            Next
        objRecordSet.MoveNext ' Keep going down the table
    Loop

    Set objConnection = Nothing
    Set objCommand = Nothing
    Set objCommand.ActiveConnection = Nothing
    Set objRootDSE = Nothing
    Set objRecordSet = Nothing
    Set objUserLDAP = Nothing
    Set objEmail = Nothing
    WScript.Quit

     

     

    att;
    Marcus

    quinta-feira, 1 de dezembro de 2011 11:10

Respostas

  • Marcus,

    Indique também o texto da linha que dá o erro pois por conta de linhas em branco a linha 64 pode ser diferente do que eu imagino.

    De cara vi um erro na linha:

    objEmail.To = marcus.p.gioscia@gmail.com

    o correto seria o e-mail entre aspas.

    objEmail.To = "marcus.p.gioscia@gmail.com"

     

    Sem as aspas é gerado o erro abaixo:

    Microsoft (R) Windows Script Host Versão 5.8
    Copyright (C) 1996-2001 Microsoft Corporation. Todos os direitos reservados.
    
    E:\PROFILES\Desktop\teste.vbs(61, 40) Erro de compilação do Microsoft VBScript: Caractere inválido
    



    Fábio de Paula Junior
    quinta-feira, 1 de dezembro de 2011 12:11
    Moderador

Todas as Respostas