I have the following code in script my.ps1.
....
$attach = New-Object System.Net.Mail.Attachment("c:\my.log")
$msg.Attachments.Add( $attach )
And I want to schedule it running as powershell "& { my.ps1 > c:\my.log }".
However, I got the following error.
New-Object : Exception calling ".ctor" with "1" argument(s): "The process cannot access the file 'c:\my.log' because it is being used by another process."
Is anyway to implement it?