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

Aran Billen 661 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
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,916 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,132 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,774 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 98,531 Reputation points MVP
    2023-10-24T17:27:20.6266667+00:00

    Hi @Aran Billen ,

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

    upn,pw
    testpeter@test.net,ThisIsTheNewPassword12345?
    testpaul@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

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Andreas Baumgarten 98,531 Reputation points MVP
    2023-10-24T16:54:55.84+00:00

    Hi @Aran Billen ,

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

    $upns = "testpaul@test.net", "testpeter@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