The PowerShell scripts given below can be used for Office 365 password policy management. ADSelfService Plus, the Active Directory self-service password management and single sign-on solution, provides advanced password policy settings that could be applied for both on-premises and cloud applications including Office 365, G Suite, etc. By integrating Active Directory with Office 365, ADSelfService Plus helps IT admins apply one custom password policy for users Office 365 and Windows Azure AD cloud accounts.
The following is a comparison between password policy management in Office 365 with Windows PowerShell and ADSelfService Plus:
Using PowerShell, only the maximum password age can be modified. Other password policy settings cannot be managed using PowerShell.
Set-MsolPasswordPolicy -DomainName <Domain Name> –ValidityPeriod <Number Of Days>Set-msoluser –UserPrincipalName <UserPrincipalName> -PasswordNeverExpires $True
Log in to your Microsoft 365 tenant using the script below. This prompts for credentials to authenticate.
Connect-MsolServiceRetrieve the existing settings using the script below. This displays the current policy for yourdomain.com.
Get-MsolPasswordPolicy -DomainName "yourdomain.com"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 14Ensure users follow stronger passwords. The script below requires user@yourdomain.com to use a complex password.
Set-MsolUser -UserPrincipalName "user@yourdomain.com" -StrongPasswordRequired $trueCheck the current Office 365 password policy by running the script below.
Get-MsolPasswordPolicy -DomainName yourdomain.comSet 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 60Yes, you can disable password expiration using the script below.
Set-MsolUser -UserPrincipalName user@domain.com -PasswordNeverExpires $true