Recently after looking at “Risky Users” in our Office 365 tenant, I found many users that could use a password reset. I wanted to make sure these users would receive a temp password via cell phone.
This function will take a filter param company and reset each user and text them a password given they have ATT, T-Mobile, or Verizon.
# First connect to your tenant connect-msoluser Function Reset-PassandText {param ($user,$smtpemail,$creds) $textnumber = ((Get-MsolUser -UserPrincipalName $user | select MobilePhone).PhoneNumber).Replace("-","") $password = Set-MsolUserPassword -ForceChangePassword $true -UserPrincipalName $user Send-MailMessage -Body "$password" -To $textnumber@vtext.com -SmtpServer smtp.office365.com -Credential $creds -From $smtpemail -Subject "Temp Password" -Port 587 -UseSsl } # Enter SMTP Server Creds (make sure this user can send or SMTP authenticate $smtpcredentials = get-credentials # Run the Function Reset-PassandText -User email@mydomain.com -smtpemail passwordreset@mydomain.com -Creds $smtpcredentials