This example uses an App Registration. As well as the correct API permissions, you will need to ensure your app is a User administrator
If you don’t have the correct permissions, you will see an error about insufficient privileges to complete the operation
Run the below PowerShell Mg-Graph cmdlet.
Password profile is an array.
#Get the User Object
$User = (Get-MgUser -Userid "blah@blah.com")
# Disable User Account
Update-MgUser -UserId $User.Id -AccountEnabled:$false
# Password Reset
# Create a strong password
$Password = $(1..2 | % { [char[]]"ABCDEFGHJKMNPQRSTUVWXYZ" | Get-Random }) -join ""
$Password += $(1..2 | % { [char[]]"abcdefghkmnopqrstuvwxyz" | Get-Random }) -join ""
$Password += $(1..2 | % { [char[]]"0123456789" | Get-Random }) -join ""
$Password += $(1..2 | % { [char[]]"!@#$%" | Get-Random }) -join ""
# password profile
$PasswordProfile = @{
Password = $Password
}
# reset password command
Update-MgUser -UserId $User.Id -PasswordProfile $PasswordProfile