Email reset password in Office365 using powershell

Server Fault Asked by Kjensen on January 3, 2022

When I reset a password in the Office 365 Admin portal, I have the option to send the new password in an email, without me even seeing the password first.

enter image description here

I know I can reset the password with


Can I also trigger the password email to an email address of my choice from Powershell – like in the UI? If yes, how?

2 Answers

One tweak to Mike111b's email:

You could simply use:

$Password = Set-MsolUserPassword -UserPrincipalName <UPN>

Then use the Send-MailMessage command.

The Set-MsolUserPassword command returns the password as an output so it can be saved to a variable.

Answered by Adam Drayer on January 3, 2022

Yeah. Check out the Send-MailMessage cmdlet:

Very basic implementation:

$UserPrincipalName = Read-Host "Enter the UserPrincipalName"
$Password = Read-Host "Enter the new password"

Set-MsolUserPassword -UserPrincipalName "$UserPrincipalName" -NewPassword "$Password"

Send-MailMessage -To "$UserPrincipalName" -From "ENTER YOUR EMAIL HERE" -Subject "Password Reset" -Body "I have reset your password.  Your new password is:`n`n$Password"

The authentication against the sender field is by default authenticated against the current user. If that doesn't work for you you can use the -Credential parameter.

I would also recommend randomizing each password. Whether that be from an online tool then pasted into PowerShell or done right in PowerShell it doesn't matter but I would make it a priority.

Answered by Michael Timmerman on January 3, 2022

Add your own answers!

Related Questions

How to run clamd by systemd as daemon on Centos 7

1  Asked on November 18, 2021 by vczm


How to correctly deploy Adobe Reader 9.1

4  Asked on November 16, 2021 by ben-gillam


duplicate cache pages: Varnish

2  Asked on November 16, 2021 by sukhjinder-singh


NFS Server hangs on proxmox

1  Asked on November 16, 2021 by zarex


Azure App Service on Linux or Windows

1  Asked on November 16, 2021


Apache MPM_Prefork Setting for high performance

0  Asked on November 16, 2021 by anthonyinit


Disable TLS 1.3 on IIS

1  Asked on November 16, 2021 by user9099944


Ask a Question

Get help from others!

© 2023 All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP