Attach and send HTML file

This topic contains 2 replies, has 2 voices, and was last updated by  Ostik 4 years, 3 months ago.

  • Author
  • #13826


    Hi Guys,

    I am trying to get an HTML file attached and e-mailed to myself.
    I run a weekly script that gets and e-mails the Replication status and FSMO Roles of the Domain Controllers on the network.
    The Replication Status HTML file gets attached and sent without any issues, it's the FSMO Roles HTML file that does not get attached.
    I get the following error message:

    Send-MailMessage : Cannot find drive. A drive with the name 'The syntax of this command is
    At D:\Software\ReplicationScripts\HTMLScript.ps1:72 char:17
    + Send-MailMessage <<<< -to $toaddress -Bcc $bccaddress -From $fromaddress -Attachments " host -Subject $subject -BodyAsHtml $msgbody + CategoryInfo : ObjectNotFound: (The syntax of this command is:String) [Send Exception + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SendMailMessage I have attached the script that I am trying to run. Could you please point me in the right direction. Regards.

  • #13828

    Dave Wyatt

    Looks like you've redefined your $FSMORoles variable several times in the code. At first, it contains a file path suitable to be passed to the -Attachments parameter of Send-MailMessage, but later on, it'll contain something else.

    $FSMORoles = "E:\Software\ReplicationScripts\FSMORoles.html"
    $FSMORoles=netdom query FSMORoles > E:\Software\ReplicationScripts\FSMORoles.txt
    $FSMORoles = Get-Content $FSMORoles
    Send-MailMessage -Attachments "$FullReplication","$FSMORoles" #...
  • #13836


    Thanks a mill,

    The issue has been resolved,
    The variable should have been:
    $FSMORoles=netdom query FSMO > E:\Software\ReplicationScripts\FSMORoles.txt

    Instead of:
    $FSMORoles=netdom query FSMORoles > E:\Software\ReplicationScripts\FSMORoles.txt.
    As you pointed out, the $FSMORoles variable had a few more inconsistencies which I have also corrected.

    Thank you.

You must be logged in to reply to this topic.