Forum Discussion
abedinthehouse
Mar 29, 2023Copper Contributor
Bulk Disable Azure AD Users
I am looking for a way to disable (not delete) 300 AzureAD users with the "AccountEnabled" field. I was able to find the script below from an older post but I keep getting an error. I'm new here and ...
- 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.
Update Bulk Office 365 User Profile Information from CSV | Specmasoft Office 365 Manager
Kevin_Morgan
Mar 30, 2023Iron Contributor
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.
Update Bulk Office 365 User Profile Information from CSV | Specmasoft Office 365 Manager
abedinthehouse
Apr 08, 2023Copper Contributor
Thank 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"
}
}
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"
}
}