Back to top

FREE eBook: The Most USEFUL PowerShell CmdLets and more…

Grab a copy!

Send Emails Using PowerShell With Many Examples

Send Emails Using PowerShell With Many Examples
Approx Reading Time: 20 minutes

The possibility to send emails using PowerShell is a great feature and can help us tremendously if implemented in the right way. So I will show you many examples of how you can send emails using PowerShell and how you can further implement this in your daily IT routines.

To Send Emails using PowerShell we will use Send-MailMessage PowerShell CmdLet and we need a few prerequisites before start using it that I will layout here:

  • First, we need an SMTP server that will provide a service of transmitting our emails to the recipients.
  • Second, we will get SMTP credentials (user name and password) from our SMTP Server provider in order to authenticate us to the service while transmitting emails.
  • Finally, after clearing up the SMTP server provider and credentials we can start using Send-MailMessage PowerShell CmdLet with several examples that I have prepared for you.

Let’s dive into several awesome examples so we can get the look and feel of email sending capabilities using PowerShell.

Send Email Using PowerShell – Easy Example

As we have already concluded PowerShell Send-MailMessage CmdLet will help us to send email from PowerShell and here is a very simple example:

Send-MailMessage -To "recipient’s email address" -From "sender’s email address"  -Subject "Your message subject" -Body "Message text!" -Credential (Get-Credential) -SmtpServer "SMTP server" -Port 587

IMPORTANT: The values for all the parameters except Port should be replaced with actual values applicable for your case in order for this line of code to work.

In this simple example we have used just a few necessary parameters of Send-MailMessage PowerShell CmdLet to send a simple email to the recipient:

  • -To parameter value is the email address of the recipient
  • -From parameter value is the email address of the sender
  • -Subject parameter value is the email’s subject text
  • -Body parameter value is the email’s content. This is simple text content and later we will see how we can send HTML content in email’s body text.
  • -Credential parameter is the SMTP server user name and password credentials. Please look at the following subtopics in this article where I have explained the ways to pass the credentials. It is very important so pay attention to that.
  • -SmtpServer parameter value is SMTP’s server address.
  • -Port parameter value is the port number that SMTP listens for the email messages.

NOTE: If you for -From parameter use a senders email address that is not registered as sender at the SMTP server you might get an email from SMTP server support that you try sending emails from a non-registered sender’s email address. So you have to use either a registered email address or register an additional sender’s email address.

Here is the email that I have received using my SMTP server address and credentials. As you can see we have an example of sending an email with attachment and we see the Subject text and part of the email body text in the Gmail Inbox.

Email message in Gmail Inbox sent using PowerShell script

In the email body, we can see the content of the email message sent using PowerShell. This is an example of sending an email using PowerShell with Subject text, via MailJet SMTP Server, body text is just plain text and with attachment to the email.

Email message with plain text and attachment

There are many more parameters of Send-MailMessage CmdLet that we will see in the following examples a little bit further down in this article.

But before diving in with more examples and nuances of sending emails using PowerShell let’s clear the prerequisites needed for sending the emails and those are SMTP Server and SMTP Server authentication credentials.

Which SMTP Server To Use And How To Get an SMTP Server

Now you are probably wondering, wait a minute, I want to send an email using PowerShell and why we are talking about SMTP server.

Well, do you remember the old days when we were sending messages in envelopes? Did you deliver your envelopes personally to the recipient? Of course not. There is a high probability, at least to say, that you have used some providers like Post Office to do this for you.

So SMTP Server is our provider that will send emails that we write in PowerShell and send them to the recipients for us.

INFO: SMTP stands for (Simple Mail Transfer Protocol) and it is an agreed “language” or communication protocol for the applications on servers to transmit emails.

If you wonder which SMTP Server to use please do your research since there are many companies on the internet that provide such service and just to name a few: Gmail, Hotmail, Yahoo, etc.

For my examples and to test the code I have used MailJet just because it was easy to create an account and set up everything.

When I have created an account with MailJet it is possible to see the SMTP Settings:

  • the SMTP Server address (“in-v3.mailjet.com”),
  • a port that is used (587),
  • user name, and
  • password for SMTP credentials.

All these pieces of information are important when we want to send emails using Send-MailMessage PowerShell CmdLet so make sure that you have them before starting using PowerShell send email feature.

How To Send SMTP email with authentication using PowerShell

