header1   header
header
header : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
IMPORTANT: PowerShellCommunity.org is moving! - Wednesday, August 15, 2012

PowerShellCommunity.org is moving!  This community software, and the hardware that it sits on, are no longer serving the purposes of this community.  As a result, we have decided to move this community to a new home at PowerShell.org.  PowerShell.org is already up and running with the new community software and in its new location, so please post any new questions that you have on the forums over there instead of posting them on this site.  We've already started getting some great questions from members of the community over there so please, come on over and join us!

While we are going through this transition, this site will remain up for the short term.  New posts may no longer be created on these forums, however replies to existing posts are allowed so that users who posted questions don't have to re-post the same question on the new site.

[UPDATE 28/02/2013] New user registration has been disabled and forums have now been switched to read-only, including for existing posts since all threads that were started should now be completed. If you have a question about content on this site or about PowerShell in general, head over to PowerShell.org and ask it there where there are people actively using the site and answering questions.

If you have any questions, please let us know on the PowerShell.org site.

Thank you,

Kirk "Poshoholic" Munro

 
24 hour user report that emails .csv attachment.
Last Post 17 Aug 2011 05:20 PM by Marco Shaw. 1 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages
FuriouSUser is Offline
New Member
New Member
Posts:3
Avatar

--
15 Aug 2011 08:39 AM
    I am pretty new to PowerShell and wanted some peer review on these scripts.  I am playing around with some easy to run message log reporting scripts that allow admins with a lesser understanding of PowerShell and Exchange to easily pull reports and get the results in email.  I have shortcuts to these scripts on the desktop of a CAS/HUB server that allows any admin with RDP access to easily run the reports.

    These scripts prompt for the user name to run the report on and then for the the username of the intended recipient of the report.  I opted to attach a .csv file instead of text to allow easy sorting of the data in excel.

    The script is currently designed for domain user support only, usernames will need to be formatted as first.last.  A few tweaks to it would easily allow for complete email address checks or for a different domain username standard.

    If possible, having this script pop up a calendar that users can select the date range form would be ideal.

    Any peer review is appreciated here.  As I said, I am new to powershell and appreciate all insights

    24 hour sent.
    #Add Snapin#
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

    #Define Variables#
    $start = ((get-date).AddHours(-24))
    $end = get-date
    $sender = read-host "Enter Senders Username (first.last)"
    $reportaddress = read-host "Enter Your Username(first.last)"
    $filename = "C:\temp\$sender{0:yyyyMMdd-HHmm}.csv" -f (get-date)

    #Command#
    Get-TransportServer | Get-MessageTrackingLog -resultsize unliminted -Sender $sender@domain.com -Start $start -End $end | ?{$_.EventID -eq 'RECEIVE'} | Select-Object Timestamp,MessageSubject,{$_.Recipients} | Sort-Object -Property Timestamp | Export-Csv -NoTypeInformation $filename

    #Email#
    $EmailFrom = "sendingaddress@domain.com"
    $EmailTo = "$reportaddress@domain.com"
    $EmailSubject = "$sender Email Report"  
    $SMTPServer = ""
    $emailattachment = $filename
    $mailmessage = New-Object system.net.mail.mailmessage 
    $mailmessage.from = ($emailfrom) 
    $mailmessage.To.add($emailto)
    $mailmessage.Subject = $emailsubject
    $mailmessage.Body = $emailbody
    $attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
    $mailmessage.Attachments.Add($attachment)
    #$mailmessage.IsBodyHTML = $true
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)  
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("$SMTPAuthUsername", "$SMTPAuthPassword") 
    $SMTPClient.Send($mailmessage)


    24 hour received
    #Add Snapin#
    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.Admin

    #Define Variables#
    $start = ((get-date).AddHours(-24))
    $end = get-date
    $recipient = read-host "Enter Recipients Username (first.last)"
    $reportaddress = read-host "Enter Your Username(first.last)"
    $filename = "C:\temp\$sender{0:yyyyMMdd-HHmm}.csv" -f (get-date)

    #Command#
    Get-TransportServer | Get-MessageTrackingLog -resultsize unlimited -Recipient $recipient@domain.com -Start $start -End $end | ?{$_.EventID -eq 'DELIVER'} | Select-Object Timestamp,MessageSubject,Sender | Sort-Object -Property Timestamp | Export-Csv -NoTypeInformation $filename

    #Email#
    $EmailFrom = "sendingaddress@domian.com"
    $EmailTo = "$reportaddress@domain.com"
    $EmailSubject = "$recipient Email Report"  
    $SMTPServer = ""
    $emailattachment = $filename
    $mailmessage = New-Object system.net.mail.mailmessage 
    $mailmessage.from = ($emailfrom) 
    $mailmessage.To.add($emailto)
    $mailmessage.Subject = $emailsubject
    $mailmessage.Body = $emailbody
    $attachment = New-Object System.Net.Mail.Attachment($emailattachment, 'text/plain')
    $mailmessage.Attachments.Add($attachment)
    #$mailmessage.IsBodyHTML = $true
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)  
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("$SMTPAuthUsername", "$SMTPAuthPassword") 
    $SMTPClient.Send($mailmessage)
    Marco ShawUser is Offline
    Veteran Member
    Veteran Member
    Posts:1684
    Avatar

    --
    17 Aug 2011 05:20 PM
    Sorry, I just don't have enough free time to look at this in detail, but thought I'd point out this PowerShell calendar blog post that I remembered:
    http://mow001.blogspot.com/2006/10/...n-gui.html
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Many thanks to our original sponsors: Quest Software • SAPIEN Technologies • Compellent • Microsoft footer
    footer   footer