Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 8 – Exploring CMDLET – Revoke-MgUserSignInSession

Hi All,
Greetings for the day!!!
Today exploring one more GRAPH PowerShell CMDLET- Revoke-MgUserSignInSession.
Details:
- Module:Microsoft.Graph.Users.Actions
- This PowerShell CMDLETs invalidates all the refresh tokens issued to applications for a user.
- It also invalidates session cookies in a user’s browser.
- Refresh tokens are invalidated by resetting the signInSessionsValidFromDateTime user property to the current date-time.
- This operation prevents access to the organization’s data through applications on the device.
- It requires the user to sign in again to all applications that they have previously consented to. This requirement is independent of the device.
Use Case:
- This PowerShell used mostly when user lost his/her device or device is stolen
Syntax
Revoke-MgUserSignInSession
-UserId <String>
[-ResponseHeadersVariable <String>]
[-Headers <IDictionary>]
[-ProgressAction <ActionPreference>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Revoke-MgUserSignInSession
-InputObject <IUsersActionsIdentity>
[-ResponseHeadersVariable <String>]
[-Headers <IDictionary>]
[-ProgressAction <ActionPreference>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Permissions needed to execute this CMDLET
| Permission type | Least privileged permissions | Higher privileged permissions |
|---|---|---|
| Delegated (work or school account) | User.RevokeSessions.All | Directory.ReadWrite.All, User.ReadWrite.All |
| Delegated (personal Microsoft account) | Not supported. | Not supported. |
| Application | User.RevokeSessions.All | Not available. |
Demo / Example
- Lets execute this CMDLET
- To execute this CMDLET we need to connect to Microsoft Graph API using CMDLET – Connect-MgGraph
We have detailed article on Connect-MgGraph CMDLET – Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 2 – exploring Connect-MgGraph with couple of scenarios
- Open the Microsoft PowerShell ISE
- Import the module – “Microsoft.Graph.Users.Actions”
Import-Module Microsoft.Graph.Users.Actions
- Connect to Microsoft Graph using – Connect-MgGraph
- As “Revoke-MgUserSignInSession” requires “User.RevokeSessions.All” permissions, while connecting to Microsoft Graph use the value to scope attribute to “User.RevokeSessions.All“
Connect-MgGraph -Scopes "User.RevokeSessions.All"
- As we successfully connected to “Microsoft Graph“, we are ready to execute “Revoke-MgUserSignInSession” CMDLET
# A UPN can also be used as -UserId.
Revoke-MgUserSignInSession -UserId prasham@knowledgejunction1.onmicrosoft.com -Confirm
- This PowerShell CMDLET returns “True” or “False”.
Complete PowerShell
Import-Module Microsoft.Graph.Users.Actions
Connect-MgGraph -Scopes "User.RevokeSessions.All"
# A UPN can also be used as -UserId.
Revoke-MgUserSignInSession -UserId prasham@knowledgejunction1.onmicrosoft.com -Confirm

- As “Revoke-MgUserSignInSession” CMDLET executed successfully, next time when we login to any service of Microsoft 365 / Azure, we will get an prompt for authentication (password)
REFERENCES:
- Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 1 – starting with Microsoft Graph PowerShell – https://knowledge-junction.in/2023/08/30/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-1/
- Microsoft 365 : PowerShell – Microsoft Graph PowerShell tutorial – Part 2 – exploring Connect-MgGraph with couple of scenarios – https://knowledge-junction.in/2024/01/18/microsoft-365-powershell-microsoft-graph-powershell-tutorial-part-2-exploring-connect-mggraph-with-couple-of-scenarios/
- Microsoft Entra – registering new application and assigning permissions to access Microsoft Graph APIs – https://knowledge-junction.in/2024/01/18/microsoft-entra-registering-new-application-and-assigning-permissions-to-access-microsoft-graph-apis/
Thanks for reading ! Stay tuned for more articles on Microsoft Graph PowerShell and PowerShell !
HAPPY LEARNING 🙂 LIFE IS BEAUTIFUL 🙂

1 Response
[…] This cmdlet has been deprecated and replaced by Microsoft graph cmdlet ‘Revoke-MgUserSignInSession’ as described in: Revoke-MgUserSignInSession […]