Managing user accounts in Microsoft 365 (M365) can be time-consuming, especially for large organizations. Learn how to use Graph PowerShell to bulk disable or enable user accounts, streamlining your administrative tasks and saving valuable time.
Prepare a CSV file (users.csv) with the following structure:
To disable user accounts in bulk, you need to set the accountEnabled property to false. Here's the Graph PowerShell script to do this:
To enable user accounts in bulk, you need to set the accountEnabled property to true. Here's a Graph PowerShell script to do this:
What permissions do I need to run these scripts?
You need to have the "User.ReadWrite.All" permission to manage user accounts using Graph PowerShell. You should also have the Microsoft 365 Administrator role assigne to you.
Can I use these scripts to manage guest user accounts?
Yes, you can manage both regular and guest user accounts with these scripts, as long as you have the necessary permissions
How can I log errors to a file?
You can modify the scripts to log errors to a file by using the Out-File cmdlet. For example: Failed to disable account for user: $($user.UserPrincipalName). Error: $_" | Out-File -FilePath "C:\path\to\errorlog.txt" -Append
What if some user accounts are not found?
Ensure that the UPNs in your CSV file are correct and exist in your tenant. The scripts will skip any accounts that are not found and log the error.
Using Graph PowerShell, you can efficiently manage user accounts in Microsoft 365, enabling or disabling them in bulk with ease. This approach saves time and reduces the potential for manual errors, making it an essential tool for administrators.
Note: Always stay updated by reading the Microsoft documentation: Disable M365 User Accounts
© m365corner.com. All Rights Reserved. Design by HTML Codex