Hi Paul Nwanochiri,
Thanks for reaching out.
Update-MgUser is a graph command and based upon the link you have attached is meant for cloud users only, could you please check if the user is cloud user only. if not, you can use permissions Directory.ReadWrite.All, User.ReadWrite.All (application)
In case nothing works, maybe you can also give a try to use the following permission.
Import-Module Microsoft.Graph.Users
Connect-MgGraph -Scopes "Directory.AccessAsUser.All"
Be Careful with this permission, this will allow you to do anything a signed in user can do.
For bulk update using csv, you can write down a script similar to something below by updating the $params object for your use case.
# Install the required modules - if not already installed
#Install-Module -Name Microsoft.Graph
Import-Module Microsoft.Graph.Users
Connect-MgGraph -Scopes "Directory.AccessAsUser.All"
# Import users from CSV
$csvPath = "PATH\passwordReset.csv" #Containing Username and Password
Import-Csv $csvPath | ForEach-Object {
$upn = $_."Username" + "@DOAMIN.org.uk"
$params = @{
passwordProfile = @{
forceChangePasswordNextSignIn = $true
password = $_."Password"
}
accountEnabled = $true
}
try {
Update-MgUser -UserId $upn -BodyParameter $params
Write-Host "Azure Password has been reset for: $upn"
} catch {
Write-Host "Failed to reset password for: $upn"
Write-Host $_.Exception.Message
}
}
For specific details about how to update a specific property you can refer to the following link https://learn.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=powershell#request
Refer to the below screenshot for your specific properties update on the same link.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".