There are several ways to provide SMTP credentials while sending emails using PowerShell. We will show you two different approaches.

The first is simpler but less secure since the SMTP server password is visible to the others who have access to the source code.

The second one has one additional step but it is more secure since allows us to keep the password secured and encrypted in an external file that we can use when providing SMTP credentials.

Sending SMTP credentials with a visible password in source code (less secure)

In this example, we provide several parameters to Send-MailMessage CmdLet but the most important parameters for explaining this example are:

  • SmtpServer
  • Credential

NOTE: In order for this example to work for you please replace the values of these variables to your own data: $EmailFrom, $EmailTo, $SMTPserver, $username.

$EmailFrom = "sender’s email address"                
$EmailTo = "recipient’s email address"
            
$EmailSubject = "Learn PowerShell With Dejan - ImproveScripting.com." 
$EmailBody = "This email has an attachment error log." 

$SMTPserver= "SMTP server"
$username="your_user_name" 
$password = "your_password" | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Send-MailMessage -ErrorAction Stop -from "$EmailFrom" -to "$EmailTo" -subject "$EmailSubject" -body "$EmailBody" -SmtpServer "$SMTPserver" -Attachments "$home\Documents\PSlogs\Error_Log.txt" -Priority  "Normal" -Credential $credential -Port 587 -UseSsl

SmtpServer parameter value has an address of the SMTP Server, for example, MailJet SMTP Server is “in-v3.mailjet.com”.

The Credential parameter wraps user and password SMTP Server credentials and needs to be passed as a PSCredential object. We need to pay special attention when passing a password to the creation of a PSCredential object since a password cannot be plain text but SecureString data type. So we need to convert our plain password into SecureString data type using ConvertTo-SecureString CmdLet.

$password = "your_password" | ConvertTo-SecureString -AsPlainText -Force

As already mentioned this method is not too complicated but has security issue since we keep our SMTP Server password as plain text in our source code which is not the best practice.

Finally, here is the result and email received using this example:

Email message

Sending SMTP credentials with a hidden password in source code (more secure)

In this example, we will provide SMTP credentials while calling Send-MailMessage CmdLet but this time password will not be visible. However, this method requires an additional step from our side in order to work.

First we will encrypt our password in external txt file just once and use that file to decrypt and read our password whenever we need in our source code.

When we run this code we will be prompted to provide SMTP Server password credential. Clicking on the OK button (as you can see on the screenshot) encrypted password will be saved in an external file (In this example that is MailJet.txt file).

Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File -FilePath "C:\Users\dekib\Documents\PSCredential\MailJet.txt"
Save encrypted password in external file.

Now our password is encrypted and saved in an external file so we can use it when calling Send-MailMessage CmdLet.

Here is an example that show us how to use encrypted password in external txt file.

NOTE: In order for this example to work for you please replace the values of these variables to your own data: $EmailFrom, $EmailTo, $SMTPserver, $username.

$EmailFrom = "sender’s email address"                
$EmailTo = "recipient’s email address"
            
$EmailSubject = "Learn PowerShell With Dejan - ImproveScripting.com." 
$EmailBody = "This email has an attachment error log." 

$SMTPserver= "SMTP server"
$EncryptedPasswordFile = "$home\Documents\PSCredential\MailJet.txt"
$username="your_user_name" 
$password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Send-MailMessage -ErrorAction Stop -from "$EmailFrom" -to "$EmailTo" -subject "$EmailSubject" -body "$EmailBody" -SmtpServer "$SMTPserver" -Attachments "$home\Documents\PSlogs\Error_Log.txt" -Priority  "Normal" -Credential $credential -Port 587 -UseSsl

Now when we have cleared away the ways to pass SMTP credentials to the Send-MailMessage CmdLet we can focus on different examples.

How To Send Attachment(s) With Email Using PowerShell

Sometimes it is very convenient to accompany email with some attachments that will give us additional info. Although, we have already used examples of sending emails with attachments using PowerShell let’s look at one dedicated example. We are using -Attachments parameter of Send-MailMessage CmdLet to finish the job:

NOTE: In order for this example to work for you please replace the values of these variables to your own data: $EmailFrom, $EmailTo, $SMTPserver, $username.

$EmailFrom = "sender’s email address"
                
$EmailTo = "recipient’s email address"
            
