# Import the Microsoft Graph module
Import-Module Microsoft.Graph
# Connect to Microsoft Graph with the necessary permissions (User.ReadWrite.All or Directory.AccessAsUser.All)
Connect-MgGraph -Scopes "User.ReadWrite.All"
# Specify the user's UPN (User Principal Name)
$userUPN = "[email protected]"
# Retrieve the user ID for the UPN
$user = Get-MgUser -UserId $userUPN
# Force the user to change their password at next sign-in by updating the PasswordProfile
Update-MgUser -UserId $user.Id -PasswordProfile @{ ForceChangePasswordNextSignIn = $true }
Write-Output "Password change enforced for $userUPN"