Manage Office 365 Users Passwords using PowerShell | Office 365 5/5 (3) 6 min read

In the current article, we will review how to use PowerShell commands for managing user password in Office 365 environment.

Office 365 user’s password management versus the “standard” Domain Active Directory is a little restricted.

For example – configure password policy parameters such as – Enforce password history, Minimum password length, Password must meet complexity requirements cannot be configured by the Office 365 administrator.

At the current time, the options that related to Office 365 users password management are – reset the user password and setting the number of a maximum number of days or password expiration (the default is 90 days).

So, what are the options that are available for Office 365 user’s password management?
In this, the article will review a couple of options. Some of the options can manage by using the Office 365 Web interface and some task only by using PowerShell.

PowerShell | Help & additional information

In case that you are a novice in the PowerShell environment, you can use the following link to get more information about the “first steps” such as: downloading the required PowerShell
software components, how to use the PowerShell console, running a PowerShell script, etc.

Read more
Link Table
PowerShell Naming Conventions & general informationIf you want to get more information about the Naming Conventions that we use for this article and get some general tips about: how to work with the PowerShell, read the article: Help and additional information – PowerShell articles
Create remote PowerShell sessionBefore we can use the required PowerShell commands, we need to download and install the Office 365 cmdlets + create remote PowerShell session to Office 365 or Exchange Online. If you need more information about how to create a remote PowerShell session read the following articles: Part 2: Connect to Office 365 by using Remote PowerShell and Part 3: Connect to Exchange Online by using Remote PowerShell
How to use a PowerShell scriptMost of the PowerShell articles include a PowerShell script that simplifies the use of the PowerShell commands. If you want to get more information about: How to use a PowerShell script, read the article: Connect to Office 365 and Exchange Online using a script
PowerShell command and Script languish in more detailsIf you are new to the PowerShell world, you can read more information about PowerShell in Office 365 environment in the article: The Power of PowerShell

1. Set Password never expired

Set Password never expired for Office 365 user

PowerShell command Syntax

PowerShell command Example

Disable Password never expired option for a Office 365 user

PowerShell command Syntax

PowerShell command Example

Set Password never expired for ALL Office 365 users (Bulk Mode)

PowerShell command Syntax

Re-enable Password expired ( the default) for ALL Office 365 users (Bulk Mode)

PowerShell command Syntax

2. Set Password

Set a Predefined Password for Office 365 user

PowerShell command Syntax

PowerShell command Example

Set a Predefined Password for all Office 365 users (Bulk mode)

PowerShell command Syntax

PowerShell command Example

Set a Predefined Password for Office 365 users imported from a CSV File

Step 1: Export Office 365 users account
PowerShell command Syntax

Step 2: Set a Predefined Password

Example: Step 1: Export Office 365 users account

Predefined Password-CSV

PowerShell command Example

Create new Office 365 user and set a unique temporary password by import the information from CSV file

temp password

You can download a sample CSV file – Password.csv

PowerShell command Example

Provisioning Office 365 user and export information from Active Directory

