目标:查找过去 90 天内未发送(或可能未接收)邮件的所有邮箱。
我已看过一些有关 powershell 命令的指南,但我不确定我是否有正确的顺序(Get-Mailbox | 等),所以我不想冒险执行它?
答案1
add-pssnapin *exchange* -EA 0
Get-Mailbox -ResultSize Unlimited |Get-MailboxStatistics |?{$_.Lastlogontime -lt (Get-Date).AddDays(-90)}|Select DisplayName, LastLoggedOnUserAccount, LastLogonTime |Export-csv .\NotAccess90.csv -noType
方法二:将日志交换到 SQL Server Express 版本。
这是一种创建快速报告的方法。只需要创建要搜索的索引字段。然后查询处理速度将约为每秒 1-3 M 条记录。这是文件创建的速度 - 不会那么快。理想的工作是通过驱动程序 csv 完成的。总的来说,改进是无限的)。
但是,停止日志(SQL Server Express) - Exchange Server 也停止了!
需要sql函数:
ConvertCharIP - 将字符串 IP 地址转换为 BIGINT
CREATE FUNCTION [dbo].[ConvertCharIP] (@IP AS VARCHAR(20))
RETURNS BIGINT
AS
BEGIN
RETURN (CONVERT(BIGINT, PARSENAME(@IP,1)) +
CONVERT(BIGINT, PARSENAME(@IP,2)) * 256 +
CONVERT(BIGINT, PARSENAME(@IP,3)) * 65536 +
CONVERT(BIGINT, PARSENAME(@IP,4)) * 16777216)
END
ConvertLongIP - 将 BIGINT 转换为字符串 IP 地址。
CREATE FUNCTION [dbo].[ConvertLongIP] (@LongIP bigint)
RETURNS varchar(15) AS BEGIN
DECLARE @DotIP varchar(15), @bin varbinary(4)
select @bin = cast(@LongIP as varbinary(4))
select @DotIP = cast(convert(int,substring(@bin,1,1)) as varchar(3))
+ '.' + cast(convert(int,substring(@bin,2,1)) as varchar(3))
+ '.' + cast(convert(int,substring(@bin,3,1)) as varchar(3))
+ '.' + cast(convert(int,substring(@bin,4,1)) as varchar(3))
RETURN @DotIP END
getCurrentTime - 返回现在时间。
CREATE FUNCTION [dbo].[getCurrentTime]()
RETURNS DATETIME
AS
BEGIN
RETURN (SELECT CurrentTime FROM CurrentDateTime)
END
使用模式:
邮件地址.sql:
SELECT
SUM(bytesrecvd)/1024 AS [Upload, Kb],
SUM(bytessent)/1024 AS [Download, Kb],
...
<other log column name>,
master.[dbo].[ConvertLongIP]([SourceIP]) AS [SourceIP],
master.[dbo].[ConvertLongIP]([DestinationIP]) AS [DestinationIP]
FROM [<Table name>]
WHERE
<other bound>
AND master.[dbo].[ConvertLongIP]([SourceIP])=@DotIP
GROUP BY [SourceIP],[DestinationIP]
SourcePort
,DestinationPort
ORDER BY [Upload, Kb] DESC
查询邮件.cmd:
@echo off
SET SQLSERVER=.\SQL2K5
SET DBName=Exch2010
SET QueryFile=MailAddress.sql
SET CSVLog=C:\MailLogCSV
@echo %date% %time%
sqlcmd -S %SQLSERVER% -d %DBName% -E -h-1 -i %QueryFile% -o %CSVLog%\MailAddress-%DBName%.csv -s ";" -W
@echo %date% %time%