$EmailSubject = "Learn PowerShell With Dejan - ImproveScripting.com. (Multiple recipients example)" 
$EmailBody = "This email has an attachment error log." 
                
$SMTPserver= "SMTP server"

$EncryptedPasswordFile = "$home\Documents\PSCredential\MailJet.txt"
$username="your_user_name" 
$password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PSCredential($username, $password)


Send-MailMessage -ErrorAction Stop -from "$EmailFrom" -to $EmailTo -subject "$EmailSubject" -body "$EmailBody" -SmtpServer "$SMTPserver" -Attachments "$home\Documents\PSlogs\Error_Log.txt" -Priority  "Normal" -Credential $credential -Port 587 -UseSsl

If we want to send several attachments in the same email we can easily do that since -Attachments parameter of Send-MailMessage CmdLet accepts an array of strings as input values. However, be careful how you pass the array of strings just no to be surprised with unexpected outcomes.

This is correct way to pass two attachments

$Attachments =  "$home\Documents\PSlogs\Error_Log.txt",  "$home\Documents\PSReports\Excel_report.xls"

and this one as well:

$Attachments =  @("$home\Documents\PSlogs\Error_Log.txt",  "$home\Documents\PSReports\Excel_report.xls")

but this one is wrong. So pay attention to that.

$Attachments = "$home\Documents\PSlogs\Error_Log.txt, $home\Documents\PSReports\Excel_report.xls"
Email sent with attachment (Error_Log.txt) using PowerShell

How To Send Email To Multiple Recipients Using PowerShell

If we want to send emails using PowerShell to several recipients than we have a convenience of parameter -To that accepts an array of strings in Send-MailMessage CmdLet. It is important to pay attention to how we add multiple email addresses as an array of strings and not just a single string with comma-separated values. At the end of this subtopic, I gave several examples of the right and wrong ways of passing multi recipients.

Here is an example of sending email to multiple recipients using PowerShell :

NOTE: In order for this example to work for you please replace the values of these variables to your own data: $EmailFrom, $ToRecipients, $SMTPserver, $username.

$EmailFrom = "sender’s email address"
                
$ToRecipients = "recipient’s email address 1", "recipient’s email address 2", "recipient’s email address 3" 
            
$EmailSubject = "Learn PowerShell With Dejan - ImproveScripting.com. (Multiple recipients example)" 
$EmailBody = "This email has an attachment error log." 
                
$SMTPserver= "SMTP server"

$EncryptedPasswordFile = "$home\Documents\PSCredential\MailJet.txt"
$username="your_user_name" 
$password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PSCredential($username, $password)


Send-MailMessage -ErrorAction Stop -from "$EmailFrom" -to $ToRecipients -subject "$EmailSubject" -body "$EmailBody" -SmtpServer "$SMTPserver" -Attachments "$home\Documents\PSlogs\Error_Log.txt" -Priority  "Normal" -Credential $credential -Port 587 -UseSsl

Notice the difference between the correct passing of recipient’s email addresses as a string array:

$ToRecipients = "recipient’s email address 1", "recipient’s email address 2", "recipient’s email address 3"

and wrong passing just as a single string (email addresses are comma-separated values but within a single string) instead of a string array.

$ToRecipients = "recipient’s email address 1, recipient’s email address 2, recipient’s email address 3"

In addition to sending emails to multiple recipients, we have usually email features of sending Cc (Carbon copy) and Bcc (Blind carbon copy) and for that, we use parameters -Cc and -Bcc (Send-MailMessage CmdLet) respectively while providing the email addresses as values for each of them.

How To Send Email With HTML Body Using PowerShell

We have the option to send our emails using PowerShell with HTML content inside of the email body using Send-MailMessage CmdLet. To be able to send emails using PowerShell as HTML we need to do two additional things:

  • -body parameter value should be well-formatted HTML in order for the email client to show us an HTML email.
  • -BodyAsHtml switch parameter has been passed to Send-MailMessage CmdLet just to notify it that -body parameter has HTML code in it.

Here is an example of a call to Send-MailMessage CmdLet that creates HTML email instead of plain text in the email body.

NOTE: In order for this example to work for you please replace the values of these variables to your own data: $EmailFrom, $EmailTo, $SMTPserver, $username.

$EmailFrom = "sender’s email address"                
$EmailTo = "recipient’s email address"
            
