Reset Password for Multiple Office 365 Users

To reset the password for a single Office 365 user or a list of users we will need to first, connect to Office 365.

Change Password for Single Users

Run this command, to set the password for a single O365 user…

Set-MsolUserPasswordUserPrincipalName <UserPrincipalName>NewPassword <Password> -ForceChangePassword $False

NOTE: The “-ForceChangePassword” parameter with the “$True” value will force the user to change their password from the portal the next time they sign in. The “$False” value will not require it to be changed.

Change Password for Multiple Users

To set the password for a list of O365 users by from a CSV file. Remember that we need to be connected to Office 365. Let’s create a CSV file with only user names from our O365 account.

Get-MsolUser | Select UserPrincipalName | Export-Csv C:\Users.csv -NoTypeInformation

Before we move on to the next command, be sure to review the CSV file and remove the users from the list that you do not want to reset passwords for.

We will now enter a password into a variable that will be used to set for all users.

$PASS = Read-Host "Enter password"

set password variable

NOTE: The password will show in clear text in the PowerShell module as it is entered and with the following command as each user is changed.

The following command will set the password for each O365 user listed in the CSV file we create previously, and require the user to change their password at next login.

Import-Csv "C:\Users.csv" | % { Set-MsolUserPassword -userPrincipalName "$_.UserPrincipalName" -NewPassword "$PASS" -ForceChangePassword $True }

If the CSV has a column preset with passwords, we will use this command, provided the column header is titled “Password”…

Import-Csv "C:\Users.csv" | % { Set-MsolUserPassword -userPrincipalName "$_.UserPrincipalName" -NewPassword "$_.Password" -ForceChangePassword $True }

For more information regarding managing O365 passwords, check out this awesome write up.

Related Article(s):


4 thoughts on “Reset Password for Multiple Office 365 Users

  1. If you want to set a specific password for all users within the .csv then the password variable should be set as $PASS = ‘your password goes here’

    Note the single quotation marks around the password.

    • Actually, there are a few ways this can be done.

      If we do it based on the example you provide, the password will be set to “your password goes here“. It doesn’t matter if it is encapsulated in single quotes or double quotes; however if there are no quotes, the command will receive an error because it doesn’t recognize the cmdlet.

      If we set a password based on the previous example provided in this article “$PASS = Read-Host“, then the console will wait for a password to be typed at the console. In this example I provide, it will do nothing to prompt the user. Therefore, I have updated the example in the article to prompt the user to enter a password so it appears to be interactive…

      $PASS = Read-Host “Enter password”

      If we want to preset passwords in a CSV file, and eliminate setting the password in clear text at the console, then we will use this command (provided the CSV has a column with a title of “Password” somewhere in it. Quotes are not necessary but, in my opinion, they do help us to read the command a bit more clearly between command, parameter and value.

      Import-Csv “C:\Users.csv” | % { Set-MsolUserPassword -userPrincipalName “$_.UserPrincipalName” -NewPassword “$_.Password” -ForceChangePassword $True }

  2. This simpler than this even you can just run this command:

    Get-MsolUser | Set-MsolUserPassword -NewPassword ‘password’ -ForceChangePassword $True

    The difference being this will hit every single user, but that is what I was searching for when I stumbled upon this site.

    Good Luck!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s