Manage passwords with PowerShell
This article applies to both Microsoft 365 Enterprise and Office 365 Enterprise.
You can use PowerShell for Microsoft 365 as an alternative to the Microsoft 365 admin center to manage passwords in Microsoft 365.
When a command block in this article requires that you specify variable values, use these steps.
- Copy the command block to the clipboard and paste it into Notepad or the PowerShell Integrated Script Environment (ISE).
- Fill in the variable values and remove the "<" and ">" characters.
- Run the commands in the PowerShell window or the PowerShell ISE.
Use the Azure Active Directory PowerShell for Graph module
First, connect to your Microsoft 365 tenant.
Set a password
Use these commands to specify a password for a user account.
$userUPN="<user account sign in name, such as belindan@contoso.com>"
$newPassword="<new password>"
$secPassword = ConvertTo-SecureString $newPassword -AsPlainText -Force
Set-AzureADUserPassword -ObjectId $userUPN -Password $secPassword
Force a user to change their password
Use these commands to set a password and force a user to change their new password.
$userUPN="<user account sign in name, such as belindan@contoso.com>"
$newPassword="<new password>"
$secPassword = ConvertTo-SecureString $newPassword -AsPlainText -Force
Set-AzureADUserPassword -ObjectId $userUPN -Password $secPassword -EnforceChangePasswordPolicy $true
Use these commands to set a password and force a user to change their new password the next time they sign in.
$userUPN="<user account sign in name, such as belindan@contoso.com>"
$newPassword="<new password>"
$secPassword = ConvertTo-SecureString $newPassword -AsPlainText -Force
Set-AzureADUserPassword -ObjectId $userUPN -Password $secPassword -ForceChangePasswordNextLogin $true
Use the Microsoft Azure Active Directory module for Windows PowerShell
First, connect to your Microsoft 365 tenant.
Set a password
Use these commands to specify a password for a user account.
$userUPN="<user account sign in name>"
$newPassword="<new password>"
Set-MsolUserPassword -UserPrincipalName $userUPN -NewPassword $newPassword
Force a user to change their password
Use these commands to force a user to change their password.
$userUPN="<user account sign in name>"
Set-MsolUserPassword -UserPrincipalName $userUPN -ForceChangePassword $true
See also
Manage Microsoft 365 user accounts, licenses, and groups with PowerShell
Feedback
Submit and view feedback for