2017-03-16 2 views
0

Exchange 용 powershell 스크립트를 작성하여 특정 사서함이 1 개월 내에받은 전자 메일의 양을 찾아 해당 개체 합계를 특정 개인에게 전자 메일로 보내려합니다. 지금까지 내가 가진했습니다Exchange 자동화 스크립트

$date = Get-Date -Format MM/dd/yyyy 
$time = Get-Date -Format HH:mm:ss 
$previousMonth = 

PS C:\> Get-MessageTrackingLog -Recipients:mailbox1.org -start "02/01/2017 00:00:00" -end "$date $time" -EventId "Receive" -ResultSize unlimited | Measure-Object 
PS C:\> Get-MessageTrackingLog -Recipients:mailbox2.org -start "02/01/2017 00:00:00" -end "$date $time" -EventId "Receive" -ResultSize unlimited | Measure-Object 
PS C:\> Get-MessageTrackingLog -Recipients:mailbox3.org -start "02/01/2017 00:00:00" -end "$date $time" -EventId "Receive" -ResultSize unlimited | Measure-Object 
PS C:\> Get-MessageTrackingLog -Recipients:mailbox4.org -start "02/01/2017 00:00:00" -end "$date $time" -EventId "Receive" -ResultSize unlimited | Measure-Object 
ps c:\> Send-MailMessage -SmtpServer "server" -To "recipient email<recipient email>" -From "Monthly Mailbox Totals <email address>" -Subject "Monthly Mailbox Item Count" -Body "" 

는 내가에 문제가 있어요 이것이다 : 나는 꽤 -start 입력 이전 달의 1을 얻을 수 날짜 범위를 계산하는 방법을 알아낼 수 없습니다 현재 날짜와 시간에서부터 시작하여 두 번째로 합계를이 형식의 전자 메일 본문으로 보내는 방법에 대해 고민하고 있습니다. 이 스크립트가 도움이된다면 매달 첫 번째 스크립트를 실행하고 싶습니다.

어떤 조언을 미리 주시면 감사하겠습니다.

+0

로 날짜 열을 변환 유형 가속기를 사용할 수 있습니다. 자신을 단 한 명으로 제한해야합니다. 과거에 날짜를 얻고 현재의 서식 논리를 유지하는 데 사용할 수있는 날짜 방법이 있습니다. 추적 로그 요청의 결과도 저장하지 않습니다. 이것을 자동화하는 방법을 묻고 있습니까? – Matt

답변

0

System.DateTime에는 AddX (일, 시간, 분 등) 기능이 있습니다. 이들을 사용하여 정확한 시간대를 지정할 수 있습니다. 그런 다음 Get-MessageTrackingLog에서 반환 된 값을 더하고 변수의 내용을 멀리 보냅니다. 당신이 시간대를 직접 설정할 수있는 유연성이 필요하면

$StartDate = (Get-Date).AddDays(-14) #Get the last 2 Weeks 
$EndDate = Get-Date 
$i = 0 
$ += (Get-MessageTrackingLog -Recipients "RecipientA" -Start $StartDate -End $EndDate -EventId "Receive" -ResultSize unlimited | measure).Count 
$ += (Get-MessageTrackingLog -Recipients "RecipientB" -Start $StartDate -End $EndDate -EventId "Receive" -ResultSize unlimited | measure).Count 
Send-MailMessage -SmtpServer "server" -To "recipient" -From "sender" -Subject "Mailcount" -Body "Mail count for this month is $i" 

당신은 단순히 내가 여기에 2-3 별도의 질문을 참조 DateTime

$StartDate = [DateTime]"3.10.17" 
+0

굉장히 고마워요! (Get-Date) .AddDays (-14)를 사용하여 서식을 지정할 수 있습니까? MM/dd/yyyy HH : mm : ss (Get-Date) .AddDays (-14) -Format MM/dd/yyyy HH : mm : ss – xs0u1x

+0

필요하지 않습니다. 'Get-MessageTrackingLog'에서 사용하도록 포맷하십시오. 단순히 현재 날짜 및 시간을 사용하고 14 일을 뺄 것입니다. 출력 목적으로 포맷하고 싶다면'(Get-Date) .AddDays (-14) .ToString ("MM/dd/yyyy HH : mm : ss")' – Fairy