Forum Discussion
Bulk Disable Azure AD Users
- Mar 30, 2023
The command to disable Azure AD user is:
Set-AzureADUser -ObjectID "user_upn_or_id" -AccountEnabled $false
You can just change the line as like below one:
Set-AzureADUser -ObjectID $user.ObjectId -AccountEnabled $false
Refer this post to update bulk Azure AD User attributes:
https://morgantechspace.com/2022/03/update-bulk-azure-ad-user-attributes-using-powershell.html
If you're interested in updating bulk Office 365 user profile information without using PowerShell, try the Office 365 Manager from Specmasoft. This tool helps you modify bulk M365 users using CSV, update licenses, add bulk members to groups, and more.
https://specmasoft.com/office-365-manager/update-bulk-azure-ad-users-in-microsoft-365-using-a-csv-file
The command to disable Azure AD user is:
Set-AzureADUser -ObjectID "user_upn_or_id" -AccountEnabled $false
You can just change the line as like below one:
Set-AzureADUser -ObjectID $user.ObjectId -AccountEnabled $false
Refer this post to update bulk Azure AD User attributes:
https://morgantechspace.com/2022/03/update-bulk-azure-ad-user-attributes-using-powershell.html
If you're interested in updating bulk Office 365 user profile information without using PowerShell, try the Office 365 Manager from Specmasoft. This tool helps you modify bulk M365 users using CSV, update licenses, add bulk members to groups, and more.
https://specmasoft.com/office-365-manager/update-bulk-azure-ad-users-in-microsoft-365-using-a-csv-file
- abedinthehouseApr 08, 2023Copper ContributorThank you so much! This worked just perfectly with the ObjectId.
Below is the final script I got working
# Get CSV content
$CSVrecords = Import-Csv C:\Users\abedi\Downloads\MLNAccounts.csv
# Create arrays for skipped and failed users
$SkippedUsers = @()
$FailedUsers = @()
# Loop trough CSV records
foreach ($CSVrecord in $CSVrecords) {
$ObjectID = $CSVrecord.ObjectID
$user = Get-AzureADUser -ObjectID "$ObjectID"
if ($user) {
try{
$user | Set-AzureADUser -AccountEnabled $false
} catch {
$FailedUsers += $ObjectID
Write-Warning "$ObjectID user found, but FAILED to deactivate."
}
}
else {
$SkippedUsers += $ObjectID
Write-Warning "$ObjectID not found, skipped"
}
}