Password Notifier VBscripts
In our new exchange 2007 enviroment, i run the password notifier vbscipts to check the user's password age. Below the scipts i used:' John Savill 8th June 2005' Runs check on last password change date'Option Explicit Dim objCommand, objConnection, objChild, objUserConnection, strBase, strFilter, strAttributes, objRootDSEstrPasswordChangeDate, intPassAgeDim lngTZBias, objPwdLastSet, strEmailAddress, objMessageDim objShell, lngBiasKey, k, PasswordExpiry, strRootDomainDim strQuery, objRecordset, strName, strCN, objLogfile, objFSO Dim oWshShell : Set oWshShell = CreateObject("WScript.Shell")Dim strNoOfDaysDim objRootDSE, strPasswordChangeDate ' ********************* CHANGE THESE VALUES TO PASSWORD EXPIRY AND ROOT OF WHERE USERS WILL BE SEARCHED *********************************** PasswordExpiry=90'strRootDomain="dc=contoso,dc=com"Set objRootDSE = GetObject("LDAP://RootDSE")strRootDomain = objRootDSE.get("defaultNamingContext") ' *****************************************************************************************************************************************'create logfileConst ForWriting = 2 Set objFSO = CreateObject("Scripting.FileSystemObject")Set objLogFile = objFSO.CreateTextFile("PasswordExpireLog.txt", _ ForWriting, True)'objLogFile.Writeline "List of users With Password That Nearly Expire" objLogFile.Writeline "*********************************************" objLogFile.Writeline ' Obtain local Time Zone bias from machine registry.Set objShell = CreateObject("Wscript.Shell")lngBiasKey = objShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")If UCase(TypeName(lngBiasKey)) = "LONG" Then lngTZBias = lngBiasKeyElseIf UCase(TypeName(lngBiasKey)) = "VARIANT()" Then lngTZBias = 0 For k = 0 To UBound(lngBiasKey) lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k) NextEnd If Set objCommand = CreateObject("ADODB.Command")Set objConnection = CreateObject("ADODB.Connection")objConnection.Provider = "ADsDSOObject"objConnection.Open "Active Directory Provider"objCommand.ActiveConnection = objConnectionstrBase = "<LDAP://" & strRootDomain & ">" strFilter = "(&(objectCategory=person)(objectClass=user))"strFilter = "(&(objectCategory=person)(objectClass=user)(!userAccountControl:1.2.840.113556.1.4.803:=65536))"strAttributes = "displayName,cn,mail,pwdLastSet,distinguishedName"strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"objCommand.CommandText = strQueryobjCommand.Properties("Page Size") = 100objCommand.Properties("Timeout") = 30objCommand.Properties("Cache Results") = FalseSet objRecordSet = objCommand.ExecuteoWshShell.Popup "Running at " & Date(), 1 Do While Not objRecordSet.EOF strName = objRecordSet.Fields("displayName").Value strCN = objRecordSet.Fields("cn").value strEmailAddress = objRecordSet.Fields("mail").value oWshShell.Popup "NT Name: " & strName & ", Common Name: " & strCN, 1 ' write user info to logfile 'oWshShell.Popup vbtab & "DistinguishedName: " & objRecordSet.Fields("distinguishedName").Value, 1 On Error Resume Next Set objUserConnection = GetObject("LDAP://" & objRecordSet.Fields("distinguishedName").Value) If Err.Number = 0 Then On Error GoTo 0 Set objPwdLastSet = objUserConnection.pwdLastSet strPasswordChangeDate = Integer8Date(objPwdLastSet, lngTZBias) 'oWshShell.Popup vbTab & "Password last changed at " & strPasswordChangeDate, 1 intPassAge = DateDiff("d", strPasswordChangeDate, Now) oWshShell.Popup vbTab & "Password changed " & intPassAge & " days ago", 1 If intPassAge = (PasswordExpiry-1) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 1 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 1 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 1) ElseIf intPassAge = (PasswordExpiry-2) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 2 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 2 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 2) ElseIf intPassAge = (PasswordExpiry-3) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 3 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 3 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 3) ElseIf intPassAge = (PasswordExpiry-4) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 4 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 4 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 4) ElseIf intPassAge = (PasswordExpiry-5) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 5 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 5 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 5) ElseIf intPassAge = (PasswordExpiry-6) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 6 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 6 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 6) ElseIf intPassAge = (PasswordExpiry-7) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 7 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 7 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 7) ElseIf intPassAge = (PasswordExpiry-12) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 12 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 12 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 12) ElseIf intPassAge = (PasswordExpiry-13) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 13 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 13 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 13) ElseIf intPassAge = (PasswordExpiry-14) Then oWshShell.Popup vbTab & "Sending user notification to " & strEmailAddress & " that password expires in 14 days", 1 objLogFile.Writeline " Display Name :" & strName objLogFile.Writeline " Email :" & strEmailAddress objLogFile.Writeline " Password Expires in 14 " & " days" objLogFile.Writeline Call SendEmailMessage(strEmailAddress, 14) End If Else Err.Clear On Error GoTo 0 oWshShell.Popup vbtab & "Error binding to " & objRecordSet.Fields("distinguishedName").Value, 1 End If objRecordSet.MoveNextLoop objConnection.Close Function Integer8Date(objDate, lngBias)' Function to convert Integer8 (64-bit) value to a date, adjusted for' local time zone bias. Dim lngAdjust, lngDate, lngHigh, lngLow lngAdjust = lngBias lngHigh = objDate.HighPart lngLow = objdate.LowPart ' Account for error in IADslargeInteger property methods. If lngLow < 0 Then lngHigh = lngHigh + 1 End If If (lngHigh = 0) And (lngLow = 0) Then lngAdjust = 0 End If lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _ + lngLow) / 600000000 - lngAdjust) / 1440' Trap error if lngDate is overly large On Error Resume Next Integer8Date = CDate(lngDate) If Err.Number <> 0 Then On Error GoTo 0 Integer8Date = #1/1/1601# End If On Error GoTo 0End Function Sub SendEmailMessage(strDestEmail, strNoOfDays) Set objMessage = CreateObject("CDO.Message") objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "send.contoso.com.my" objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Update objMessage.Subject = "Password Expires in " & strNoOfDays & " days" objMessage.From = "Postmaster@contoso.com.my" objMessage.To = strDestEmail objMessage.TextBody = "Your password expires in " & strNoOfDays & " day/s. Please change your password at http://webmail.contoso.com.my to prevent further logon problems." & vbCRLF & vbCRLF & vbCRLF & vbCRLF & "Regards," & vbCRLF & vbCRLF & "contoso Postmaster" 'objLogFile.Writeline 'objLogFile.Writeline 'objMessage.TextBody = "Regards," 'objLogFile.Writeline 'objMessage.TextBody = "contoso Postmaster" objMessage.SendEnd Sub In our enviroment, all DC are running on Windows Server 2008, Exchange 2007 on Windows Server 2008. The Receive connector for client and default were not check for anonymous. However, able to receive email from internet.Problem:When i run the password notifier scripts, it will generated this error: Ther server reject the sender address. the server respone was:530 5.7.1 Client was not aunthenticate.The scripts will check the password age and which password age already over then they should receive email from Postmatser@contoso.com.my ( please refer to scripts)Pleae help.
January 25th, 2010 12:24pm

