Wednesday, August 7, 2013

How to set a User's Password to Never Expire in Office 365

Many settings in Office 365 can only be access through PowerShell or through directory synchronization of your on-premises servers. Setting passwords to never expire is one of those settings. We could debate the merits of passwords that expire but let's not. Instead, let's just take a look at how to change this somewhat controversial attribute with PowerShell.

If you haven't already setup Windows PowerShell to work with Office 365, please see: How to Install and Configure PowerShell for Office 365 in Windows 8 (works for Windows 7 too).

You'll also need to connect to Office 365 with PowerShell. If you're unfamiliar with that process, we have a guide for that too...  How to Connect to Office 365 with Windows PowerShell.

Once you've completed those two prerequisites, enter the following commands at your PowerShell command prompt. I think typing the commands in by hand builds better memory, but cut and paste is just as functional. I've included a quick reference at the end of this post for those that don't need the screen shots.


You'll be prompted for an Office 365 account with administrative permissions. Enter your credentials and click OK.

Back in the PowerShell window, enter the following command to find the status of PasswordNeverExpires for a specific user.

Get-MSOLUser -UserPrincipalName <user ID> | Select PasswordNeverExpires

Where <user ID> is the Office 365 user ID of the user you wish to update.

In the example above, the user's password in not set to never expire. The following command changes the PasswordNeverExpires attribute to true.

Set-MSOLUser -UserPrincipalName <user ID> -PasswordNeverExpires $true

Now the status of the PasswordNeverExpires attribute for your user should be true. Run a Get-MSOLUser command again to verify.

Get-MSOLUser -UserPrincipalName <user ID> | Select PasswordNeverExpires

Now your user can keep using Monkey1 as their password for as long as they like.

Command Quick Reference

The following is a quick reference of PowerShell commands to show the status and change the PasswordNeverExpires attribute for an individual user or all users.

Connect to the MSOL Service


Show an Individual User's Setting

Get-MSOLUser -UserPrincipalName <user ID> | Select PasswordNeverExpires

Show All User's Settings

Get-MSOLUser -All | Select UserPrincipalName, PasswordNeverExpires

Change for an Individual User

Set-MSOLUser -UserPrincipalName <user ID> -PasswordNeverExpires $true

Change for All Users

Get-MSOLUser -All | Set-MsolUser -PasswordNeverExpires $true

Disable Never Expire for an Individual User

Set-MsolUser -UserPrincipalName <user ID> -PasswordNeverExpires $false

Disable Never Expire for All Users

Get-MSOLUser -All | Set-MsolUser -PasswordNeverExpires $false

No comments: