-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEntraID-Bulk-Remove-Users.ps1
43 lines (31 loc) · 1.26 KB
/
EntraID-Bulk-Remove-Users.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<#
Description:
Script removes users in bulk.
Requirements:
- Microsoft.Graph PowerShell module
- User.ReadWrite.All permission
Version:
1.0
More details:
https://azure365addict.com/2025/03/22/bulk-user-deletion-in-entra-id-with-powershell/
#>
# Connect Microsoft Graph
$Scopes = "User.ReadWrite.All "
Connect-MgGraph -Scopes $Scopes
# Get the list of users
$Users = Import-CSV "C:\Temp\EntraID-Bulk-Remove-Users_SAMPLE.csv"
foreach ($User in $Users)
{
$UPN = $User.UserPrincipalName
try
{
$AADUser = Get-MgUser -UserId $UPN -ErrorAction Stop #Check if user exists
Remove-MgUser -UserId $UPN
Write-Host "Deleted user $UPN" -ForegroundColor Green
}
catch
{
Write-Host "WARNING: Could not delete user $UPN - User does not exist in Entra ID" -ForegroundColor Yellow
}
}
Write-Host `n"*** Please visit " -NoNewline -ForegroundColor Green; Write-Host "azure365addict.com" -ForegroundColor Yellow -NoNewline; Write-Host " to get access to the latest PowerShell related blog entries. ***" -ForegroundColor Green