Hi @Filippo Iacobellis, Thanks for reaching out.
To get list of all users and their current password expiration policy activation status, run the below command:
Get-MgUser -All |Select-Object PasswordPolicies
To Set Password Never Expire for All Users, run below code:
Get-MgUser -All | foreach {
$Id=$_.Id
$DisplayName=$_.DisplayName
Write-Progress "Set password never expires to $DisplayName"
Update-MgUser –UserId $Id -PasswordPolicies DisablePasswordExpiration
}
To Set Password Never Expire for set of Users, run below code:
$UserId = Import-Csv "xxx.csv" | ForEach-Object { $upn = $_."UserId"
Write-Progress -Activity "Setting password to never expire to -$upn"
Update-MgUser -UserId $upn -PasswordPolicies DisablePasswordExpiration
}
Note: xxx.csv is the location of csv file contains the ID of required users.
I have tested the commands and below the screen shot for reference.
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.