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.
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?
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
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP