Learning and Sharing
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
  • Home
  • Blog
  • Linux
  • macOS
  • Virtualization
    • VMware
    • VirtualBox
  • Windows
    • Windows 11
    • Windows 10
    • Windows Server
  • Series
    • Symantec
    • Intune
    • Microsoft Azure
    • Powershell
    • VirtualBox
    • VMware
    • PowerShell Learning
    • Microsoft Graph
  • More
    • Auto Installation
    • AEC Installation
  • Contact
No Result
View All Result
No Result
View All Result

Force Password Change without Updating Existing Password in Microsoft 365

February 1, 2024
in Blog, Microsoft 365
0
ADVERTISEMENT

Table of Contents

In some cases, you want to force a password change on a Microsoft 365 users without having to reset their user password first. In the scenario, the Microsoft 365 administrator has modified the default password policy in Microsoft 365. However, without a password change, users do not yet have passwords that conform to the new policy.

Here are some examples of how to use PowerShell commands or the Microsoft Graph API to force a password change for a user.

Using the Microsoft Graph PowerShell SDK

1. Install the required Microsoft Graph PowerShell SDK module by opening PowerShell as administrator then run the following command:

Install-Module -Name Microsoft.Graph.Users -Scope CurrentUser

2. Modifying the user’s password profile requires a certain level of permissions to be granted to the Microsoft Graph Command Line Tools application. So, in this case, we need to connect to Graph PowerShell with the following scopes:

Connect-MgGraph -Scopes User.ReadWrite.All,Directory.AccessAsUser.All

3. To force a single user to change their password, you can use the Update-MgUser cmdlet with the -PasswordProfile parameter. For example:

$PasswordProfile = @{
   ForceChangePasswordNextSignIn = $true
}
Update-MgUser -userid [email protected] -PasswordProfile $PasswordProfile

As you can see in the below screenshot, the user need to update her account password in the

ymZ0Z03VYWORBnRhv6kQB1Sh1p9ReW16UHSv3OVTdql6Z9Cu2aqtpISNPwfB

Sometimes, or for compliance, a critical incident may require all users to change their passwords as soon as possible. To force all users to change their passwords via PowerShell, you will first need to store your users into an array, then loop through each user to apply the new password profile.

$users = Get-MgUser -All
$PasswordProfile = @{
  ForceChangePasswordNextSignIn = $true
}

Foreach ($user in $users) {
    Update-MgUser -UserId $user -PasswordProfile $PasswordProfile
}

In most cases, you should not run the above script against all users in your tenant. You would be better off applying the password profile to a group of users from a CSV file, excluding your admirative accounts.

adLESHNFU52e4GV4vItJyF0SIpFoWqLVYrcHLTE4ZqaacbkmeA8DKPoXeiae

The below script pulls the list of users from a CSV file. Then loop through each user to apply the new password profile.

$passwordProfile = @{
    ForceChangePasswordNextSignIn = $true
}
 
$users = Import-Csv "D:\scripts\users.csv"
$users | ForEach-Object {
    Write-Host "Updating $($_.UserPrincipalName)..." -ForegroundColor Yellow
    Update-MgUser -UserId $_.UserPrincipalName -PasswordProfile $passwordProfile
}
mLLJ34gKpof4vAfe4CjkWqK5Nsrj1lo9mbIYLofKKalj0VMJYuzUVzeVAVUU

Using the Microsoft Graph Explorer

If you don’t want to install any Microsoft Graph PowerShell module. You can use Microsoft Graph Explorer to quickly force a user to change his account password on the next login.

1. Visit Microsoft Graph Explorer at https://aks.ms/ge.

2. Consent the required permission to the Graph Explorer app to update the user information.

3. Enter the request body as follows, change the method to PATCH, change the endpoint URL to fit with yours, and then click on Run query button.

{"passwordProfile":{"forceChangePasswordNextSignIn":true}}

4. If has no error, you will see the blank output with status code 204. output

