Adding/removing users via PowerShell in Microsoft Graph
Managing users through PowerShell and the Microsoft Graph SDK allows administrators to automate and streamline user account management tasks. This is particularly useful for bulk operations and can significantly reduce the time and effort required to manage user accounts.
Getting ready
Ensure you have PowerShell 7.0 or later, administrative rights on your machine, and the Global or User Administrator role in Microsoft 365.
How to do it…
- Follow the steps in the previous recipe, Installing and connecting to the Microsoft Graph SDK via PowerShell, to install and connect to Microsoft Graph, if not already completed.
- To add a new user, run the following script, replacing the placeholder values with actual user information:
$PasswordProfile = New-Object -TypeName Microsoft.Graph.PowerShell.Models.MicrosoftGraphPasswordProfile $PasswordProfile.Password = "aStrongP@ssw0rd" New-MgUser -AccountEnabled...