Please post your query in Developers section of this forum http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threadsRaj
Free Windows Admin Tool Kit Click here and download it now
January 25th, 2010 1:24pm

Can you post Get-ReceiveConnector | fl and include the ones for the server you're relaying off of?Active Directory, 4th Edition - www.briandesmond.com/ad4/
January 26th, 2010 12:06am

#TYPE Microsoft.Exchange.Data.Directory.SystemConfiguration.ReceiveConnector AuthMechanism Tls, Integrated, BasicAuth, BasicAuthRequireTLS, ExchangeServer Tls, Integrated, BasicAuth, BasicAuthRequireTLS Tls, Integrated, BasicAuth, BasicAuthRequireTLS, ExchangeServer Tls, Integrated, BasicAuth, BasicAuthRequireTLS Tls, ExchangeServer Tls, ExchangeServer Banner BinaryMimeEnabled TRUE TRUE TRUE TRUE TRUE TRUE Bindings Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPBinding] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPBinding] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPBinding] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPBinding] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPBinding] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPBinding] ChunkingEnabled TRUE TRUE TRUE TRUE TRUE TRUE DefaultDomain DeliveryStatusNotificationEnabled TRUE TRUE TRUE TRUE TRUE TRUE EightBitMimeEnabled TRUE TRUE TRUE TRUE TRUE TRUE DomainSecureEnabled FALSE FALSE FALSE FALSE FALSE FALSE EnhancedStatusCodesEnabled TRUE TRUE TRUE TRUE TRUE TRUE LongAddressesEnabled FALSE FALSE FALSE FALSE FALSE FALSE OrarEnabled FALSE FALSE FALSE FALSE FALSE FALSE Fqdn CARINA.contoso.com CARINA.contoso.com CORVUS.contoso.com CORVUS.contoso.com CARINA.contoso.com CORVUS.contoso.com Comment Enabled TRUE TRUE TRUE TRUE TRUE TRUE ConnectionTimeout 00:10:00 00:10:00 00:10:00 00:10:00 00:10:00 00:10:00 ConnectionInactivityTimeout 00:05:00 00:05:00 00:05:00 00:05:00 00:05:00 00:05:00 MessageRateLimit unlimited 600 unlimited 600 unlimited unlimited MaxInboundConnection 5000 5000 5000 5000 5000 5000 MaxInboundConnectionPerSource unlimited 20 unlimited 20 20 20 MaxInboundConnectionPercentagePerSource 100 2 100 2 100 100 MaxHeaderSize 64KB 64KB 64KB 64KB 64KB 64KB MaxHopCount 30 30 30 30 30 30 MaxLocalHopCount 8 8 8 8 8 8 MaxLogonFailures 3 3 3 3 3 3 MaxMessageSize 10MB 10MB 10MB 10MB 10MB 10MB MaxProtocolErrors 5 5 5 5 5 5 MaxRecipientsPerMessage 5000 200 5000 200 200 200 PermissionGroups ExchangeUsers, ExchangeServers, ExchangeLegacyServers ExchangeUsers, ExchangeServers, ExchangeLegacyServers ExchangeUsers, ExchangeServers, ExchangeLegacyServers ExchangeUsers, ExchangeServers, ExchangeLegacyServers AnonymousUsers, ExchangeServers, ExchangeLegacyServers AnonymousUsers, ExchangeServers, ExchangeLegacyServers PipeliningEnabled TRUE TRUE TRUE TRUE TRUE TRUE ProtocolLoggingLevel None None None None None None RemoteIPRanges Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange] Microsoft.Exchange.Data.MultiValuedProperty`1[Microsoft.Exchange.Data.IPRange] RequireEHLODomain FALSE FALSE FALSE FALSE FALSE FALSE RequireTLS FALSE FALSE FALSE FALSE FALSE FALSE EnableAuthGSSAPI FALSE TRUE FALSE TRUE FALSE FALSE Server CARINA CARINA CORVUS CORVUS CARINA CORVUS SizeEnabled EnabledWithoutValue Enabled EnabledWithoutValue Enabled EnabledWithoutValue EnabledWithoutValue TarpitInterval 00:00:05 00:00:05 00:00:05 00:00:05 00:00:05 00:00:05 AdminDisplayName ExchangeVersion 0.1 (8.0.535.0) 0.1 (8.0.535.0) 0.1 (8.0.535.0) 0.1 (8.0.535.0) 0.1 (8.0.535.0) 0.1 (8.0.535.0) Name Default CARINA Client CARINA Default CORVUS Client CORVUS Trusted Application CARINA Trusted Application CORVUS DistinguishedName CN=Default CARINA,CN=SMTP Receive Connectors,CN=Protocols,CN=CARINA,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Sapura,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=sapura,DC=com CN=Client CARINA,CN=SMTP Receive Connectors,CN=Protocols,CN=CARINA,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Sapura,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=sapura,DC=com CN=Default CORVUS,CN=SMTP Receive Connectors,CN=Protocols,CN=CORVUS,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Sapura,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=sapura,DC=com CN=Client CORVUS,CN=SMTP Receive Connectors,CN=Protocols,CN=CORVUS,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Sapura,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=sapura,DC=com CN=Trusted Application CARINA,CN=SMTP Receive Connectors,CN=Protocols,CN=CARINA,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Sapura,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=sapura,DC=com CN=Trusted Application CORVUS,CN=SMTP Receive Connectors,CN=Protocols,CN=CORVUS,CN=Servers,CN=Exchange Administrative Group (FYDIBOHF23SPDLT),CN=Administrative Groups,CN=Sapura,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=sapura,DC=com Identity CARINA\Default CARINA CARINA\Client CARINA CORVUS\Default CORVUS CORVUS\Client CORVUS CARINA\Trusted Application CARINA CORVUS\Trusted Application CORVUS Guid 05bf7ccd-b074-44ff-8177-b7c2bdb5d223 e5261ec1-5cbb-4803-8a15-faae1aa64128 0effb4fb-0619-4bf5-84be-19642de71e2c 74fbd19c-17a2-4cbe-bae0-f7a114d0309f 24dc55f2-4867-4d97-bd3c-54df49c49d7b c9b48492-df05-423b-b21b-0773dd87f69b ObjectCategory contoso.com/Configuration/Schema/ms-Exch-Smtp-Receive-Connector contoso.com/Configuration/Schema/ms-Exch-Smtp-Receive-Connector contoso.com/Configuration/Schema/ms-Exch-Smtp-Receive-Connector contoso.com/Configuration/Schema/ms-Exch-Smtp-Receive-Connector contoso.com/Configuration/Schema/ms-Exch-Smtp-Receive-Connector contoso.com/Configuration/Schema/ms-Exch-Smtp-Receive-Connector ObjectClass Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] Microsoft.Exchange.Data.MultiValuedProperty`1[System.String] WhenChanged 08/01/2010 18:10 11/01/2010 17:03 09/01/2010 16:53 11/01/2010 17:03 26/01/2010 12:31 26/01/2010 12:31 WhenCreated 08/01/2010 18:11 08/01/2010 18:11 09/01/2010 16:55 09/01/2010 16:55 14/01/2010 17:04 14/01/2010 17:14 OriginatingServer DC001.contoso.com DC001.contoso.com DC001.contoso.com DC001.contoso.com DC001.contoso.com DC001.contoso.com IsValid TRUE TRUE TRUE TRUE TRUE TRUE
Free Windows Admin Tool Kit Click here and download it now
January 26th, 2010 12:57pm

Dear Brian,Are you able to view it. I have a txt file but not sure where to upload to
January 26th, 2010 12:58pm

You're going to either a) need to change that script to authenticate to Exchange (lots of examples on the Internet) or b) stand up a receive connector that permits anonymous relay from the IP(s) the script runs at.Active Directory, 4th Edition - www.briandesmond.com/ad4/
Free Windows Admin Tool Kit Click here and download it now
January 26th, 2010 8:23pm

I suggest you write the post in our development forum for further help: http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threadsThanks,Elvis
January 29th, 2010 6:03am

There's nothing devleopment related about this if you read the post. The customer has a script which tries to relay off of Exchange and fails with a specific DSN code. Whether it's a VBScript or some off the shelf software it's the same problem and it's Exchange config related.Active Directory, 4th Edition - www.briandesmond.com/ad4/
Free Windows Admin Tool Kit Click here and download it now
January 29th, 2010 9:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics