This site uses cookies. By continuing you accept the use of cookies.I Accept

A common issue with Office 365 is the password policy that forces a password expiration every 90 days. So I wrote a PowerShell script that updates the entire organization with a Password Never Expires flag. However, the script must be executed everytime a new user is added to the organization, since it only applies the new rules for existing users.

First of all, you must install the Office 365 cmdlets from here:

Fire up PowerShell and execute the following:

$oUsername = ""
$oPassword = "administrator-password"

$password = ConvertTo-SecureString $oPassword -AsPlainText –Force
$credential = New-Object System.Management.Automation.PsCredential($oUsername,$password)
$cred = Get-Credential -cred $credential

Import-Module MSOnline

Connect-Msolservice -cred $cred

Get-MSOLUser | Set-MsolUser -PasswordNeverExpires $true
Get-MSOLUser | Select UserPrincipalName,PasswordNeverExpires


The script will connect to Office 365 and fetch all existing users and apply the new rules to them. Then it will display a list of all users with the value of PasswordNeverExpires.