作为 SQL 代理作业或 SSIS 包的一部分(如果您需要更复杂的处理),您可以使用此脚本来获取用户密码何时到期:
USE [master]
GO
SELECT [name] AS [sa]
,LOGINPROPERTY([name], 'PasswordLastSetTime') AS [PasswordLastResetDT]
,DATEDIFF(DAY, CONVERT([datetime],LOGINPROPERTY([name],'PasswordLastSetTime')),GETDATE()) AS [DaysUntilExpiration]
,LOGINPROPERTY([name], 'BadPasswordCount') AS [BadPasswordCount]
,LOGINPROPERTY([name], 'BadPasswordTime') AS [BadPasswordDT]
,LOGINPROPERTY([name], 'HistoryLength') AS [HistoryLength]
,LOGINPROPERTY([name], 'IsExpired') AS [IsExpired]
,LOGINPROPERTY([name], 'IsLocked') AS [IsLocked]
,LOGINPROPERTY([name], 'IsMustChange') AS [IsMustChange]
,LOGINPROPERTY([name], 'LockoutTime') AS [LockoutTime]
FROM [sys].[sql_logins]
GROUP BY [name]
之后,您需要以某种方式关联用户名和他们的密码,并在密码过期之前发送电子邮件。