Change User Password in Bulk Force

Modified on Tue, 30 Jun at 3:32 PM

# Connect to Microsoft Graph PowerShell module

# Connect-MgGraph -Scopes "User.ReadWrite.All"


# Path to your CSV file

$csvPath = "C:\temp\changepass.csv" # Replace with the actual path


# Import the CSV and process each row

Import-Csv -Path $csvPath | ForEach-Object {

    $upn = $_.UserPrincipalName

    $newPassword = $_.NewPassword

    $forceChange = $_.ForceChangePassword


    # Set the password for the user

    Set-MgUserPassword -UserId $upn -PasswordProfile (New-Object -TypeName Microsoft.Open.MSGraph.Model.PasswordProfile -ArgumentList @($newPassword, $forceChange))


    Write-Host "Password updated for user: $upn"

}

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