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 = "[email protected]"
$to = "[email protected]"
$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 = "[email protected]"
$to = "[email protected]"
$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
Topics
- All Topics
- 18 Getting started
- 12 Read before posting
- 6 Meet and greet
- 112 General
- 37 News and announcements
- 29 Resources
- 5 Knowledge Base
- 5 Webinars
- Shared Script Library
- Blog
- 3 Pro Tips
- 16 Got an idea?
- 66 Remote Monitoring and Management
- 54 Remote Monitoring
- 12 Patch Management
- 50 Professional Services Automation
- 30 Helpdesk
- 7 Billing
- 13 Reporting
- 15 Integrations & add-ons
- 10 Integrations
- 4 Add-ons
- 45 Scripting and automations
- 34 Scripts
- 10 Automations