Bulk Password Reset

Modified on Tue, 30 Jun at 3:31 PM

# Import necessary modules



# Connect to Microsoft Graph


# Path to the CSV file containing the user IDs and new passwords

$csvFilePath = "C:\temp\changepass.csv"


# Import the CSV file

$userList = Import-Csv -Path $csvFilePath


# Loop through each user in the CSV file

foreach ($user in $userList) {

    try {

        # Reset the user's password

        Update-MgUser -UserId $user.UserId -PasswordProfile @{ Password = $user.NewPassword; ForceChangePasswordNextSignIn = $true }

        

        Write-Host "Password reset successfully for user: $($user.UserId)" -ForegroundColor Green

    } catch {

        Write-Host "Failed to reset password for user: $($user.UserId). Error: $($_.Exception.Message)" -ForegroundColor Red

    }

}


# Disconnect from Microsoft Graph


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article