You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: microsoft-365/enterprise/block-user-accounts-with-microsoft-365-powershell.md
+42-71Lines changed: 42 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: "Block Microsoft 365 user accounts with PowerShell"
3
3
ms.author: kvice
4
4
author: kelleyvice-msft
5
5
manager: scotv
6
-
ms.date: 07/16/2020
6
+
ms.date: 02/14/2024
7
7
audience: Admin
8
8
ms.topic: article
9
9
ms.service: microsoft-365-enterprise
@@ -13,13 +13,15 @@ search.appverid:
13
13
ms.collection:
14
14
- scotvorg
15
15
- Ent_O365
16
+
- must-keep
16
17
f1.keywords:
17
18
- CSH
18
19
ms.custom:
19
20
- Ent_Office_Other
20
21
- PowerShell
21
22
- seo-marvel-apr2020
22
23
- has-azure-ad-ps-ref
24
+
- azure-ad-ref-level-one-done
23
25
ms.assetid: 04e58c2a-400b-496a-acd4-8ec5d37236dc
24
26
description: How to use PowerShell to block and unblock access to Microsoft 365 accounts.
25
27
---
@@ -30,60 +32,79 @@ description: How to use PowerShell to block and unblock access to Microsoft 365
30
32
31
33
When you block access to a Microsoft 365 account, you prevent anyone from using the account to sign in and access the services and data in your Microsoft 365 organization. You can use PowerShell to block access to individual or multiple user accounts.
32
34
33
-
## Use the Azure Active Directory PowerShell for Graph module
35
+
## Block access to individual user accounts
34
36
35
-
First, [connect to your Microsoft 365 tenant](connect-to-microsoft-365-powershell.md#connect-with-the-azure-active-directory-powershell-for-graph-module).
37
+
>[!NOTE]
38
+
> The Azure Active Directory module is being replaced by the Microsoft Graph PowerShell SDK. You can use the Microsoft Graph PowerShell SDK to access all Microsoft Graph APIs. For more information, see [Get started with the Microsoft Graph PowerShell SDK](/powershell/microsoftgraph/get-started).
36
39
37
-
### Block access to individual user accounts
40
+
First, [connect to your Microsoft 365 tenant](connect-to-microsoft-365-powershell.md).
41
+
42
+
Blocking and unblocking user accounts requires the **User.ReadWrite.All** permission scope or one of the other permissions listed in the ['List subscribedSkus' Graph API reference page](/graph/api/subscribedsku-list).
43
+
44
+
```powershell
45
+
Connect-Graph -Scopes User.ReadWrite.All
46
+
```
38
47
39
48
Use the following syntax to block an individual user account:
40
49
41
50
```powershell
42
-
Set-AzureADUser -ObjectID <sign-in name of the user account> -AccountEnabled $false
51
+
$params = @{
52
+
accountEnabled = $false
53
+
}
54
+
Update-MgUser -UserId <sign-in name of the user account> -BodyParameter $params
43
55
```
44
56
45
57
> [!NOTE]
46
-
> The *-ObjectID* parameter in the **Set-AzureAD** cmdlet accepts either the account sign-in name, also known as the User Principal Name, or the account's object ID.
58
+
> The *-UserId* parameter in the **Update-MgUser** cmdlet accepts either the account sign-in name, also known as the User Principal Name, or the account's object ID.
## Use the Microsoft Azure Active Directory module for Windows PowerShell
114
-
115
-
First, [connect to your Microsoft 365 tenant](connect-to-microsoft-365-powershell.md#connect-with-the-microsoft-azure-active-directory-module-for-windows-powershell).
116
-
117
-
### Block individual user accounts
118
-
119
-
Use the following syntax to block access for an individual user account:
120
-
121
-
```powershell
122
-
Set-MsolUser -UserPrincipalName <sign-in name of user account> -BlockCredential $true
123
-
```
124
-
125
-
>[!Note]
126
-
>PowerShell Core doesn't support the Microsoft Azure Active Directory module for Windows PowerShell module and cmdlets that have *Msol* in their name. You have to run these cmdlets from Windows PowerShell.
127
-
128
-
This example blocks access to the user account *fabricec\@litwareinc.com*.
In the following commands, the example text file is *C:\My Documents\Accounts.txt*. Replace this file name with the path and file name of your text file.
157
-
158
-
To block access for the accounts that are listed in the text file, run the following command:
0 commit comments