Using PowerShell to change Office 365 password policy

Step 1: Connect to Microsoft 365 PowerShell

Log in to your Microsoft 365 tenant using the script below. This prompts for credentials to authenticate.

Connect-MsolService

Step 2: View the current password policy

Retrieve the existing settings using the script below. This displays the current policy for yourdomain.com.

Get-MsolPasswordPolicy -DomainName "yourdomain.com"

Step 3: Modify password expiration settings

Update expiration policy. The script below sets passwords to expire every 90 days and sends an expiration warning at 14 days before expiry.

Set-MsolPasswordPolicy -DomainName "yourdomain.com" -ValidityPeriod 90 -NotificationDays 14

Step 4: Enforce stronger password rules

Ensure users follow stronger passwords. The script below requires user@yourdomain.com to use a complex password.

Set-MsolUser -UserPrincipalName "user@yourdomain.com" -StrongPasswordRequired $true

FAQs

1. How can I check the current Office 365 password policy?

Check the current Office 365 password policy by running the script below.

Get-MsolPasswordPolicy -DomainName yourdomain.com

2. How do I set a new password expiration policy?

Set a new password expiration policy by running the script below. This sets passwords to expire in 60 days with a 10-day reminder.

Set-MsolPasswordPolicy -DomainName yourdomain.com -NotificationDays 10 -ValidityPeriod 60

3. Can I disable password expiration in Office 365?

Yes, you can disable password expiration using the script below.

Set-MsolUser -UserPrincipalName user@domain.com -PasswordNeverExpires $true
 
  • Step 1: Connect to Microsoft 365 PowerShell
  • Step 2: View the current password policy
  • Step 3: Modify password expiration settings
  • Step 4: Enforce stronger password rules
  • FAQs

ADSelfService Plus trusted by

A single pane of glass for complete self service password management
Email Download Link