How to change user passwords in bulk - without force to change

Aran Billen 941 Reputation points
2023-10-24T16:13:49.5566667+00:00

Hello everyone,

 

I'm in the process of updating the passwords for multiple users, and I'd like to set specific passwords of my choice. Additionally, I want to ensure that these accounts won't prompt users to change their passwords upon their first login.

 

I'd greatly appreciate your assistance, as the scripts I previously used are no longer effective.

Microsoft 365 and Office Install, redeem, activate For business Windows
Windows for business Windows Server User experience PowerShell
Microsoft Security Microsoft Entra Microsoft Entra ID
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2023-10-24T17:27:20.6266667+00:00

    Hi @Aran Billen ,

    if your csv looks like this (for example Sample7users.csv):

    upn,pw
    ******@test.net,ThisIsTheNewPassword12345?
    ******@test.net,ThisIsTheNewPassword7890?
    

    this PowerShell script should work (tested):

    Import-Csv ".\Sample7users.csv" -Delimiter "," -Encoding UTF8 | ForEach-Object {
            $user = Get-AzureADUser -Filter "userPrincipalName eq '$($_.upn)'"
            $secureString = ConvertTo-SecureString ($_.pw) -AsPlainText -Force
            Set-AzureADUserPassword -ObjectId $user.ObjectID -Password $secureString -ForceChangePasswordNextLogin $false
        }
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2023-10-24T16:54:55.84+00:00

    Hi @Aran Billen ,

    maybe this PowerShell script helps to get started (not tested by myself!):

    $upns = "******@test.net", "******@test.net"
    $password = 'ThisIsTheNewPassword12345?'
    ForEach-Object ($upn in $upns)
        {
            $user = Get-AzureADUser -Filter "userPrincipalName eq '$upn'"
            Set-AzureADUserPassword -ObjectId $userObjectId -Password $password -ForceChangePasswordNextLogin $false
        }
    
    

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards

    Andreas Baumgarten


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.