$EmailSubject = "Learn PowerShell With Dejan - ImproveScripting.com. HTML Example" 
$EmailHTMLBody = 'Learn PowerShell With Dejan - ImproveScripting.com'

$SMTPserver= "SMTP server"

$EncryptedPasswordFile = "$home\Documents\PSCredential\MailJet.txt"
$username="your_user_name" 
$password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
$credential = New-Object System.Management.Automation.PSCredential($username, $password)

Send-MailMessage -ErrorAction Stop -from "$EmailFrom" -to "$EmailTo" -subject "$EmailSubject" -body "$EmailHTMLBody" -BodyAsHtml -SmtpServer "$SMTPserver" -Attachments "$home\Documents\PSlogs\Error_Log.txt" -Priority  "Normal" -Credential $credential -Port 587 -UseSsl

Here is the resulting email that was received and as you can see in the email body we have an HTML link to this website instead of just plain text.

Send HTML email using PowerShell

How To Send Email From PowerShell Using Gmail SMTP Server

Maybe my answer will surprise you but I do not recommend using Gmail SMTP server for sending emails using PowerShell Send-MailMessage CmdLet.

The reason being for that is the fact that we need to enable in Gmail account feature: “Enable less secure apps to access Gmail”. This will lower our Gmail account security and I prefer not to do it especially that there are plenty of other options publicly available.

System.Net.Mail API

One of the alternative approaches to send emails using PowerShell is to use .NET classes in System.Net.Mail namespace. This approach is pre-Send-MailMessage CmdLet time when Send-MailMessage CmdLet was not available.

Here is example call using System.Net.Mail API:

NOTE: In order for this example to work for you please replace the values of these variables to your own data: $EmailFrom, $EmailTo, $SMTPserver, $username.

$EmailFrom = “sender’s email address”
$EmailTo = “recipient’s email address”

$EmailSubject = “Learn PowerShell With Dejan - ImproveScripting.com. (System.Net.Mail API Example)”
$EmailBody = "This email has as the attachments error log."

$SMTPServer = “SMTP server”

$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true

$EncryptedPasswordFile = "$home\Documents\PSCredential\MailJet.txt"
$username="your_user_name" 
$password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($username, $password);

$SMTPClient.Send($EmailFrom, $EmailTo, $EmailSubject, $EmailBody)

Here is the received email in the inbox after replacing the example with actual necessary parameters’ values:

Email subject in the inbox
Email using System.Net.Mail API with PowerShell

In my opinion, using System.Net.Mail .NET namespace classes is a more natural approach for .NET developers while using Send-MailMessage CmdLet is a more native PowerShell approach. Anyway, it is good to be familiar with alternatives and both approaches are useful to have in PowerShell scripting skillset.

How To Write Own CmdLet For Sending Emails Using PowerShell

I have written my own PowerShell CmdLet that provides the send mail functionality called Send-Email CmdLet.

This CmdLet belongs to Efficiency Booster PowerShell Project. This project is the library of different CmdLets that can help us IT personal to do our everyday tasks more efficiently and accurately.

Source code for Send-Email CmdLet can be downloaded from this zip file so please feel free to download it or look at source code at the bottom of this article.

Send-Email CmdLet is part of the Utils module and if you have downloaded the source code it can be found in the folder …\[My] Documents\WindowsPowerShell\Modules\02utils

I will not explain too much about this CmdLet since it is basically a wrapper around Send-MailMessage CmdLet and not especially innovative but it is important to use PowerShell capabilities of sending emails as an important mechanism in automatization and efficiency.

INFO: If you want to know how to install and configure Efficiency Booster PowerShell Project files please read the following article: How To Install And Configure PowerShell: CmdLets, Modules, Profiles.

How To Use Send Email Feature In PowerShell

I will give to you a few examples of how I have used emails combined with some other PowerShell features to be more efficient or to have a better overview of the system that needs to be maintained.

Example: Disk Free Space On Servers

I wanted to have an overview of the free space on the disks of servers that I was maintaining. So I have written my own PowerShell CmdLet Get-DiskFreeSpace that will check free space on each disk of all servers, further this CmdLet was scheduled to run once a week and produce a report as an Excel sheet that will be sent to my email so I can review it and avoid low disk free spaces.

This example can be further expanded to be used for capacity planning and send the data further to MS SQL Table and combined with MS SQL Reporting Service to get graphs with trends of disk storage usage to plan upgrades and expansions of storage in the future.

