Powershell command to set the password policy

Office 365 password never expires

In the Office 365 Admin Panel, one searches in vain for a checkbox to set the password policy "Password never expires". The question whether a password should be set to "never expires" or not is security-relevant and everyone has to take responsibility themselves.

The settings must be made via PowerShell . To do this, the following tools must be installed locally on a Windows computer:

I did this on Windows 8.1, had a few problems with the versions to that extent....

The following tools finally led to success:

  • Microsoft Onlie Services Sing-In Assistant for IT Professionals Beta
  • Online Services Module for Windows PowerShell (64-bit)

The order of installation is important. Please note whether 32bit or 64 bit version. Windows 8 is always 64 bit.

The system must be rebooted at least 1x. With me it needed 2 reboots.

Start Powershell and execute the following command:

Import modules MsOnline

Then the following command:

Connect-MSOLService

A prompt for the user name and password appears. Enter here the e-mail address of a global administrator and his password.

Password never expires Change settings with command line command

To see the password never expires settings of all users execute the following command:

Get-MSOLUser | Select UserPrincipalName, PasswordNeverExpires

False = Expires, True = Never expires

If the settings are to be made globally for all users, execute the following command:

Get-MSOLUser | Set-MSOLUser -PasswordNeverExpires $true

The following command can be executed for a single user. Replace USER ALIAS:

Set-MsolUser -UserPrincipalName BENUTZERALIAS -PasswordNeverExpires $true

$false logically undo the whole thing