In case that you need to export Active Directory on-Premise user account based on a specific parameter, you can use the PowerShell cmdlets named – get-aduser (you will need to use PowerShell console from DC or import the Active Directory cmdlets to the existing PowerShell console
For example:

Example 1 – display or export, all of the Active Directory users that located in a specific OU.

In our particular scenario, the domain name is – and the specific OU is – Test

Display information about – all of the Active Directory users that located in a specific OU

PowerShell command Example

Export to a CSV file information about – all of the Active Directory users that are located in a specific OU + choose a specific data fields.

Example 2 – display + export information about Active Directory users from a specific department.

The PowerShell command syntax is:

An example to a scenario in which we want to export information only about Active Directory users that belong to the marketing department could be

Set a Temporary Password for a specific user

PowerShell command Syntax

PowerShell command Example

Set a Temporary Password for all Office 365 users (Bulk Mode)

PowerShell command Syntax

PowerShell command Example

3. Office 365 Password Policy

Set Office 365 Password Policy

PowerShell command Syntax

PowerShell command Example

4. Display Password settings

Display Password settings for all Office 365 users

PowerShell command Syntax

Display information about Office 365 Password Policy

PowerShell command Syntax

PowerShell command Example

5. Download Manage password PowerShell menu script

For your convenience, I have “Wrapped” all the PowerShell commands that were reviewed in a PowerShell Script named:
You are welcome to download the script and use

PowerShell command syntax – Office 365 | Article series index

Now it’s Your Turn!
It is important for us to know your opinion on this article

Print Friendly, PDF & Email

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

31 Responses to “Manage Office 365 Users Passwords using PowerShell | Office 365”

  1. Nice write up. Do you know if the password complexity policy can be bypassed or disabled?

  2. Hi. First of all let me thank you for the information here – it is much more informative than 90% of the MS support out there :). But, I still have a problem related to Office365:
    – I need to create around 1150 accounts for students (at the same time, bulk)
    – up to last year, I always prepared a CSV file which contained, among other records, the information for “account name”, “password” and “expiration policy”
    – every student was announced to login into the account by using the email address (published on our website) and their personal identity numbers as “one-time” passwords that had to be changed mandatory at the first login
    – now, in the administration panel of the new Office365 i can only add a bulk list of accounts and in the end I have the possibility to send to myself a message with 1150 accounts and their correspondent temporary passwords… which I have to manually distribute to each student 🙁 – a solution which seems rather stupid form my point of view (and the same thing applies to the reset password issue which now cannot be solved by the user himself but that is another story)
    – and now, for the grand finale, is their any way to create a CSV file containing 1150 accounts, each one with its different one-time password? (I have learned here how to setup passwords individually for each account and how to set the same password for all accounts but neither solution are suitable for me)
    Thanks a lot for the time and patience to read this 🙂

    • Hello Alex,
      You can solve the need for “one-time time password” or a random password by using the excel formula.
      (Most of the time you edit the CSV file by using application such as excel)
      In the “Password row” of the CSV file, you can use a formula such as:
      To create a random alphanumeric string that has two letters and two numbers, use this formula: =CHAR(RANDBETWEEN(65,90))&CHAR(RANDBETWEEN(65,90))&RANDBETWEEN(10,99)

      Additional example is: randomly generate a string of eight characters.
      You will need to copy this formal to the first cell and drag the formal until the last user.

    • Hello.
      Thnks for the reply but maybe I was not clear enough in my previous message :).
      I know how to obtain random numbers – I can actually do advanced coding in 4 or 5 different programming languages :).
      The problem was how to set a specific password for a specific user when creating a batch of 1000 accounts on Microsoft’s Office365 platform. The CSV that is delivered by MS as a template for the batch creation does not contain a filed for the password – it there was such a field I would undoubtedly be able to fill it with some password or another :).

    • Hello alex
      For your request, I have add a new sample named: Create new Office 365 user and set a unique temporary password by import the information from CSV file.
      The CSV file include filed name password that include a “random password”. After a successfully import operation, the password value in the CSV will be treated as a temporary password. When the user login to the Office 365 portal, he will need to provide the temporary password and the next step is to provide a permanent password. I hope that this is the solution that you look for :- )

    • Hi.
      Great – thanks a lot. I can’t test it right now but I’ll be back to this issue on Friday. I’ll let you know how it turned out in the end :). Thanks again and have a great day.

  3. Please tell me that youre heading to keep this up! Its so great and so important. I cant wait to read a lot more from you. I just feel like you know so substantially and know how to make people listen to what you might have to say. This blog is just too cool to become missed. Terrific stuff, genuinely. Please, PLEASE keep it up!

  4. Hello again.
    It worked like a charm 🙂 – I actually managed to build a complete set of scripts suited to my needs. I still think Microsoft did a stupid thing with management/administration part of the new Offic365 platform but, at least for the moment it works for me :(. I cannot understand how did they think to eliminate the automated mechanism for “lost password” but I keep saying sweet things to MS in my mind and wait for manual requests of lost passwords changes… and for a whole lot of more than 25000 users (out of witch of course there are plenty to forget the password) you can think about the time I spend thinking about MS :))).
    Anyway, thanks again to Eyal – great job.

  5. I really like what you guys tend to be up too. This sort of clever work and exposure!
    Keep up the terrific works guys I’ve you guys to blogroll.

  6. Really liked the way you have set all this out…, easy to understand and easy to follow…
    I’m a newbee at Office 365, and I’m just about to do a bulk setup of 99 mailboxes, and I can’t quite find what I’m looking for..
    I want to use a CSV file to setup the accounts, and I think I’m okay with that, but I already have a complete list of the users passwords and I want to set the new accounts up with these passwords, I don’t want it to force the user to change when they login, I just want the account to be setup and ready to use, but I do want the password to be set to never expire..
    Could you give me some advice as to if this is possible..?

  7. I leave a comment whenever I appreciate a post on a site or I have something
    to valuable to contribute to the discussion. It’s a result of the passion displayed in the post I looked at.
    And on this article Manage Office 365 user’s Passwords using PowerShell.
    I was actually excited enough to drop a thought 😉 I do have a couple of questions
    for you if you tend not to mind. Is it only me or do a few of these comments appear like
    they are left by brain dead people? 😛 And, if you are writing at additional social sites, I would like to
    follow anything new you have to post. Could you list every
    one of your public pages like your linkedin profile, Facebook page
    or twitter feed?

  8. Hello
    I have tried with

    Get-MsolUser | Set-MsolUser –PasswordNeverExpires $True

    But the powershell shows an error that Get-MsolUser is not recognized !!

    What should i do now ?

  9. Many Thanks – This saved hours!
    but one error while I use below option:
    12) Disconnect Powershell session
    option not working Error “The command Failed :-(“

  10. This is a fantastic article – again, much more thorough and easy to understand than any MS article anywhere.

  11. keithransom Reply

    Its not my first time to pay a visit this web page, i am visiting this website dailly and take pleasant data from here every day.

  12. anuncios de coches Reply

    It’s difficult to find knowledgeable people
    in this particular subject, however, you sound like you know what you’re talking
    about! Thanks

  13. The level of information, layout and depth of knowledge you share so freely is truly amazing. It has helped me numerous times and saved hours of research.

  14. Hi Thanks alot, the information is very useful, but if you can help me in this, is there anyway to reset the last password changed date. as the problem is our passwords were not changed since more than 3 years, now i want to set a password expiration policy to 60 Days but as soon as i set it , the users gets blocked and they have to change immediately, i want to give them 15 days to change their passwords

  15. Kris Beatty Reply

    so i needed to change all the passwords to a password i randomly chose for each user, i also need to make it not ask for password change at next login. here is what i used.
    $users = Import-CSV –Path C:\Users\Admin\Import_User_Sample_en.csv | ForEach-Object { Set-MsolUserPassword -UserPrincipalName $_.UserPrincipalName -NewPassword $_.Password -ForceChangePassword:$false}
    its important to make sure the CSV has the correct column names. on this one the only need to be UserPrincipalName which is the email and the Password.
    hope that helps anyone who need to do the same.

Leave a Reply

Your email address will not be published. Required fields are marked *