Skip to content

Commit 1f6cf28

Browse files
authored
Merge pull request #228290 from omondiatieno/disable-sign-in
Disable user sign in using PowerShell and Graph API
2 parents 9112547 + 77d457f commit 1f6cf28

File tree

1 file changed

+63
-5
lines changed

1 file changed

+63
-5
lines changed

articles/active-directory/manage-apps/disable-user-sign-in-portal.md

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ ms.service: active-directory
88
ms.subservice: app-mgmt
99
ms.workload: identity
1010
ms.topic: how-to
11-
ms.date: 09/06/2022
11+
ms.date: 2/23/2023
1212
ms.author: jomondi
1313
ms.reviewer: ergreenl
1414
ms.custom: it-pro
1515
ms.collection: M365-identity-device-management
16+
zone_pivot_groups: enterprise-apps-all
17+
1618
#customer intent: As an admin, I want to disable user sign-in for an application so that no user can sign in to it in Azure Active Directory.
1719
---
1820
# Disable user sign-in for an application
@@ -28,10 +30,12 @@ In this article, you'll learn how to prevent users from signing in to an applica
2830
To disable user sign-in, you need:
2931

3032
- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
31-
- One of the following roles: Global Administrator, Cloud Application Administrator, Application Administrator, or owner of the service principal.
33+
- One of the following roles: An administrator, or owner of the service principal.
3234

3335
## Disable how a user signs in
3436

37+
:::zone pivot="portal"
38+
3539
1. Sign in to the [Azure portal](https://portal.azure.com) as the global administrator for your directory.
3640
1. Search for and select **Azure Active Directory**.
3741
1. Select **Enterprise applications**.
@@ -40,13 +44,18 @@ To disable user sign-in, you need:
4044
1. Select **No** for **Enabled for users to sign-in?**.
4145
1. Select **Save**.
4246

43-
## Use Azure AD PowerShell to disable an unlisted app
47+
:::zone-end
4448

45-
Ensure you've installed the AzureAD module (use the command Install-Module -Name AzureAD). In case you're prompted to install a NuGet module or the new Azure Active Directory V2 PowerShell module, type Y and press ENTER.
49+
:::zone pivot="aad-powershell"
4650

47-
You may know the AppId of an app that doesn't appear on the Enterprise apps list. For example, you may have deleted the app or the service principal hasn't yet been created due to the app being pre-authorized by Microsoft), you can manually create the service principal for the app and then disable it by using the following cmdlet.
51+
You may know the AppId of an app that doesn't appear on the Enterprise apps list. For example, you may have deleted the app or the service principal hasn't yet been created due to the app being pre-authorized by Microsoft, you can manually create the service principal for the app and then disable it by using the following Azure AD PowerShell cmdlet.
52+
53+
Ensure you've installed the AzureAD module (use the command `Install-Module -Name AzureAD`). In case you're prompted to install a NuGet module or the new Azure AD V2 PowerShell module, type Y and press ENTER.
4854

4955
```PowerShell
56+
# Connect to Azure AD PowerShell
57+
Connect-AzureAD -Scopes "Application.ReadWrite.All"
58+
5059
# The AppId of the app to be disabled
5160
$appId = "{AppId}"
5261
@@ -60,6 +69,55 @@ if ($servicePrincipal) {
6069
$servicePrincipal = New-AzureADServicePrincipal -AppId $appId -AccountEnabled $false
6170
}
6271
```
72+
:::zone-end
73+
74+
:::zone pivot="ms-powershell"
75+
76+
You may know the AppId of an app that doesn't appear on the Enterprise apps list. For example, you may have deleted the app or the service principal hasn't yet been created due to the app being pre-authorized by Microsoft, you can manually create the service principal for the app and then disable it by using the following Microsoft Graph PowerShell cmdlet.
77+
78+
Ensure you've installed the Microsoft Graph module (use the command `Install-Module Microsoft.Graph`).
79+
80+
```powershell
81+
# Connect to Microsoft Graph PowerShell
82+
Connect-MgGraph -Scopes "Application.ReadWrite.All"
83+
84+
# The AppId of the app to be disabled
85+
$appId = "{AppId}"
86+
87+
# Check if a service principal already exists for the app
88+
$servicePrincipal = Get-MgServicePrincipal -Filter "appId eq '$appId'"
89+
90+
# If Service principal exists already, disable it , else, create it and disable it at the same time
91+
if ($servicePrincipal) { Update-MgServicePrincipal -ServicePrincipalId $servicePrincipal.Id -AccountEnabled:$false }
92+
93+
else { $servicePrincipal = New-MgServicePrincipal -AppId $appId –AccountEnabled:$false }
94+
```
95+
96+
:::zone-end
97+
98+
:::zone pivot="ms-graph"
99+
100+
You may know the AppId of an app that doesn't appear on the Enterprise apps list. For example, you may have deleted the app or the service principal hasn't yet been created due to the app being pre-authorized by Microsoft, you can manually create the service principal for the app and then disable it by using Microsoft Graph explorer.
101+
102+
To disable sign-in to an application, sign in to [Graph Explorer](https://developer.microsoft.com/graph/graph-explorer) with one of the roles listed in the prerequisite section.
103+
104+
You'll need to consent to the `Application.ReadWrite.All` permission.
105+
106+
Run the following query to disable user sign-in to an application.
107+
108+
```http
109+
PATCH https://graph.microsoft.com/v1.0/servicePrincipals/2a8f9e7a-af01-413a-9592-c32ec0e5c1a7
110+
111+
Content-type: application/json
112+
113+
{
114+
"accountEnabled": false
115+
}
116+
```
117+
118+
:::zone-end
119+
120+
63121

64122
## Next steps
65123

0 commit comments

Comments
 (0)