Scripts and results\output file handling
Hey everyone,
I am trying to figure out a way to get files resulting from a script run back to me, either by email or cloud service, preferably something that would be available via powershell without a lot of legwork. I can see this being very handy for a number of situations.
In my past life we used CW Automate (Labtech) and you could easily and natively pull a file back from a script to the ticketing system or a shared drive.
For Example, I have a script that will run Wiztree and outputs a CSV and a JPG file (I will be submitting this to the script repo when it's polished). I would like to be able to have the script send these files to me automatically.
Comments
-
PowerShell can natively send emails using the
Send-MailMessage
cmdlet. You can use this cmdlet to email the files to yourself.Example PowerShell Script:
$PSEmailServer = "your-smtp-server.com"
$from = "script@yourdomain.com"
$to = "you@yourdomain.com"
$subject = "Script Output"
$body = "See attached files for script output."
$attachments = @("C:\path\to\output.csv", "C:\path\to\output.jpg")
Send-MailMessage -From $from -To $to -Subject $subject -Body $body -Attachments $attachments3 -
This work well with Office 365, or something like SMTP2Go better ?
1 -
Thank you for sharing! This script looks great and I’ll have to try this in my environment.
2 -
As always @tanderson… superstar!
1 -
Here is what I ended up using for SMTP2Go.
I ended up having to beef up the script a bit for use with SSL and a password.
I used a double Base64 encoded string to prevent prying eyes for the email password, though it should be noted that this is in no way "encrypted", it just looks like trash unless you know what you are looking for.
I have a very small send limit set on my sub account in SMTP2Go, so not worried about it being used maliciously.
$smtpServer = "mail.smtp2go.com"
$from = "script@yourdomain.com"
$to = "you@yourdomain.com"
$subject = "Script Output"
$body = "See attached files for script output."
$port = 2525
$encrypted = [Text.Encoding]::Utf8.GetString([Convert]::FromBase64String([Text.Encoding]::Utf8.GetString([Convert]::FromBase64String('Double_Base64_String_Goes_Here')))) $smtpPassword = ConvertTo-SecureString -String $encrypted -AsPlainText -Force
$smtpCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $from, $smtpPassword $attachments = @("C:\File.csv", "C:\File.png")
Send-MailMessage -SmtpServer $smtpServer -From $from -To $to -Subject $subject -Body $body -Attachments $attachments -UseSsl -Port $port -Credential $smtpCredential -Encoding "utf8"2 -
Doesn't Atera have it's own email system or relay built-in? Is there any way to leverage this?
0 -
You could create an Alert, but then it would need to be closed and when I last looked you weren't able to feed much onto it.
Things may have changed since I last looked, and your needs might be different than mine.
1 -
You could use e.g. PowerAutomate and just trigger the workflow via your script. This would allow you to write the data into a file, send via email or feed it back via API into Atera.
1
Topics
- All Topics
- 41 Getting started
- 25 Read before posting
- 8 Meet and greet
- 238 General
- 64 News and announcements
- 1 Swag
- 1 Roadmap updates
- 79 Resources
- 12 Knowledge Base
- 16 Webinars
- 1 Shared Script Library
- 2 Blog
- 19 Pro Tips
- 27 Got an idea?
- 3 Atera Academy
- 2 ActionAI
- 1 Copilot
- 140 Remote Monitoring and Management
- 84 Remote Monitoring
- 27 Patch Management
- 106 Professional Services Automation
- 65 Helpdesk
- 17 Billing
- 21 Reporting
- 37 Integrations & add-ons
- 20 Integrations
- 10 Add-ons
- 103 Scripting and automations
- 61 Scripts
- 30 Automations