Is it possible to email Powershell output to certain email address?

Shamyog 1 Reputation point


I am trying to email the following PowerShell output to a certain email address. Is there a way to do that?

Search-ADAccount -AccountExpiring -TimeSpan "365" | Select-Object Name, SamAccountName, AccountExpirationDate | Sort-Object AccountExpirationDate

Thank you.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,344 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 95,021 Reputation points MVP

    Hi @Shamyog ,

    one option could be using Send-MailMessage:

    Just put the query result of your command in a variable and it's possible to use this as body of the email.


    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

    0 comments No comments