I highly recommend everyone to read the article dedicated to this PowerShell Cmdlet “How To Get Disk Size And Disk Free Space Using PowerShell”.

How To Get Disk Size And Disk Free Space Using PowerShell
How To Get Disk Size And Disk Free Space Using PowerShell

Example: Windows Event Logs On Servers

The second example has been part of my monthly maintenance routine to look into all Windows Event Logs for errors that are occurring on the servers especially with respect to OS and mission-critical applications.

For that purpose, I have written my own PowerShell CmdLet Get-ErrorFromEventLog that will check Windows Event Logs and look for errors on all servers. This script has been scheduled to run once a month prior to maintenance and further it would produce Excel Sheet so it is easy to filter and look at the data. Finally, an Excel report has been sent to my email address. So I can review the errors and be prepared to do necessary actions and avoid the same errors in the future.

In that sense, I would save a tremendous amount of time by not doing a manual job of logging on each server and manually checking each Windows Event Log on each server.

If you maintain an environment with lots of servers I highly recommend adopting this monthly routine and look at the article written about it “How To Get Windows Event Logs Details Using PowerShell”.

How To Get Windows Event Logs Details Using PowerShell Featured
How To Get Windows Event Logs Details Using PowerShell

I hope that these two examples will trigger your ideas to implement fantastic possibilities by sending an email using PowerShell combined with other PowerShell capabilities.

Useful PowerShell Send Email Articles

Here are some useful articles and resources:

Send-Email CmdLet – Source Code

DISCLAIMERSend-Email function is part of the Efficiency Booster PowerShell Project and as such utilizes other CmdLets that are part of the same project. So the best option for you in order for this function to work without any additional customization is to download the source code of the whole project from here.

INFO: My best advice to every PowerShell scripter is to learn writing own PowerShell Advanced Functions and CmdLets and I have written several articles explaining this, so please read them. How To Create A Custom PowerShell CmdLet (Step By Step). Here I explain how to use PowerShell Add-on Function to be faster in writing PowerShell Functions How To Write Advanced Functions Or CmdLets With PowerShell (Fast).

Here is the source code of the whole Send-Email CmdLet:

NOTE: In order for this example to work for you please replace the values of these variables to your own data: $EmailFrom, $EmailTo, $SMTPserver, $EncryptedPasswordFile, $username.

<#
.SYNOPSIS
Send email.
.DESCRIPTION
Send email.
.PARAMETER Attachments
Email attachments. File path to file(s) that will be attachments.
.PARAMETER Priority
Email priority. Valid values are: Normal, High, and Low.
.PARAMETER errorlog
Write to Error log or not. Switch parameter. Error log is in PSLogs Folder of My documents.
.PARAMETER client
OK - O client
BK - B client
.PARAMETER solution
FIN - Financial solution 
HR - Humane Resource solution
.EXAMPLE
Send-Email -Attachments "$home\Documents\PSlogs\Error_Log.txt" -Priority "Normal" -errorlog -client "Test" -solution "Test" -Verbose

.NOTES
FunctionName : Send-Email
Created by   : Dejan Mladenovic
Date Coded   : 09/23/2020 15:13:00
More info    : https://improvescripting.com/send-emails-using-powershell-with-many-examples/

