Disable password expiration on Office 365



By default passwords do expire after a certain amount of days on Office 365. This can be disabled via PowerShell only.

required steps

First of all you’ll need to download and install Microsoft Online Services Sign-In Assistant and the Windows Azure Active Directory Module. Then establish a connection to Office 365 servers. For details see commands below.

After entering $cred=get-credential you’ll be prompted for administrator credentials.


First connect to Office 365. To do that open PowerShell and paste the following code.

# Setting the execution policy to RemoteSigned. This will allow us to run scripts later
Set-ExecutionPolicy RemoteSigned
# Connecting to O365
Import-Module MSOnline
Connect-MSOLService -credential $cred

Now that we are connected we can check the password expiration policy for all users.

Get-MSOLUser | Sort-Object DisplayName | Format-Table -Property DisplayName, UserPrincipalName, PasswordNeverExpires -AutoSize

# This will result in something similar

DisplayName       UserPrincipalName           PasswordNeverExpires
-----------       -----------------           --------------------
Andy Monday       andy@onmicrosoft.com                    False
Chris Tuesday     chris@onmicrosoft.com                   False
Frans Wednesday   frans@onmicrosoft.com                   False
Graham Thursday   graham@onmicrosoft.com                  False
James Friday      james@onmicrosoft.com                   False
Joe Saturday      joe@onmicrosoft.com                     False
John Sunday       John@onmicrosoft.com                    False
Julian Monday     julian@onmicrosoft.com                  False
Katia Tuesday     katia@onmicrosoft.com                   False
Keith Wednesday   keith@onmicrosoft.com                   False
Kim Thursday      kim@onmicrosoft.com                     False
Lara Friday       lara@onmicrosoft.com                    False
Matt Saturday     matt@onmicrosoft.com                    False
Nigel Sunday      nigel@onmicrosoft.com                   False
Phil Monday       phil@onmicrosoft.com                    False
Richard Tuesday   richard@onmicrosoft.com                 False
Roger Wednesday   roger@onmicrosoft.com                   False
Simon Thursday    simon@onmicrosoft.com                   False
Steve Friday      steve@onmicrosoft.com                   False

From here you can see that passwords do expire. To check the password policy for the domain you could run the following command.

# Checking password policy for our domain
Get-MsolPasswordPolicy -DomainName onmicrosoft.com | fl

ExtensionData    : System.Runtime.Serialization.ExtensionDataObject
NotificationDays : 14
ValidityPeriod   : 730

You can edit the Validity Period and the Notification Days but you cannot turn it off so the best bet is to disable expiration.

# Setting password never to expire for all users
Get-MSOLUser | Set-MsolUser -PasswordNeverExpires $true


Now lets verify if the command worked.

Get-MSOLUser | Sort-Object DisplayName | Format-Table -Property DisplayName, UserPrincipalName, PasswordNeverExpires -AutoSize

DisplayName       UserPrincipalName           PasswordNeverExpires
-----------       -----------------           --------------------
Andy Monday       andy@onmicrosoft.com                    True
Chris Tuesday     chris@onmicrosoft.com                   True
Frans Wednesday   frans@onmicrosoft.com                   True
Graham Thursday   graham@onmicrosoft.com                  True
James Friday      james@onmicrosoft.com                   True
Joe Saturday      joe@onmicrosoft.com                     True
John Sunday       John@onmicrosoft.com                    True
Julian Monday     julian@onmicrosoft.com                  True
Katia Tuesday     katia@onmicrosoft.com                   True
Keith Wednesday   keith@onmicrosoft.com                   True
Kim Thursday      kim@onmicrosoft.com                     True
Lara Friday       lara@onmicrosoft.com                    True
Matt Saturday     matt@onmicrosoft.com                    True
Nigel Sunday      nigel@onmicrosoft.com                   True
Phil Monday       phil@onmicrosoft.com                    True
Richard Tuesday   richard@onmicrosoft.com                 True
Roger Wednesday   roger@onmicrosoft.com                   True
Simon Thursday    simon@onmicrosoft.com                   True
Steve Friday      steve@onmicrosoft.com                   True

Sisko Warrior

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.