qqx3zu93ejBckf8thfY0sAYwtjRI7uPAMODPvQmV7mosfPBXS3z8OiaesEbf

Using the Microsoft Graph API

If you want to force a user to change their password on the next login using the Microsoft Graph API, you can follow these general steps:

  • Get Access Token: Obtain an access token with the necessary permissions. Your app should have the User.ReadWrite.All or similar permission to update user information.

  • Update User’s Password Profile: Use the access token to make a PATCH request to the Microsoft Graph API endpoint to update the user’s password profile. You will need to set the forceChangePasswordNextSignIn property to true.

Make sure to replace the variables with your actual values. Here’s an example using PowerShell with the Microsoft Graph API:

# Define variables
$clientId = "xxxxxxxxxxxxx-cd58-4e4d-95ac-17081063c20b"
$clientSecret = "vUm8Q~xxxxxxxxxxxxx.pRiyMuQIJ0RCfBaSa"
$tenantId = "c032627b-6715-4e39-9990-xxxxxxxxxx"
$username = "[email protected]"

# Get OAuth token
$tokenEndpoint = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
$body = @{
    client_id     = $clientId
    client_secret = $clientSecret
    grant_type    = "client_credentials"
    scope         = "https://graph.microsoft.com/.default"
}

$response = Invoke-RestMethod -Method Post -Uri $tokenEndpoint -Body $body

# Extract access token
$accessToken = $response.access_token

# Set user's password to expire immediately
$userEndpoint = "https://graph.microsoft.com/v1.0/users/$username"
$body = @{
    passwordProfile = @{
        forceChangePasswordNextSignIn = $true
    }
} | ConvertTo-Json

# Update user's password profile
$params = @{
   Method      = "Patch"
   Uri         = $userEndpoint 
   Headers     = @{Authorization = "Bearer $accessToken"} 
   Body        = $body 
   ContentType = "application/json"
}
Invoke-RestMethod @params

Conclusion

Forcing password changes without updating the existing password in Microsoft 365 could be done using Graph PowerShell SDK, Graph Explorer, or Graph API.

ADVERTISEMENT

Not a reader? Watch this related video tutorial:

5/5 - (1 vote)
Previous Post

How to Mount and Unmount ISO File in PowerShell

Next Post

Get the Last Password Change Date Using PowerShell in Microsoft 365

Related Posts

Running Hyper-V and VMware Workstation on The Same Machine

August 15, 2024

How to Uninstall All Autodesk Products At Once Silently

July 29, 2024
Ftr5

How to Uninstall the Autodesk Genuine Service on Windows

July 29, 2024
Ftr19

How to Fix Windows Cannot Read the ProductKey From the Unattend Answer File in VirtualBox

July 26, 2024
Ftr25

How to Update Windows Terminal in Windows 10/11

July 26, 2024

How to Disable The Beep Sound in WSL Terminal on Windows

July 26, 2024

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • How To Turn On uBlock Origin Extension in Chrome (2025)
  • Images Hidden Due To Mature Content Settings In CivitAI
  • Azure OpenAI vs Azure AI Hub, How to Choose the Right One for Your Needs

Categories

Stay in Touch

Discord Server

Join the Discord server with the site members for all questions and discussions.

Telegram Community

Jump in Telegram server. Ask questions and discuss everything with the site members.

Youtube Channel

Watch more videos, learning and sharing with Leo ❤❤❤. Sharing to be better.

Newsletter

Join the movement and receive our weekly Tech related newsletter. It’s Free.

General

Microsoft Windows

Microsoft Office

VMware

VirtualBox

Technology

PowerShell

Microsoft 365

Microsoft Teams

Email Servers

Copyright 2025 © All rights Reserved. Design by Leo with ❤

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory

No Result
View All Result
  • Home
  • Linux
  • Intune
  • macOS
  • VMware
  • VirtualBox
  • Powershell
  • Windows 10
  • Windows 11
  • Microsoft 365
  • Microsoft Azure
  • Microsoft Office
  • Active Directory