TransWikia.com

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

Set-MsolUserPassword

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:

https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/send-mailmessage

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!

Ask a Question

Get help from others!

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