Forum Discussion

talobau's avatar
talobau
Copper Contributor
Jul 08, 2024
Solved

Can't change PasswordExpirationPolicy of all users with Update-MgUser

Hello,

 

Ive got into a problem where we disabled Password expiration in the GUI but some account keep having it enabled when you look with Powershell. Microsoft provides a guide where they explain hot to set all users policy to never expire, sadly it doesn't work, I've tried it in several Tenants already.

 

Here is the link to the guide:

https://learn.microsoft.com/en-us/microsoft-365/admin/add-users/set-password-to-never-expire?view=o365-worldwide

 

The command:

Get-MGuser -All | Update-MgUser -PasswordPolicies DisablePasswordExpiration

 

The error when the command is used:

Update-MgUser_UpdateViaIdentityExpanded: The pipeline has been stopped.

Exception: InputObject has null value for InputObject.UserId

 

I know that you should set a UserID as a scope for it to work, but this isn't possible as far as I know on update-mguser. Please help me find a solution to update everyone's PasswordExpirationPolicy to never expire.

 

I was thinking about creating a script that goes through every userid and performs the action, but my knowledge isn't as advanced to create it.

  • I found the solution for it

    first you download a CSV file of every User in your tenant.

    Get-MGuser -All -Property UserPrincipalName | 
    Select-Object UserprincipalName | 
    ConvertTo-Csv -NoTypeInformation | 
    Out-File /Users/username/Downloads/UPN.csv

    after you have that file you use it to scope all users in your tenant and apply the change

    Import-Csv “/Users/username/Downloads/UPN.csv” | ForEach-Object{
    $UserPrincipalName = $_.UserPrincipalName
    Update-MgUser -UserId $UserPrincipalName -PasswordPolicies DisablePasswordExpiration }

     

1 Reply

  • talobau's avatar
    talobau
    Copper Contributor

    I found the solution for it

    first you download a CSV file of every User in your tenant.

    Get-MGuser -All -Property UserPrincipalName | 
    Select-Object UserprincipalName | 
    ConvertTo-Csv -NoTypeInformation | 
    Out-File /Users/username/Downloads/UPN.csv

    after you have that file you use it to scope all users in your tenant and apply the change

    Import-Csv “/Users/username/Downloads/UPN.csv” | ForEach-Object{
    $UserPrincipalName = $_.UserPrincipalName
    Update-MgUser -UserId $UserPrincipalName -PasswordPolicies DisablePasswordExpiration }

     

Resources