Changing user password in Azure AD with MgGraph

Bombbe 1,441 Reputation points
2023-10-25T07:20:02.8966667+00:00

Hello,

I'm creating script that get finds wanted service accounts in Azure AD and then changes their password. To find wanted account I'm using following line which works fine

$accounts = Get-MgUser -ConsistencyLevel eventual -Count userCount -Search 'DisplayName:SVC_Acc'


Then I would go to Foreach loop and change all theirs passwords

foreach($account in $accounts) {
$name = $account.DisplayName 
$id = $account.Id  
Write-Output "Account In Azure AD: $name. Changing the password now..."

}

I have now hard time finding the right command in MgGraph which can change users passwords. All I can find is the old AzureAD module which I would not want to use. So are there MgGraph cmdlet for changing user passwords?

#Set-AzureADUserPassword -ObjectId  "$id" -Password $password
Windows for business | Windows Server | User experience | PowerShell
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph
0 comments No comments
{count} votes

Accepted answer
  1. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2023-10-25T17:01:39.9733333+00:00

    If that doesnt work, then I would use:

    https://learn.microsoft.com/en-us/graph/api/user-update?view=graph-rest-1.0&tabs=powershell#example-3-update-the-passwordprofile-of-a-user-to-reset-their-password

    Import-Module Microsoft.Graph.Users
    
    $params = @{
    	passwordProfile = @{
    		forceChangePasswordNextSignIn = $false
    		password = "xWwvJ]6NMw+bWH-d"
    	}
    }
    
    Update-MgUser -UserId $userId -BodyParameter $params
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Andy David - MVP 157.8K Reputation points MVP Volunteer Moderator
    2023-10-25T11:38:22.6566667+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.