rakkad
asked on
Powershell script include embedded images
Hi
I have a powershell script that uses the send-mailmessage cmdlet, but the script needs to incorporate a nbs.bmp image as part of the message body, but can't seem to get this working.
Can anyone help please
Thank-you
I have a powershell script that uses the send-mailmessage cmdlet, but the script needs to incorporate a nbs.bmp image as part of the message body, but can't seem to get this working.
Can anyone help please
Thank-you
ASKER
I have built my script around using send-mailmessage and i don't want to change the script by using net.objects.
Is there an alternative approach ?
Thanks
Is there an alternative approach ?
Thanks
No, footech is right, if you want embedded attachments you need to use the .NET class which underpins Send-MailMessage.
There are pre-existing scripts kicking around which do exactly the same thing as footech's response, but you're just substituting the work you can get support on from footech with something someone else did (which, ultimately, will be the much the same anyway).
There are pre-existing scripts kicking around which do exactly the same thing as footech's response, but you're just substituting the work you can get support on from footech with something someone else did (which, ultimately, will be the much the same anyway).
ASKER
Can I use a combination of both, so still remain the existing send-mailmessage command and use .net class as well ?
Thanks
Thanks
Nope, sorry. This part of the functionality provided above is mandatory:
$Attachment = New-Object System.Net.Mail.Attachment($AttachmentPath)
$Attachment.ContentID = "SomeImage"
I do appreciate this is frustrating, unfortunately Send-MailMessage (like many, many other commands) doesn't flex to meet requirements like this.
What Chris is talking about is something like the modified Send-MailMessage at https://gallery.technet.microsoft.com/scriptcenter/Send-MailMessage-3a920a6d .
ASKER
This relates to LVL69
The script that I have created looks for files in c:\cogtest which is ok, but then when it tries to send files it further looks for files in c:\windows\system32, so I am having to copy files to c:\windows\system32 and then it is ok.
Is this related to system.io.path that is defined in this script. Can it be changed so it looks at c:\cogtest ?
Thanks
The script that I have created looks for files in c:\cogtest which is ok, but then when it tries to send files it further looks for files in c:\windows\system32, so I am having to copy files to c:\windows\system32 and then it is ok.
Is this related to system.io.path that is defined in this script. Can it be changed so it looks at c:\cogtest ?
Thanks
When you use paths with .NET types they do not honour the PowerShell path; they don't know anything about it. You end up in whatever is the working directory for the program you're using. In the case of Powershell that's quite frequently set to C:\Windows\System32.
There are a number of approaches you can take. For example:
There are a number of approaches you can take. For example:
(Get-Item $relativePath).FullName
Or:(Resolve-Path $relativePath).Path
Exactly which approach is most appropriate depends on your code. It's a known aspect of working with .NET types which ingest paths in PowerShell.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks. This helped me sort the issue out
Open in new window