Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Modify Powershell script to send .html attachments

Avatar of E=mc2
E=mc2 asked on
Email ClientsScripting LanguagesPowershell
2 Comments1 Solution18 ViewsLast Modified:
I would like to modify the script so that any html files it finds at this path:
"C:\Users\User1\Desktop\Path
that start with "Desktop-123-Files.... "...
Are sent as attachments with the email.

If there are 2 or 3 html files that all start with the designation above, they should be sent as attachments.
Is this possible?

#Send Email 
$EncryptedCredential = "C:\creds\creds.txt" 
$EmailUsername = "email1@email.com" 
$EncryptedPW = Get-Content $EncryptedCredential | ConvertTo-SecureString 
$Credential = New-Object System.Management.Automation.PsCredential($EmailUsername, $EncryptedPW) 
$EmailFrom = "email1@email.com" 
$EmailTo = "email1@email.com"
$SMTPServer = "smtp.smtp.com" 
$SMTPPort = 123
$subject = "Files Processed"
 
$SMTPSsl = $true 
 
$param = @{ 
    SmtpServer = $SMTPServer 
    Port = $SMTPPort 
    UseSsl = $SMTPSsl      
    Credential = $Credential     
    From = $EmailFrom      
    To = $EmailTo   
    Subject = $subject
} 
 
Send-MailMessage @param