Reputation: 67
I am using a standard SendMessage command to send an email in a PowerShell script. I want to attach a log file but unfortunatly the log file is locked by a parent script.
Is there a way to send the file anyways as an attachment (I don't want to delete it or write it)?
I know I can read the file with Get-Content
, should I pipe this output to a new temporary file that is then attached? If that would work how would I go about doing this.
Upvotes: 0
Views: 512
Reputation: 471
Copy-Item should work if you can read the content with Get-Content.
Copy it as a temporary file, send it, then delete it.
Copy-Item C:\My_log.log $env:TEMP
PowerShell 2.0 and above
Send-MailMessage -Attachments $env:TEMP\My_log.log .......
PowerShell 1.0 -> PowerShell Send Email
Remove-Item $env:TEMP\My_log.log
Upvotes: 2