.LINK 
Send-MailMessage
https://improvescripting.com/send-emails-using-powershell-with-many-examples/
#>
Function Send-Email {
[CmdletBinding()]
param (
    [Parameter(Mandatory=$true, 
                HelpMessage="Email attachments.")]
    [string[]]$Attachments,
    
    [Parameter(Mandatory=$false, 
                HelpMessage="Priority. Valid values are: Normal, High and Low.")]
    [ValidateSet("Normal", "High", "Low")]            
    [string]$Priority = "Normal",
        
    [Parameter( Mandatory=$false,
                HelpMessage="Write to Error log or not.")]
    [switch]$errorlog,
     
    [Parameter(Mandatory=$true,
                HelpMessage="Client OK = O client BK = B client")]
    [string]$client,
     
    [Parameter(Mandatory=$true,
                HelpMessage="Solution, for example FIN = Financial, HR = Humane resource")]
    [string]$solution
)

BEGIN {
                    
}
PROCESS { 

        try {
            Write-Verbose "Sending email..."
            
            if( $client -eq "OK" -and $solution -eq "FIN") {
                ##REPLACE THIS VALUE!!!
                $EmailFrom = "your_email"
                
                ##REPLACE THIS VALUE!!!
                $EmailTo = "your_email"
            
                $EmailSubject = "Report from Financial solution - OK client." 
                $EmailBody = "This email has as attachments error log and report file from Financial Solution - OK client." 

                ##REPLACE THIS VALUE!!!
                $SMTPserver= "your_SMTP_server"

                ##REPLACE THIS VALUE!!!
                $EncryptedPasswordFile = "$home\Documents\PSCredential\MailJet.txt"
                ##REPLACE THIS VALUE!!!
                $username="your_user_name" 
                $password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
                $credential = New-Object System.Management.Automation.PSCredential($username, $password)

                ##Change this as splatting syntax in Send-MailMessage CmdLet
                Send-MailMessage -ErrorAction Stop -from "$EmailFrom" -to "$EmailTo" -subject "$EmailSubject" -body "$EmailBody" -SmtpServer "$SMTPserver" -Attachments $Attachments -Priority $Priority -Credential $credential -Port 587
                
            } elseif ( $client -eq "Test" -and $solution -eq "Test" ) {
                
                ##REPLACE THIS VALUE!!!
                $EmailFrom = "your_email"
                
                ##REPLACE THIS VALUE!!!
                $EmailTo = "your_email"
            
                $EmailSubject = "Test of Send-Email cmdlet" 
                $EmailBody = "This is test email." 

                ##REPLACE THIS VALUE!!!
                $SMTPserver= "your_SMTP_server"

                ##REPLACE THIS VALUE!!!
                $EncryptedPasswordFile = "$home\Documents\PSCredential\MailJet.txt"
                ##REPLACE THIS VALUE!!!
                $username="your_user_name" 
                $password = Get-Content -Path $EncryptedPasswordFile | ConvertTo-SecureString
                $credential = New-Object System.Management.Automation.PSCredential($username, $password)

                ##Change this as splatting syntax in Send-MailMessage CmdLet
                Send-MailMessage -ErrorAction Stop -from "$EmailFrom" -to "$EmailTo" -subject "$EmailSubject" -body "$EmailBody" -SmtpServer "$SMTPserver" -Attachments $Attachments -Priority $Priority -Credential $credential -Port 587
                
            }
            
            Write-Verbose "Email sent."
            
        } catch {
            
            Write-Warning "There was a problem with sending email, check error log. Value of error is: $_"
            
            if ( $errorlog ) {

                $errormsg = $_.ToString()
                $exception = $_.Exception
                $stacktrace = $_.ScriptStackTrace
                $failingline = $_.InvocationInfo.Line
                $positionmsg = $_.InvocationInfo.PositionMessage
                $pscommandpath = $_.InvocationInfo.PSCommandPath
                $failinglinenumber = $_.InvocationInfo.ScriptLineNumber
                $scriptname = $_.InvocationInfo.ScriptName

                Write-Verbose "Start writing to Error log."
                Write-ErrorLog -hostname "Send Email was failing." -errormsg $errormsg -exception $exception -scriptname $scriptname -failinglinenumber $failinglinenumber -failingline $failingline -pscommandpath $pscommandpath -positionmsg $pscommandpath -stacktrace $stacktrace
                Write-Verbose "Finish writing to Error log."
            }
            
        }
}
END { 

}
}

#Send-Email -Attachments "$home\Documents\PSlogs\Error_Log.txt" -Priority "Normal" -errorlog -client "Test" -solution "Test" -Verbose

About Dejan Mladenović

Hey Everyone! I hope that this article you read today has taken you from a place of frustration to a place of joy coding! Please let me know of anything you need for Windows PowerShell in the comments below that can help you achieve your goals!
I have 18+ years of experience in IT and you can check my Microsoft credentials. Transcript ID: 750479 and Access Code: DejanMladenovic
Credentials
About Me...

My Posts | Website

Dejan Mladenović

Hey Everyone! I hope that this article you read today has taken you from a place of frustration to a place of joy coding! Please let me know of anything you need for Windows PowerShell in the comments below that can help you achieve your goals! I have 18+ years of experience in IT and you can check my Microsoft credentials. Transcript ID: 750479 and Access Code: DejanMladenovic
Credentials About Me...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Content