We can use the Azure AD powershell cmdlet Set-MsolUser to set a user on Office 365 to Password Never Expire with the attribute -PasswordNeverExpires.
Note: Before proceed, Install and Configure Azure AD PowerShell
Use the below powershell command to set an user password to never expire:
Set-MsolUser -UserPrincipalName $userid -PasswordNeverExpires $true
You can get an Azure AD user’s PasswordNeverExpires state using below command:
Get-MSOLUser -UserPrincipalName $userid | Select UserPrincipalname, PasswordNeverExpires
Now, you can also enable password never expire flag for bulk office 365 users. You can read users from a csv file using Powershell cmdlet Import-CSV. Consider the CSV file Office365Users.csv which contains set of office 365 users with the column “UserPrincipalname“.
Import-Csv "C:\Office365Users.csv" | ForEach-Object { $upn = $_."UserPrincipalName" Set-MsolUser -UserPrincipalName $upn -PasswordNeverExpires $true }
The following command lists all the Azure AD users whose password never expire flag enabled.
Get-MSOLUser -All | Where-Object { $_.PasswordNeverExpires } | Select UserPrincipalname, PasswordNeverExpires
Advertisement