# 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
Feedback sent
We appreciate your effort and will try to fix the article