Sending an Powershell script Output via email

Le'Trell Davis 21 Reputation points
2022-12-15T18:54:38.82+00:00

How can I add to the script below to send the Output via email ?

$Users = Get-MsolUser -All | Where-Object { $.isLicensed -eq "TRUE" } | Where {$.BlockCredential -eq $True} | Select-Object UserPrincipalName, DisplayName, Department

> $GroupMembers = Get-ADGroupMember -Identity "Jpeople" | Get-ADUser
> $Users | Where-Object { $_.UserPrincipalName -notin $GroupMembers.UserPrincipalName}

Windows for business | Windows Server | User experience | PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Andreas Baumgarten 124.1K Reputation points MVP Volunteer Moderator
    2022-12-15T19:03:43.48+00:00

    Hi @Le'Trell Davis ,

    this should be possible using the Send-MailMessage cmdlet:
    https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/send-mailmessage?view=powershell-5.1

    ----------

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

    Regards
    Andreas Baumgarten

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.