Safely and Efficiently Sending New Accounts and Passwords to Multiple Users via Email

For an ongoing project I had the requirement to send information about new accounts and passwords to the users in an organization. Luckily some people on the customer’s side (namely Paul Derbyshire and Lewis Davey) had experienced a similar situation before and they had a script that I was able to customize, to create a solution based on and the PowerShell module PwPoSh .

The solution allows to send to the users their login information and a link to to retrieve their password (removing the risk of sending passwords in an email).

The final result will be an email looking like the one in the picture:

When the user opens the password link, they will have the following screen offering them to copy their password

Note: I had also to configure Exchange Online to allow SMTP AUTH (to fix the 550 5.7.520 Access denied error).

You can create your own script based on the following one (we had also MFA enrolment and we provided support via a Teams channel):

Install-Module -Name PwPoSh
Import-Module -Name PwPoSh

$sendermailaddress = "Sender Email Address"
$senderpassword = "Sender Password"
$SecurePWD = ConvertTo-SecureString -Force -AsPlainText $senderpassword
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $sendermailaddress, $SecurePWD

$CompanyName = "Name of your company"

##Launch File Browser
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{Filter = 'CSV Files (*.CSV)|*.CSV'}
$null = $FileBrowser.ShowDialog()

##Get data from selected file and cache in var
$UserAccCSV = $FileBrowser.FileName
$UserAccounts = Import-Csv $UserAccCSV

#foreach ( $user in $UserAccounts )
#$user.pwpush = Publish-Password $user.password

foreach ( $user in $UserAccounts )
    $FirstName = $    
    $EmailAddress = $
    $UserPassword = Publish-Password $user.password
    $Recipient = $user.recipient    

$Content = @'
<!DOCTYPE html>
  <meta charset="UTF-8">
    /* Font Definitions */
    @font-face {
      font-family: "Cambria Math";
      panose-1: 2 4 5 3 5 4 6 3 2 4;
    @font-face {
      font-family: Calibri;
      panose-1: 2 15 5 2 2 2 4 3 2 4;
    @font-face {
      font-family: Tahoma;
      panose-1: 2 11 6 4 3 5 4 4 2 4;
    /* Style Definitions */
    body {
      margin: 0;
      font-family: "Calibri", sans-serif;
      font-size: 11pt;
      line-height: 1.5;
      color: #000;
    a:link, a:visited {
      color: #0563C1;
      text-decoration: underline;
    /* Additional Styles */
    .message {
      margin: 20px 0;
    .message strong {
      font-weight: bold;
  <p>Hi $FirstName,</p>
  <div class="message">
    <p>We have created your $CompanyName account.</p>
    <p>E-mail Address: <a href="mailto:$EmailAddress">$EmailAddress</a></p>
    <p>E-mail Password: $UserPassword</p>
  <div class="message">
    <p>On first sign-in, you will need to set up MFA using an authenticator app or mobile phone. As soon as you have logged in, please immediately change your password.</p>
  <div class="message">
    <p>Do not reply to this email as the mailbox is not monitored. If you have any queries, please direct them to:</p>
      <li>Email for the M365 Migration teams’ channel <a href="mailto:[email protected]">[email protected]</a></li>
      <li>Or post a message in Teams in "M365 Migration"</li>
$CWCN = $Content.Replace('$CompanyName', $CompanyName)
$CWCNAFN = $CWCN.Replace('$FirstName', $FirstName)
$CWCNAFNAEM = $CWCNAFN.Replace('$EmailAddress', $EmailAddress)
$CWCNAFNAEMAP = $CWCNAFNAEM.Replace('$UserPassword', $UserPassword)

Send-MailMessage -SmtpServer '' -UseSsl -Credential $Credentials -Subject "$CompanyName account - log in details" -To $Recipient -From $sendermailaddress -Port 587 -BodyAsHtml $CWCNAFNAEMAP

The .csv file has to contain the following fields: password,name,recipient,email (see the image below for more details)