How to set the password to never expire for all the users on office365

There could be a requirement when you want to set the users password to never expire on office365. The setting for In-cloud accounts is controlled using Set-msoluser command. Please make sure before you set the password for the users to never expire, all users are enabled for Two Factor Authentication (2FA). You can create a conditional access (CA) policy which requires 2FA when anyone access the Cloud resources which will protect the user accounts.

First you should check PasswordNeverExpires attribute for the users before you make any changes to it. Also, you will need to connect to connect-msolservice using Global Administrator account or the account which has the rights to manage the users on office365.

MSonline Powershell Module must be imported before you can use connect-msolservice command and update the passwordneverexpires attribute.

Download the PS Module from: https://www.powershellgallery.com/packages/MSOnline/1.1.166.0

Once you have all the pre-requisites installed on the machine and have an admin account to make the changes. Follow below steps / commands to set the attribute.

  • Launch Powershell on your machine.
  • Import the MSonline powershell module using import-module msonline
  • Use the command Connect-msolservice to connect to the Office365.
  • Get the existing value of the attribute using below command:
get-msoluser | select Userprincipalname, PasswordNeverExpires
  • Set the PasswordNeverExpires Value for all the users to $true
get-msoluser | Set-MsolUser -PasswordNeverExpires $true
0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments