Below script is for automated mailing (Virtual Assistant) of reports by sending mail query to the Virtual Assistant scripted with Powershell. 

The mailbox is configured in Outlook 2016. When a query is fired to the mailbox with “automation” as subject and query in the mailbody as – for e.g. “send me report of AD”. The Script reads the inbox and replies accordingly. The mail body contents has to be matched in the script.

$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$folder=$namespace.GetDefaultFolder(6) 

$folder.Items |  
    ?{($_.subject -match "automation") -and ($_.receivedtime -ge (get-date).Date)} `
    | sort receivedtime -desc `
    | %{
        if($_.Unread)
        {
            if($_.HTMLBody -match "Send me report of AD")
            {
                $_.Subject = "RE: " + $_.Subject
                $_.HTMLBody = "Thank you for the mail <br> Here comes the AD Report" + "<br>" + `
                        "_____________________________________________" + "<br>" + `
                        "`nFrom: $($_.Sender.Name.ToString())`n" + "<br>"+ `
                        "Sent: $($_.ReceivedTime.ToString())`n" + "`n" + `
                        "To: $($_.To.ToString())`n" + "`n"+ "Cc: $($_.CC.ToString())`n" + `
                        "`n"+ "$($_.Subject)`n`n`n" + "`n"+ $_.HTMLBody

                $_.To =  $__item.Sender.Name.ToString()
                $_.HTMLBody
                $_.Send()
            }
            elseif($_.HTMLBody -match "Send me report of firewall") {
               $_.Subject = "RE: " + $_.Subject
               $_.HTMLBody = "Thank you for the mail <br> Here comes the Firewall Report"+ "<br>"+ `
                        "_____________________________________________" + "<br>" + `
                        "`nFrom: $($_.Sender.Name.ToString())`n" + "<br>"+ `
                        "Sent: $($_.ReceivedTime.ToString())`n" + "`n" + `
                        "To: $($_.To.ToString())`n" + "`n"+ "Cc: $($_.CC.ToString())`n" + `
                        "`n"+ "$($_.Subject)`n`n`n" + "`n"+ $_.HTMLBody


                $_.To =  $__item.Sender.Name.ToString()
                $_.HTMLBody
                $_.Send()
            }
           
            else {
                $_.Subject = "RE: " + $_.Subject
                $_.HTMLBody = "Thank you for the mail <br>"+ "<br>"+ `
                        "_____________________________________________" + "<br>" + `
                        "`nFrom: $($_.Sender.Name.ToString())`n" + "<br>"+ `
                        "Sent: $($_.ReceivedTime.ToString())`n" + "`n" + `
                        "To: $($_.To.ToString())`n" + "`n"+ "Cc: $($_.CC.ToString())`n" + `
                        "`n"+ "$($_.Subject)`n`n`n" + "`n"+ $_.HTMLBody

                $_.To =  $__item.Sender.Name.ToString()
                $_.HTMLBody
                $_.Send()
            }

        } 
    }
 

The script matches string with the mail content and replies a sample message. This can be further expanded to attach reports in the mail reply or can trigger some other script. By whitelisting the source server IP in exchange server, the triggered script can run and initiate mail to the requester.

Hope you like this article and thank you for reading.