In a previous article, we used Windows 10 which has PowerShell 5.1 to create a new email message. Here is the link to the article:

  • https://everything-powershell.com/powershell-create-an-email-using-powershell/

In this article we will perform the same function but we will use PowerShell v7.0.3 instead. We will run with both options as per the first article. Create an email without having the email window open:

$Outlook = New-Object -comObject Outlook.Application
$TlabEmail = $Outlook.CreateItem(0)
$TlabEmail.To = “User1@thexchangelab.com”
$TlabEmail.Subject = “Draft email from PowerShell”
$TlabEmail.Body = “PowerShell makes your life easy”
$TlabEmail.save()

And now we will do the second one but this one has the Inspector section in it:

$Outlook = New-Object -comObject Outlook.Application
$TlabEmail = $Outlook.CreateItem(0)
$TlabEmail.To = “User1@thexchangelab.com”
$TlabEmail.Subject = “Draft email from PowerShell”
$TlabEmail.Body = “PowerShell makes your life easy”
$TlabEmail.save()
$inspector = $TlabEmail.GetInspector
$inspector.Display()

and here is the email draft, just like normal PowerShell:

and there you have it, PowerShell 7 doing everything that PowerShell 5.1 can do so far..

Hope it helps.


0 Comments

Leave a Reply